0

Can someone explain to me why this happens? It compiles the program fine but it wont let me run it. I'm on ubuntu 16.04

Bonus question: How can I run the math library on Geany? I love the interface but can't figure out how to to run math.h header file.

Here's the code:

enter image description here

Pierre.Vriens
  • 1,137
  • 37
  • 16
  • 21
Sam Al
  • 1
  • 1
    Possible duplicate of [How to Compile and Run C program](http://askubuntu.com/questions/32242/how-to-compile-and-run-c-program) – David Foerster May 24 '16 at 07:58
  • Do NOT post images. Post the actual text in your question. – user3629249 May 24 '16 at 20:46
  • to incorporate the math library , link with the math library. I.E. `gcc cents.o -o cents -lm` (-lm brings in the libm.so library.) – user3629249 May 24 '16 at 20:50
  • what library do you think your incorporating with the `-ld` parameter to the link statement? – user3629249 May 24 '16 at 20:51
  • here is the right way to compile/link/run your program: `cd /home/sam/sam.c` then `gcc -Wall -Wextra -pedantic -c cents.c -o cents.o -I.` then `gcc cents.o -o cents -lm` and finally `./cents` – user3629249 May 24 '16 at 20:55
  • strongly suggest reading/understanding a tutorial for the `gcc` compiler. Pay special attention to the options/parameters that are available (most of them you will never use.) – user3629249 May 24 '16 at 20:56
  • when you want to use some function, like `round()`, read/understand the man page for that function. – user3629249 May 24 '16 at 20:58

1 Answers1

3

Firstly using the gcc switch -c you are telling the compiler to only compile and not link which doesn't produce an executable binary to get an executable binary you need to not use this switch. The correct command would be:

gcc cents.c

However since this command does not specify the output file name the default name a.out will be used for the binary so you probably want to use this command:

gcc cents.c -o cents

Which will produce an executable binary called cents which can then be executed with

./cents

As for your other question you don't run header files that is not their purpose, header files are source code files the same as .c except their job is to be processed by the c preprocessor. Generally they are used to contain function prototypes for libraries to ensure that the same definitions are used throughout the project even if later the function requires a change to the prototype this helps to minimise errors and resulting bugs when changes are made in the program since the risk of someone missing a source file when changing the definition is otherwise high in large projects.

MttJocy
  • 692
  • 3
  • 7