Brian K Hlady(deleted)
|
RE: Linking a C library from C++ project
|
Brian K Hlady(deleted)
04/28/2008 12:42 PM
post7403
|
RE: Linking a C library from C++ project
And my example was completely bass-ackwards. Sorry about that.
-----Original Message-----
From: Ryan Mansfield [mailto:rmansfield@qnx.com]
Sent: Monday, April 28, 2008 12 37
To: momentics-community
Subject: Re: Linking a C library from C++ project
> I'm trying to use the MySQL 5 client to access a database running on
another
> machine. I'm hosting on Windows Vista Momentics 4.01 and targeting 6.3.2
> Neutrino running on a separate x86 box. I've tried both the 2.95 and 3.3
> compiler tool sets.
>
> When I link from a C project everything is fine. When I link from a C++
> project I get a number of undefined reference errors (obviously due to
name
> mangling). In the MySQl header file there is the expected #ifdef
__cplusplus
> extern "C" { code. I would have expected this to work correctly, but it
isn't
> .
>
> I have run into this with gcc previously with another library. Not sure
what
> is going on.
Hi Tim,
Are the undefined references errors for the symbols that should have C
linkage? Can you use nm on both the C++ object and the library to confirm
they have C linkage ?
Can you post the linker output as well?
Regards,
Ryan Mansfield
_______________________________________________
QNX Momentics Community Support
http://community.qnx.com/sf/go/post7402
|
|
|
Tim Gessner
|
Re: Linking a C library from C++ project
|
Tim Gessner
04/28/2008 1:36 PM
post7410
|
Re: Linking a C library from C++ project
Interestingly if I undefine __cplusplus before including the mysql header the only undefined references are to the mysql
functions I call.
If I do not undefine _cplusplus before including the mysql header the undefined references are to a number of other
libraries including socket, m, <taocrypt?>, etc. along with __pure virtual and __builtin_delete.
The output of nm for the app object is (with __cplusplus defined)
C:\Users\Tim.DELTA\Documents\EclipseWorkspace\Test\x86\o-g>\QNX632\host\win32\x86\usr\ntox86\bin\nm.exe --no-demangle
test.o
U __gxx_personality_v0
00000000 T main
U mysql_close
U mysql_error
U mysql_init
U mysql_real_connect
and the library is similar for these functions. There are some mangled names in the library from what appears to be the
taocrypt library.
I have attached the output of nm for the library as it is very long.
I'm not very familiar with using nm so please let me know if the output is not what you are looking for.
Thanx
Tim
|
|
|
Tim Gessner
|
Re: Linking a C library from C++ project
|
Tim Gessner
04/28/2008 1:39 PM
post7412
|
Re: Linking a C library from C++ project
Here is the linker output
make -k EXTRA_SUFFIXES=cpp clean all --file=C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/QMakefile51860.tmp
make -j 1 -Cx86 -fMakefile clean
make[1]: Entering directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86'
make -j 1 -Co -fMakefile clean
make[2]: Entering directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o'
C:/QNX632/host/win32/x86/usr/bin/rm -f Test *.pinfo *.o *.err *.map mapfile *.sym *.i
make[2]: Leaving directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o'
make -j 1 -Co-g -fMakefile clean
make[2]: Entering directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o-g'
C:/QNX632/host/win32/x86/usr/bin/rm -f Test_g *.pinfo *.o *.err *.map mapfile *.sym *.i
make[2]: Leaving directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o-g'
make[1]: Leaving directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86'
make -j 1 -Cx86 -fMakefile all
make[1]: Entering directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86'
make -j 1 -Co -fMakefile all
make[2]: Entering directory `C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o'
C:/QNX632/host/win32/x86/usr/bin/qcc -V3.3.5,gcc_ntox86 -c -Wc,-Wall -Wc,-Wno-parentheses -O -DNDEBUG -I. -
IC:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o -IC:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86 -IC:/
Users/Tim.DELTA/Documents/EclipseWorkspace/Test -IC:/QNX632/target/qnx6/usr/include C:/Users/Tim.DELTA/Documents/
EclipseWorkspace/Test/Test.cpp
C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/Test.cpp: In function `int
main(int, char**)':
C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/Test.cpp:21: warning: unused
variable `const char*str'
C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/Test.cpp:23: warning: unused
variable `long int l'
C:/QNX632/host/win32/x86/usr/bin/rm -f C:/Users/Tim.DELTA/Documents/EclipseWorkspace/Test/x86/o/Test
C:/QNX632/host/win32/x86/usr/bin/qcc -V3.3.5,gcc_ntox86 -lang-c++ -lang-c++ -oC:/Users/Tim.DELTA/Documents/
EclipseWorkspace/Test/x86/o/Test Test.o -L. -LC:/QNX632/target/qnx6/x86/lib/mysql -LC:/QNX632/target/qnx6/x86/lib -
LC:/QNX632/target/qnx6/x86/lib/gcc/3.3.5 -LC:/QNX632/target/qnx6/x86/lib -LC:/QNX632/target/qnx6/x86/usr/lib -Bstatic
-lmysqlclient_r -Bdynamic
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(client.o): In function `my_connect':
client.o(.text+0x2b): undefined reference to `connect'
client.o(.text+0x65): undefined reference to `connect'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(client.o): In function `wait_for_data':
client.o(.text+0x1bf): undefined reference to `getsockopt'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(client.o): In function `mysql_real_connect':
client.o(.text+0x1c42): undefined reference to `socket'
client.o(.text+0x1dc5): undefined reference to `socket'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(viosocket.o): In function `vio_fastsend':
viosocket.o(.text+0x1fe): undefined reference to `setsockopt'
viosocket.o(.text+0x220): undefined reference to `setsockopt'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(viosocket.o): In function `vio_keepalive':
viosocket.o(.text+0x27a): undefined reference to `setsockopt'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(viosocket.o): In function `vio_close':
viosocket.o(.text+0x320): undefined reference to `shutdown'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(viosocket.o): In function `vio_peer_addr':
viosocket.o(.text+0x3d1): undefined reference to `getpeername'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(viosocket.o): In function `vio_timeout':
viosocket.o(.text+0x47e): undefined reference to `setsockopt'
C:/QNX632/target/qnx6/x86/lib/mysql/libmysqlclient_r.a(ssl.o): In function `TaoCrypt::Block<unsigned char, TaoCrypt::
AllocatorWithCleanup<unsigned...
View Full Message
|
|
|