简体   繁体   中英

Problem compiling C progtam from command line gcc with math.h

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?

-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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM