English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Trying to compile a fairly simple c program on my Sun Sparc running Solaris 9 O/S. I have got rid of all compiler errors and warnings, but get the following message:

# gcc BTDC.c
Undefinedfirst referenced
symbol in file
cos /var/tmp/cczK10be.o
sin /var/tmp/cczK10be.o
sqrt /var/tmp/cczK10be.o
typeq /var/tmp/cczK10be.o
degcalc /var/tmp/cczK10be.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

I am obviously writing #include in my program, but it seems the linker is not finding the math functions.

Thanks for any help.

2006-10-14 01:57:37 · 4 answers · asked by colinmeister 2 in Computers & Internet Programming & Design

4 answers

Just add -lm to the end of the linker command line, the math library is optional.

Note that just including just includes the headers, the linker still needs a reference to libm in order to be able to resolve the addresses of those functions.

This is all extensively documented.

Regards, Dan.

2006-10-14 10:31:45 · answer #1 · answered by Dan M 3 · 0 0

In C, you may have a different bug in the compiler directories. You may need to specifically find the math library file and check that the directory it is in is on the path of the OS and the compiler. It seems from the error message that it is likely the header file isn't being found, but this error also could be a result of not finding the actual object code in the library file or not finding the library file itself. You may also want to try using #include "./math.h" or some similar specifier for a relative path. This may allow you to find the problem a bit quicker than you would poking about in the directories and paths alone. I hope this helps solve the problem.

2006-10-14 03:29:54 · answer #2 · answered by Anonymous · 0 0

As you have guessed the maths library is not being linked.

I think the command you are missing is either -lm or -dld , I forget which. Add those you your linking command line

gcc BTDC.o -o prog1 -lm

2006-10-14 02:10:59 · answer #3 · answered by Mike 5 · 0 0

Manually locate the math.h file in the C++ library directory

If its not there then download it:

http://mirror.sg.depaul.edu/pub/OpenBSD/src/include/math.h

Check they are the same if it is there.

2006-10-14 02:07:15 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers