Quoting Dean Michael Berris <[EMAIL PROTECTED]>: > [EMAIL PROTECTED]:~/src/csrc$ gcc prime.c -o prime > /tmp/ccAwYhXb.o(.text+0x2c): In function `isprime': > : undefined reference to `sqrt'
The include directive in your source, #include <math.h> just enables the compiler to generate proper code (with type-conversions if needed), according to the prototypes given in the header file. However this does not link-in the proper function refered to in your source. You must tell the compiler in which library the function can be found, and in what directory to find the library. In your case you used the function sqrt(), prototyped in math.h. However the binary object for sqrt() is archived in the library /usr/lib/libm.a. You need to tell gcc to link that object in that library, using the command, gcc prime.c -o prime -lm In general, if the library is the file /path/to/lib/libXYZ.a, then the linker option is specified as: gcc prime.c -o prime -L/path/to/lib -lXYZ If the directory is one of the standard places, /lib, /usr/lib, and /usr/local/lib, there is no need to give the -L option. Note that if the library name is libXYZ.a, you need to strip off the "lib" and the "a", and just say -lXYZ. This is just one of the little "unixism" that one learns along the way. Now this does static linking. Dynamic linking to the libm.so library is a different issue. Maybe someone else should describe this to us. P~Manalastas _ Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph To leave: send "unsubscribe" in the body to [EMAIL PROTECTED] Fully Searchable Archives With Friendly Web Interface at http://marc.free.net.ph To subscribe to the Linux Newbies' List: send "subscribe" in the body to [EMAIL PROTECTED]
