-1

I am new to the command line and I am trying to run a C program containing the function log10.

If I give

gcc -o -lm randomVamp random\ vampire.c 

I get the error

gcc: error: randomVamp: No such file or directory

but randomVamp is the name I wanted to give to the executable, of course it doesn't exist yet.

If I prompt just

gcc -o -lm random\ vampire.c 

then I get the error

/usr/bin/ld: /tmp/ccbWivPU.o: in function `main':
random vampire.c:(.text+0x312): undefined reference to `log10'
collect2: error: ld returned 1 exit status

Anyone knows what's going on?

I don't know if it's relevant, but the program also includes stdlib.h and time.h should I use some flag or link them in some way?

anotherOne
  • 1,513
  • 11
  • 20

1 Answers1

2

-o means that the next argument is the output file name. Replace -o -lm randomVamp with something like -o randomVamp -lm.

Also, note that -l... have no effect if specified before the .c/.cpp/.o/... files. So, the command could look like this:

gcc -o randomVamp random\ vampire.c -lm
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207