Linker headache

Discussion of chess software programming and technical issues.

Moderator: Ras

kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Linker headache

Post by kbhearn »

Alright, brief backstory - having recently updated my linux distribution to kubuntu 13.04, when i installed eboard through the software center, it refused to run (just hangs, no errors when run in console). So i went to compile it from source instead. Was one const-related error i had to fix in the compilation step, but then it gets to the linker and appears to be unable to find any of the gtk tokens.

linker commandline used by makefile:

g++ -lpthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0 -lpng12 -o eboard board.o bugpane.o chess.o cimg.o clock.o dgtboard.o dlg_connect.o dlg_gamelist.o dlg_prefs.o global.o help.o history.o main.o mainwindow.o movelist.o network.o notebook.o ntext.o p2p.o pieces.o position.o promote.o proto_fics.o proto_p2p.o proto_xboard.o protocol.o quickbar.o script.o seekgraph.o sound.o status.o text.o tstring.o util.o widgetproxy.o langs.o

the output is some 5000 lines long and thus not included here, but it's just a long list of missing references to entry points that do exist in the gtk library referenced (used nm -D output to check some of them). There's nothing saying that it couldn't find any of the libraries listed. And I can't find any other copies of libgtk-x11-2.0.so outside of /usr/lib/x86_64-linux-gnu/ that it might be referencing. Anyone got any other ideas what could be going wrong here?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Linker headache

Post by bob »

kbhearn wrote:Alright, brief backstory - having recently updated my linux distribution to kubuntu 13.04, when i installed eboard through the software center, it refused to run (just hangs, no errors when run in console). So i went to compile it from source instead. Was one const-related error i had to fix in the compilation step, but then it gets to the linker and appears to be unable to find any of the gtk tokens.

linker commandline used by makefile:

g++ -lpthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0 -lpng12 -o eboard board.o bugpane.o chess.o cimg.o clock.o dgtboard.o dlg_connect.o dlg_gamelist.o dlg_prefs.o global.o help.o history.o main.o mainwindow.o movelist.o network.o notebook.o ntext.o p2p.o pieces.o position.o promote.o proto_fics.o proto_p2p.o proto_xboard.o protocol.o quickbar.o script.o seekgraph.o sound.o status.o text.o tstring.o util.o widgetproxy.o langs.o

the output is some 5000 lines long and thus not included here, but it's just a long list of missing references to entry points that do exist in the gtk library referenced (used nm -D output to check some of them). There's nothing saying that it couldn't find any of the libraries listed. And I can't find any other copies of libgtk-x11-2.0.so outside of /usr/lib/x86_64-linux-gnu/ that it might be referencing. Anyone got any other ideas what could be going wrong here?
First thought. I have had versions of link that were command-line option order sensitive.

Try it in this order:

link -o executable <object files listed here> -l<libraries listed here>

For gcc, obviously link becomes "gcc" or "g++" depending on the variant you are using. If you specify the libraries first, it won't see they are needed, then it parses the objects, links them, and can't find the libraries you need...

a wild guess, but probably will fix your problem. Just put the objects before the various -l library references.
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Linker headache

Post by kbhearn »

Thanks :) That fixed the linker problem. Unfortunately the application still exhibits the same behavior as the software center copy, but tracking the cause of that down is an issue for another day when i have more energy.
User avatar
Jim Ablett
Posts: 2391
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: Linker headache

Post by Jim Ablett »

kbhearn wrote:Alright, brief backstory - having recently updated my linux distribution to kubuntu 13.04, when i installed eboard through the software center, it refused to run (just hangs, no errors when run in console). So i went to compile it from source instead. Was one const-related error i had to fix in the compilation step, but then it gets to the linker and appears to be unable to find any of the gtk tokens.

linker commandline used by makefile:

g++ -lpthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0 -lpng12 -o eboard board.o bugpane.o chess.o cimg.o clock.o dgtboard.o dlg_connect.o dlg_gamelist.o dlg_prefs.o global.o help.o history.o main.o mainwindow.o movelist.o network.o notebook.o ntext.o p2p.o pieces.o position.o promote.o proto_fics.o proto_p2p.o proto_xboard.o protocol.o quickbar.o script.o seekgraph.o sound.o status.o text.o tstring.o util.o widgetproxy.o langs.o

the output is some 5000 lines long and thus not included here, but it's just a long list of missing references to entry points that do exist in the gtk library referenced (used nm -D output to check some of them). There's nothing saying that it couldn't find any of the libraries listed. And I can't find any other copies of libgtk-x11-2.0.so outside of /usr/lib/x86_64-linux-gnu/ that it might be referencing. Anyone got any other ideas what could be going wrong here?
Hi Kevin,

Do you have gtk2 libs installed ?

Jim.
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Linker headache

Post by kbhearn »

aye, all the libs are present and accounted for and dependencies resolved now. now i just need to figure out where it's hanging. saw something about another gtk application having a hangup on the theme engine used by default in 13.04. haven't looked into how to change that yet. otherwise i guess i'm littering the code with couts to find where it's hanging :)
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Linker headache

Post by kbhearn »

Indeed it appears related to the gtk theme. Firefox and eboard are now ugly as sin, but eboard runs again -.-. I love distro updates sometimes :/
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Linker headache

Post by Sven »

bob wrote:
kbhearn wrote:g++ -lpthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0 -lpng12 -o eboard board.o bugpane.o chess.o ...
First thought. I have had versions of link that were command-line option order sensitive.

Try it in this order:

link -o executable <object files listed here> -l<libraries listed here>

For gcc, obviously link becomes "gcc" or "g++" depending on the variant you are using. If you specify the libraries first, it won't see they are needed, then it parses the objects, links them, and can't find the libraries you need...

a wild guess, but probably will fix your problem. Just put the objects before the various -l library references.
It is exactly as you say. "gcc"/"g++" internally invoke "ld" which handles object files and libraries like this: (from Ubuntu ld manpage):
Some of the command-line options to ld may be specified at any point in the command line. However, options which refer to files, such as -l or -T, cause the file to be read at the point at which the option appears in the command line, relative to the object files and other file options.
...
-lnamespec
...
The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.
...
This type of archive searching is standard for Unix linkers.
Sven