On Feb 7, 1:59 am, Paul Pluzhnikov <[EMAIL PROTECTED]> wrote: > mearvk <[EMAIL PROTECTED]> writes: > > "g++ -c lip.C" gives me lip.o. > > "g++ -c test.C" gives me test.o > > "g++ -o out test.o lip.o -lm" should give me 'out' as an executable > > but it doesn't, instead giving me: > > > lip.o(.text+0xf88d): In function `zfread(_IO_FILE*, long**)': > > : undefined reference to `log(double)' > > The problem is that lip.o references C++ mangled function > 'log(double)', but it should be referencing 'extern "C"' function > 'log'. > > Here is an example showing the same problem: > > $ cat t.c > double log(double); /* problem */ > int main() { double d = log(100); return 0; } > > When above code is compiled in "C" mode, it works: > > $ gcc -fno-builtin t.c -lm > > But when compiled as C++, it doesn't: > > $ g++ -fno-builtin t.c -lm > /tmp/cc0o3mP7.o(.text+0x20): In function `main': > : undefined reference to `log(double)' > collect2: ld returned 1 exit status > > The problem is that 'double log(double);' is correct for C, but it > is *not* correct for C++. It should be: > > #ifdef __cplusplus > extern "C" > #endif > double log(double); > > I am guessing that your 'lip.C' should actually be named 'lip.c', > and should be compiled with 'gcc' instead of 'g++'. > > Cheers, > -- > In order to understand recursion you must first understand recursion. > Remove /-nsp/ for email.
Does this mean I should be wrapping the log(double) function in the math library with #ifdef __cplusplus extern "C" { #endif or that I should be doing this in lip.c's functions that reference the math library functions? Thanks, Max _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus