LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-14-2004, 03:30 PM   #1
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Question Configuring g++ or ld?


I have two computers, both running linux. On the first computer, running

g++ test.cpp -lSDL

produces no errors, however, on the second computer, running the same command produces:

/usr/lib/libSDL.so: undefined reference to `pthread_create'
/usr/lib/libSDL.so: undefined reference to `pthread_cancel'
/usr/lib/libSDL.so: undefined reference to `sem_destroy'
/usr/lib/libSDL.so: undefined reference to `sem_wait'
/usr/lib/libSDL.so: undefined reference to `sem_init'
/usr/lib/libSDL.so: undefined reference to `pthread_sigmask'
/usr/lib/libSDL.so: undefined reference to `sem_trywait'
/usr/lib/libSDL.so: undefined reference to `pthread_mutexattr_init'
/usr/lib/libSDL.so: undefined reference to `sem_getvalue'
/usr/lib/libSDL.so: undefined reference to `pthread_join'

The second computer does have libpthread installed, and running "g++ test.cpp -lSDL -lpthread" to explicitly link in libpthread compiles perfectly... but explicitly linking libpthread isn't necessary on the first computer!

It's only a slight annoyance to have to use a different command on the second comp, but certain programs downloaded online will not compile on the second computer.

Is there some sort of configuration file I could add/edit or environment variable I can set that will make both computers function the same in this regard?

Thanks.
 
Old 12-14-2004, 04:01 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
You could try using `sdl-config --clags --libs` in your g++ line. sdl-config will generally return what flags you need to use for your current system.

e.g.

g++ -o somefile somefile.cpp `sdl-config --cflags --libs`

Another alternative is to learn about the GNU autoconf tools. That might be overkill for your particular situation, though.

Last edited by deiussum; 12-14-2004 at 04:03 PM.
 
Old 12-14-2004, 06:15 PM   #3
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Original Poster
Rep: Reputation: 31
Yeah, but nothing else is necessary on the first computer's command line. I know I could add -lpthread or use `sdl-config --clfags --libs`, but those aren't necessary on the first computer.

My problem isn't that it won't compile at all, it's that I have to specify extra options on one computer and not on another.

Thanks for the reply, though.

Any other ideas?
 
Old 12-14-2004, 07:50 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Same distro, same compiler version, all packages identical?



Cheers,
Tink
 
Old 12-14-2004, 09:30 PM   #5
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Original Poster
Rep: Reputation: 31
Nope, different distro. Same compiler, though.
 
Old 12-15-2004, 08:23 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I've had similar problems with glut before. I think it has something to do with how the libraries are compiled. In some cases, the dependency on other libraries is compiled in so that the other libraries just get brought along for free, and in some cases it isn't.... That is my theory, anyway.
 
Old 12-15-2004, 11:42 AM   #7
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Original Poster
Rep: Reputation: 31
Just checked with ldd and I guess thats right: the first comp's libSDL lists libpthread while the second does not. So, is there any way to recompile SDL to have the same dependencies or am I just doomed to edit Makefiles forever?
 
Old 12-15-2004, 01:06 PM   #8
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The easy solution is to just add the libraries that the other needs. There shouldn't be any harm in having those extra libraries included in the Makefile of the computer that doesn't require it. (Unless they don't exist, but libpthread should exist on pretty much all major distros...)

Or, you can look into autoconf/automake. You can use some macros there to test if you need the additional libraries, and add them to the Makefile if needed. As I said before, this might be overkill for your particular needs, though.

You could also grab the SDL source and compile it the same way on both computers. Might have to look into what parameters you can supply to the configure script to get this to work.

Last edited by deiussum; 12-15-2004 at 01:07 PM.
 
Old 12-15-2004, 02:45 PM   #9
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Original Poster
Rep: Reputation: 31
I've already compiled SDL form source on the computer with the problem. Maybe that's the problem...

How would one go about compiling SDL such that "ldd libSDL-something.so" would list libpthread as it does on the properly functioning computer?
 
Old 12-16-2004, 09:47 AM   #10
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Good question. The first thing I'd check would be ./configure --help and see if there are any configure parameters that might affect that behavior.
 
Old 12-16-2004, 10:54 AM   #11
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Original Poster
Rep: Reputation: 31
Just checked. Only one option stood out as a possible solution (--enable-dependency-tracking) and I'm trying that. I also checked config.log and noticed no significant difference between the two other than that the architecture was different (different cpus).

EDIT: I don't think I mentioned this before, but libSDL was compiled the exact same way on both computers: ./configure (with no options) followed by make (with no options).

How is it that a library could be built which depends on another (in this case, libpthread) such that ldd doesn't list the dependency? I mean, regardless of if there is a configure option to do this kind of thing, how can one library list a dependency while the other does not, even though both have the same dependency? Is there some command line option that needs to be passed to gcc/ld that is, apparently, not being passed?

Last edited by zhangmaike; 12-16-2004 at 10:57 AM.
 
Old 12-16-2004, 03:14 PM   #12
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Original Poster
Rep: Reputation: 31
Okay. The compile finished after reconfiguring with --enable-dependency-tracking. I don't know if it was enabling that option or any number of other changes I've made to the system recently, but libpthread is now listed in the dependency list by ldd.

Thanks for your help.
 
Old 12-16-2004, 03:42 PM   #13
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Cool. That's good to know. If that didn't work, I was out of ideas...
 
  


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
Not configuring Culbert Linux - Software 3 08-24-2003 10:37 AM
Configuring X Nexer Linux - Newbie 8 05-06-2003 10:02 PM
configuring x Linux_guru_not Slackware 7 03-29-2003 06:52 AM
configuring help n00bster Slackware 1 03-01-2003 02:15 AM
configuring X dictatorofgoats Linux - General 2 08-11-2001 09:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:19 PM.

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
Open Source Consulting | Domain Registration