views:

23

answers:

3

Currently, while compiling a C program which uses pthread library function I have to specify compiler option -lpthread explicitly. Please suggest a way to configure ldconfig so that the pthread library could be used without specifying it on the command line.

presently lpthread -p gives the following output :=

[root@localhost lib]# ldconfig -p | grep pthread
    libpthread.so.0 (libc6, OS ABI: Linux 2.6.9) => /lib/libpthread.so.0
    libOpenIPMIpthread.so.0 (libc6) => /usr/lib/libOpenIPMIpthread.so.0
A: 

You can set the LD_LIBRARY_PATH env variable.

Praveen S
Is there a way out without setting the LD_LIBRARY_PATH?
Ashish
A: 

I don't believe you can do that. The LD_LIBRARY_PATH and ldconfig program are used to set up the paths to shared libraries that are used to resolve dependencies in your executable at runtime.

When compiling you will have to specify which libraries to include in the linking phase, i.e. -lpthread

Marc van Kempen
A: 

The pthreads library is a dynamic library. This means that, in order to use its functionality, a file distinct from your binary must be available at run time.

You can do this in several ways. Setting -lpthread will automatically set the compiler flags you want. Providing the shared file via LD_PRELOAD will do the same. Or you have your pthreaded program dlopen the library explicitly.

But the right way to do it is to provide the right compiler switches.

Borealid