Ask a Question related to UNIX Programming, Design and Development.
-
Stanley Yao #1
Undefined symbol in gcc & c++
Dear All,
I built the following little C program into a library (libtt.a) with gcc:
/* Filename: tt1.c */
#include <stdio.h>
int foo() {
return 1;
}
gcc -c tt1.c
ar -rs libtt.a tt1.o
Then I wrote the following C++ program and want to link with libtt.a and
failed.
/* Filename: tt2.cc */
int foo();
int main() {
int k;
k = foo();
return 0;
}
% c++ tt2.cc -L. -ltt
Undefined first referenced
symbol in file
foo() /var/tmp//cc02ILOd.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
% c++ tt2.cc tt1.o
Undefined first referenced
symbol in file
foo() /var/tmp//ccgMpZee.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
% g++ tt2.cc libtt.a
Undefined first referenced
symbol in file
foo() /var/tmp//cc8Kx1jd.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
% gcc tt2.cc tt1.o
Undefined first referenced
symbol in file
foo() /var/tmp//ccUM2g0c.o
__gxx_personality_v0 /var/tmp//ccUM2g0c.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Did I do something wrong? How can I get these 2 pieces (one is C, the
other is C++) linked together?
Thank you very much!
-Stan
Stanley Yao Guest
-
GD-1.38: Undefined symbol: .__fixsfsi
Hi ! Try to compile GD-1.38 under AIX 5.1 and run into the following error when running make: Undefined symbol: .__fixsfsi I did install... -
Undefined symbol perl_get_sv
I'm trying to use the LibXML module on our Web server, but I get the undefined symbol error. I don't seem to have a perl shared library on the... -
Undefined symbol?
Hey there, Wasn't sure which mailing list to send this to but maybe someone can point me in the right direction. When perl is invoked (presumably... -
undefined symbol in GTop.so
I'm trying to ultimately get Apache::VMonitor running on a server running turbolinx server 8. I'm stuck on GTop, which Apache::VMonitor requires.... -
undefined symbol identification problem
hpy_azizy@yahoo.com (ehab) wrote in message news:<b4f59294.0307220019.53d57117@posting.google.com>... 1. Why to name the file as such a long name?... -
Oscar del Rio #2
Re: Undefined symbol in gcc & c++
[snip]> I built the following little C program into a library (libtt.a) with gcc:
[snip}> Then I wrote the following C++ program and want to link with libtt.a and
> failed.
> Did I do something wrong? How can I get these 2 pieces (one is C, the
> other is C++) linked together?
Google for "mixing C and C++", or
[url]http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html[/url]
Oscar del Rio Guest
-
Steve Bellenot #3
Re: Undefined symbol in gcc & c++
In article <Pine.GSO.4.55.0307220956230.1661@lectura.CS.Arizo na.EDU>,
Stanley Yao <yao@CS.Arizona.EDU> wrote:This makes foo have `C' linkage>/* Filename: tt1.c */
>#include <stdio.h>
>int foo() {
> return 1;
>}
>
>gcc -c tt1.c
>ar -rs libtt.a tt1.o
here you say foo has c++ linkage>
>Then I wrote the following C++ program and want to link with libtt.a and
>failed.
>
>/* Filename: tt2.cc */
>int foo();
change to
extern "C" int foo();
yes, the c++ compile is really looking for a namemangledfoo and not>Did I do something wrong? How can I get these 2 pieces (one is C, the
>other is C++) linked together?
foo.
--
[url]http://www.math.fsu.edu/~bellenot[/url]
bellenot <At/> math.fsu.edu
+1.850.644.7189 (4053fax)
Steve Bellenot Guest
-
Fletcher Glenn #4
Re: Undefined symbol in gcc & c++
Stanley Yao wrote:
You must declare your foo() function as: extern "C",>
> Dear All,
>
> I built the following little C program into a library (libtt.a) with gcc:
>
> /* Filename: tt1.c */
> #include <stdio.h>
> int foo() {
> return 1;
> }
>
> gcc -c tt1.c
> ar -rs libtt.a tt1.o
>
> Then I wrote the following C++ program and want to link with libtt.a and
> failed.
>
> /* Filename: tt2.cc */
> int foo();
> int main() {
> int k;
> k = foo();
> return 0;
> }
>
> % c++ tt2.cc -L. -ltt
> Undefined first referenced
> symbol in file
> foo() /var/tmp//cc02ILOd.o
> ld: fatal: Symbol referencing errors. No output written to a.out
> collect2: ld returned 1 exit status
>
> % c++ tt2.cc tt1.o
> Undefined first referenced
> symbol in file
> foo() /var/tmp//ccgMpZee.o
> ld: fatal: Symbol referencing errors. No output written to a.out
> collect2: ld returned 1 exit status
>
> g++ tt2.cc libtt.a
> Undefined first referenced
> symbol in file
> foo() /var/tmp//cc8Kx1jd.o
> ld: fatal: Symbol referencing errors. No output written to a.out
> collect2: ld returned 1 exit status
>
> % gcc tt2.cc tt1.o
> Undefined first referenced
> symbol in file
> foo() /var/tmp//ccUM2g0c.o
> __gxx_personality_v0 /var/tmp//ccUM2g0c.o
> ld: fatal: Symbol referencing errors. No output written to a.out
> collect2: ld returned 1 exit status
>
> Did I do something wrong? How can I get these 2 pieces (one is C, the
> other is C++) linked together?
>
> Thank you very much!
> -Stan
or the linker will not know how to find the symbol.
The problem is that to accomodate polymorphism, the
C++ symbols are "mangled" to include type information.
The C compiler does no such thing, and for the linker to
find your symbol, it must be told that the symbol is unmangled.
--
Fletcher Glenn
email [email]f-g-l-e-n-n@quest.com[/email] (remove the dashes)
Fletcher Glenn Guest
-
Stanley Yao #5
Re: Undefined symbol in gcc & c++
Thank you very much for the help from both of you!
I modified the code with extern "C" and it's working correctly now.
According to your answer, I am now reading some materials about "mangled name".
Have a great day!
Stan
On Tue, 22 Jul 2003, Raymundo M. Vega wrote:
> Check the change to main program.
>
> raymundoStanley Yao Guest



Reply With Quote

