ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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?
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.