LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-01-2010, 08:15 AM   #1
nuliknol
Member
 
Registered: Jul 2009
Posts: 35

Rep: Reputation: 0
help with linking in c++


Hi,
i am trying to link a code in C++ with tinyxmldll library:
Code:
master out # ls -la
total 1388
drwx------ 2 root root   4096 May 10 14:02 .
drwx------ 6 root root   4096 Apr  5 08:35 ..
-rwxr-xr-x 1 root root 445771 May 10 14:02 libtinyxmlplus.so
-rw-r--r-- 1 root root 957594 May 10 14:02 libtinyxmlpluslib.a
master out #
When i link, i get 'undefined reference' error:
Code:
master hneat # make nt
g++ -g -DTIXML_USE_STL -DHCUBE_NOGUI -fPIC  -I./hneat -L./hneat -I/home/niko/hyperneat3/HyperNEAT_v3_0/JGTL/include/ -I/home/niko/hyperneat3/HyperNEAT_v3_0/tinyxmldll/include/ -I./Experiments -I../ -I./ -L/home/niko/hyperneat3/HyperNEAT_v3_0/tinyxmldll/out/ -L/usr/lib/wx -I/usr/include/boost -Wl,-rpath,/home/niko/hyperneat3/HyperNEAT_v3_0/HyperNEAT_03_29_10/HyperNEAT/NEAT/../../../tinyxmldll/out:/lib64:/usr/lib/wx:/usr/local/ompi/lib:/usr/local/python26/lib/python2.6:/home/niko/hyperneat3/HyperNEAT_v3_0/HyperNEAT_03_29_10/HyperNEAT/out -lconfig -rdynamic -lm -lgd -lmpi -lrt -lcuda -L/root/NVIDIA_GPU_Computing_SDK/sdk/lib/ -L/root/NVIDIA_GPU_Computing_SDK/C/lib/ -L/usr/lib64/openmpi/1.2.4-gcc -L/usr/local/ompi/lib/ -ltinyxmlpluslib -lz -lboost_thread-mt  -lboost_filesystem-mt -lboost_system-mt  -lwx_baseu-2.8 -lwx_gtk2u_core-2.8 -lwx_gtk2u_adv-2.8 -lpthread -lboard  -o nt main.o NEAT_Defines.o NEAT_Globals.o NEAT_Random.o NEAT_GeneticGene.o NEAT_FastBiasNetwork.o
NEAT_Globals.o: In function `NEAT::Globals::dump(TiXmlElement*)':
/root/evolute/hneat/NEAT_Globals.cpp:274: undefined reference to `TiXmlElement::SetAttribute(char const*, int)'
/root/evolute/hneat/NEAT_Globals.cpp:275: undefined reference to `TiXmlElement::SetAttribute(char const*, int)'
/root/evolute/hneat/NEAT_Globals.cpp:276: undefined reference to `TiXmlElement::SetAttribute(char const*, int)'
/root/evolute/hneat/NEAT_Globals.cpp:277: undefined reference to `TiXmlElement::SetAttribute(char const*, int)'
/root/evolute/hneat/NEAT_Globals.cpp:285: undefined reference to `TiXmlElement::SetDoubleAttribute(char const*, double)'
NEAT_Globals.o: In function `Globals':
I checked the tinyxmldll.so library and it has the symbols:
Code:
master out # nm libtinyxmlplus.so |grep SetAttribute
000000000000eca0 T _ZN12TiXmlElement12SetAttributeEPKcS1_
000000000000f000 T _ZN12TiXmlElement12SetAttributeEPKci
000000000000adf0 T _ZN12TiXmlElement12SetAttributeERKSsS1_
000000000000f380 T _ZN12TiXmlElement12SetAttributeERKSsi
master out #
The problem is, the symbols contain weird characters. How do I tell g++ that it should ignore these characters and link the functions correctly?

Thanks in advance.
 
Old 07-01-2010, 08:52 AM   #2
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,140

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
nm has a --demangle option that might give you better information. Try your nm command over using that option.

Quote:
Originally Posted by nuliknol View Post
The problem is, the symbols contain weird characters. How do I tell g++ that it should ignore these characters and link the functions correctly?
The problem is not the fact that the weird characters are there and the solution is not making g++ ignore the weird characters.

The problem seems to be a failure to match something used by your .o file with something defined by your .so file. Before fixing that, you need to diagnose it, which you can't do by comparing the demangled symbols from the .o with the mangled symbols from the .so

In most cases, the problem can be understood by comparing the demangled symbols of each. In rare cases, you need to instead look at the mangled symbols of each.

Last edited by johnsfine; 07-01-2010 at 08:57 AM.
 
Old 07-01-2010, 09:05 AM   #3
nuliknol
Member
 
Registered: Jul 2009
Posts: 35

Original Poster
Rep: Reputation: 0
thanks. But i found the problem after reading "Program Library Howto", this was the key paragraph:

"Be careful about the order of the parameters when using gcc; the -l option is a linker option, and thus needs to be placed AFTER the name of the file to be compiled. This is quite different from the normal option syntax. If you place the -l option before the filename, it may fail to link at all, and you can end up with mysterious errors."

i put the libraries after filename and it compiled ok
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static linking vs. dynamic linking? posix_memalign Programming 13 04-18-2010 03:27 PM
linking? kalleanka Programming 4 11-09-2006 10:16 AM
Problem in using both load time linking and runtime linking durgaprasad_j Linux - General 0 08-01-2006 04:49 AM
Linking LS to 'L' uveraser Linux - General 2 05-20-2004 11:24 AM
C++ linking? ugenn Programming 5 05-14-2002 02:33 AM


All times are GMT -5. The time now is 12:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration