Undefined reference to `exp'
Hello. Sorry for resurrecting an old thread, but I have exactly the same problem and the solution proposed here didn't help. To make matters more interesting, I had similar programs working maybe a year ago and then I don't really know what happened. There was no reinstalling involved or anything.
Anyway, this is the problem. After the problem started, I wrote a simple test program to make things more simple. Code:
#include <stdio.h> Code:
gcc -lm test.c Code:
test.c:(.text+0x17): undefined reference to `exp' |
Usually one puts the libraries after the file: linking is a fill in the gaps kind of deal, so you want the gap to exist first, before you fill it,
Having said that, it appears to work both ways round here on my Slackware64 box. Not sure why it works. I've certainly encountered undefined reference failures owing to incorrect order before. Anyway, give the following a go and see if it makes any difference. gcc test.c -lm Failing that, there's likely something faulty with your toolchain. |
Quote:
I should write memoires with the list of all the st00pid errors I encountered through life. It would be a bestseller. Thank you, this fixed it. |
:) You're welcome. I had to ask someone the first time I encountered this issue too.
I'm curious to understand why my Slackware64 box works when they're listed the wrong way around though. Anyone have any ideas on that? |
BTW, I see that someone (admin, mod...) removed these posts from the thread titled "Undefined reference to `exp' ". I understand some people's annoyance by resurrecting old threads, but woldn't it be much more functional if all the questions and answers regarding this problem were placed under the same name? I found the old thread by searching exactly "undefined reference to `exp'". Now, someone else with the same problem as me will find that old thread, but not this particular solution so he may have to ask the same question again.
|
Quote:
|
Changing the thread title to "Undefined reference to `exp'" might help folk find an answer in future.
|
Quote:
Quote:
|
Thanks ntubski. Adding -Wl,--as-needed certainly breaks it when they're in the wrong order, so that sounds very plausible.
|
All times are GMT -5. The time now is 02:25 AM. |