0

I'm running the following command:

g++ -m32 testLogin.cpp  -L/root/c++/libs  -ldvrnetsdk -o testLoginO -lpthread  -lasound 

the result:

/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_channels'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutex_trylock'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_readi'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_access'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_strerror'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutexattr_settype'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_rate'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_close'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_malloc'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_period_size'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutex_timedlock'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutexattr_destroy'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_drain'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_free'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_create'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_open'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_set_format'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_writei'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_mutexattr_init'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_hw_params_any'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `snd_pcm_prepare'
/root/c++/libs/libdvrnetsdk.so: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status

The first thing I did after this error was to include the libraries -lpthread -lasound, I also worked on the parameters order but did not work. I appriciate any help.

Elmo
  • 19
  • 1
  • 6

2 Answers2

1

did you try with just -pthread as the linker flag...sometimes it does notw ork with -lpthread...

This should work

g++ -m32 testLogin.cpp -L/root/c++/libs -ldvrnetsdk -pthread -lasound

basav
  • 1,475
  • 12
  • 20
0

With gcc, ordering of linking does matter.

So, try with different order.

 g++ -m32 testLogin.cpp  -L/root/c++/libs -lpthread -lasound -ldvrnetsdk -o testLoginO

See this question for order: Why does the order in which libraries are linked sometimes cause errors in GCC?

Alternatively, you can use start-group option.

gcc -m32 testLogin.cpp  -L/root/c++/libs -Wl,--start-group -lpthread -lasound -ldvrnetsdk -Wl,--end-group -o testLoginO

Edit: As you still get the error, use nm on strings on your library and check if the symbols for which linker error is given are in the library or not. Check for library version. You might be on 64-bit kernel.

Community
  • 1
  • 1
doptimusprime
  • 9,115
  • 6
  • 52
  • 90
  • tks! I used your second suggestion, with some modification: gcc -m32 -fuse-ld=bfd testLogin.cpp -L/root/c++/libs -Wl,--start-group -pthread -lasound -ldvrnetsdk -lstdc++ -Wl,--end-group -o testLoginO. It solved the pthread issue but I still have a undefined reference to `snd..." what I think is related to lasound library. Any clue? – Elmo Jan 10 '15 at 15:05