[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Linking Problem
From: |
Paul Pluzhnikov |
Subject: |
Re: Linking Problem |
Date: |
Wed, 06 Feb 2008 22:59:42 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
mearvk <mearvk@gmail.com> 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.
- Linking Problem, mearvk, 2008/02/07
- Re: Linking Problem,
Paul Pluzhnikov <=