How do I find out which library contains what ?

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View

A bit off topic perhaps but how do I find out which library contains
which routines.

I've got these errors and I can't track down which libraries I should be
linking against. It's mostly semaphores and mutex threads etc

[mike@gladys telemetry]$ g++ -Wall -o telemetry telemetry.o -lccgnu2
-lccext2
telemetry.o(.text+0x81): In function `main':
: undefined reference to `stdscr'
telemetry.o(.text+0x86): In function `main':
: undefined reference to `wgetch'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_yield'
/usr/local/lib/libccgnu2.so: undefined reference to `dlerror'
/usr/local/lib/libccext2.so: undefined reference to `deflate'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_create'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_getspecific'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_rwlock_rdlock'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_rwlock_init'
/usr/local/lib/libccext2.so: undefined reference to `inflate'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_key_delete'
/usr/local/lib/libccgnu2.so: undefined reference to `_pthread_cleanup_pop'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_cancel'
/usr/local/lib/libccgnu2.so: undefined reference to
`pthread_mutexattr_destroy'
/usr/local/lib/libccgnu2.so: undefined reference to `sem_destroy'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_rwlock_destroy'
/usr/local/lib/libccgnu2.so: undefined reference to `sem_wait'
/usr/local/lib/libccgnu2.so: undefined reference to `sem_post'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_testcancel'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_rwlock_unlock'
/usr/local/lib/libccgnu2.so: undefined reference to `dlclose'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_detach'
/usr/local/lib/libccext2.so: undefined reference to `inflateInit_'
/usr/local/lib/libccext2.so: undefined reference to `deflateInit_'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_key_create'
/usr/local/lib/libccgnu2.so: undefined reference to `sem_init'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_kill'
/usr/local/lib/libccgnu2.so: undefined reference to
`pthread_attr_setstacksize'
/usr/local/lib/libccgnu2.so: undefined reference to `dlopen'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_rwlock_wrlock'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_sigmask'
/usr/local/lib/libccgnu2.so: undefined reference to
`pthread_rwlockattr_init'
/usr/local/lib/libccgnu2.so: undefined reference to `sem_trywait'
/usr/local/lib/libccgnu2.so: undefined reference to `dlsym'
/usr/local/lib/libccgnu2.so: undefined reference to
`pthread_mutexattr_settype'
/usr/local/lib/libccgnu2.so: undefined reference to
`pthread_rwlock_trywrlock'
/usr/local/lib/libccgnu2.so: undefined reference to
`pthread_rwlock_tryrdlock'
/usr/local/lib/libccgnu2.so: undefined reference to `_pthread_cleanup_push'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_mutexattr_init'
/usr/local/lib/libccgnu2.so: undefined reference to `sem_getvalue'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_mutex_trylock'
/usr/local/lib/libccext2.so: undefined reference to `inflateEnd'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_join'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_cond_timedwait'
/usr/local/lib/libccext2.so: undefined reference to `deflateEnd'
/usr/local/lib/libccgnu2.so: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status

Re: How do I find out which library contains what ?
Quoted text here. Click to load it

Panic over. It's something like...

[mike@gladys telemetry]$ nm --print-file-name /usr/lib/* 2> /dev/null |
grep sem_init

Re: How do I find out which library contains what ?

Quoted text here. Click to load it

You've already found that you need '-lpthread'

Quoted text here. Click to load it

Note however, that there is more to compiling multithreaded programs
then simply adding the missing -lpthread.

On Linux, you should be compiling and linking such programs with
'-pthread' flag, on Solaris with '-pthreads'. This will make gcc
"do the right thing". On other platforms you may have to add
-D_REENTRANT, -D_THREAD_SAFE, or something else.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

Site Timeline