Domanda

I'm writing a program dealing with threads that I've almost got working completely. Unfortunately, I'm hitting an error (repeated 4 times) who's syntax I'm not familiar with. Here's a quick snip-it of my compile commands, and the errors that follow:

 gcc -o threads threads.cpp -pthread<br>
/tmp/ccy8maS0.o: In function `tenPercentA()':
threads.cpp:(.text+0xde): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `tenPercentB()':
threads.cpp:(.text+0x1c6): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `fiftPercentC()':
threads.cpp:(.text+0x2ae): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `fiftPercentD()':
threads.cpp:(.text+0x396): undefined reference to `ceil'
/tmp/ccy8maS0.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

I've already included the math.h library in my program, and I'm using the correct syntax for the call:

ceil(tempA);

Where tempA is a double holding the value I need to be rounded up. Any suggestions? I've tried Google'ing these errors but, like most errors, it's hard to find specific examples with the same pattern as yours.

EDIT: I've solved all of the ceil related errors (using -lm on the command line) however the last error still remains, and I have no idea what it means, or how to fix it.

È stato utile?

Soluzione

Referring the undefined reference to ceil():

You seem to be missing to link against libm.

Adding the option -lm to your call to gcc should solve this problem.


#includeing math.h is for the compiler to get to know ceil()'s defintion. The linker then later needs to know where ceil()'s implementation actually resides, namely in libm.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top