[opensuse] Unable to compile program using POSIX semaphores
I use semaphores in a C++ class, but I get errors when linking my programs. Below is the output when compiling and linking the programs. It seems that the functions related to semaphores are not found by the linker. Could you advise please? g++ -c -ansi -pedantic -Werror -Wall -O3 -W -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -fshort-enums -fno-common use_cb.cpp -o use_cb.o g++ -c -ansi -pedantic -Werror -Wall -O3 -W -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -fshort-enums -fno-common CB.cpp -o CB.o g++ use_cb.o CB.o -o use_cb CB.o: In function `CB::reset()': CB.cpp:(.text+0x1e5): undefined reference to `sem_destroy' CB.cpp:(.text+0x200): undefined reference to `sem_init' CB.o: In function `CB::create(int const&)': CB.cpp:(.text+0x266): undefined reference to `sem_init' CB.o: In function `CB::write(char const*, int const&)': CB.cpp:(.text+0x35f): undefined reference to `sem_post' CB.o: In function `CB::read(char*, int const&)': CB.cpp:(.text+0x3e7): undefined reference to `sem_wait' CB.o: In function `CB::clear()': CB.cpp:(.text+0x565): undefined reference to `sem_destroy' CB.cpp:(.text+0x580): undefined reference to `sem_init' CB.o: In function `CB::release()': CB.cpp:(.text+0x5dc): undefined reference to `sem_destroy' CB.cpp:(.text+0x5f7): undefined reference to `sem_init' CB.cpp:(.text+0x62f): undefined reference to `sem_destroy' collect2: ld returned 1 exit status make: *** [use_cb] Error 1 -- Bogdan Cristea -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, 2008-04-24 at 11:26 +0300, Bogdan Cristea wrote:
I use semaphores in a C++ class, but I get errors when linking my programs. Below is the output when compiling and linking the programs. It seems that the functions related to semaphores are not found by the linker. Could you advise please?
g++ -c -ansi -pedantic -Werror -Wall -O3 -W -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -fshort-enums -fno-common use_cb.cpp -o use_cb.o g++ -c -ansi -pedantic -Werror -Wall -O3 -W -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -fshort-enums -fno-common CB.cpp -o CB.o g++ use_cb.o CB.o -o use_cb CB.o: In function `CB::reset()': CB.cpp:(.text+0x1e5): undefined reference to `sem_destroy' CB.cpp:(.text+0x200): undefined reference to `sem_init' CB.o: In function `CB::create(int const&)': CB.cpp:(.text+0x266): undefined reference to `sem_init' CB.o: In function `CB::write(char const*, int const&)': CB.cpp:(.text+0x35f): undefined reference to `sem_post' CB.o: In function `CB::read(char*, int const&)': CB.cpp:(.text+0x3e7): undefined reference to `sem_wait' CB.o: In function `CB::clear()': CB.cpp:(.text+0x565): undefined reference to `sem_destroy' CB.cpp:(.text+0x580): undefined reference to `sem_init' CB.o: In function `CB::release()': CB.cpp:(.text+0x5dc): undefined reference to `sem_destroy' CB.cpp:(.text+0x5f7): undefined reference to `sem_init' CB.cpp:(.text+0x62f): undefined reference to `sem_destroy' collect2: ld returned 1 exit status make: *** [use_cb] Error 1
#include
-- Bogdan Cristea -- Roger Oberholtzer
OPQ Systems / Ramböll RST Ramböll Sverige AB Kapellgränd 7 P.O. Box 4205 SE-102 65 Stockholm, Sweden Office: Int +46 8-615 60 20 Mobile: Int +46 70-815 1696 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
* Bogdan Cristea (cristeab@gmail.com) [20080424 10:27]:
It seems that the functions related to semaphores are not found by the linker. Could you advise please?
CB.cpp:(.text+0x5dc): undefined reference to `sem_destroy' CB.cpp:(.text+0x5f7): undefined reference to `sem_init' CB.cpp:(.text+0x62f): undefined reference to `sem_destroy'
You need to link to libpthread i.e. add -lpthread to the compiler options. Philipp PS opensuse-programing would have been the better place top ask such questions. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 2008-04-24 14:26, Philipp Thomas wrote:
* Bogdan Cristea (cristeab@gmail.com) [20080424 10:27]:
It seems that the functions related to semaphores are not found by the linker. Could you advise please?
CB.cpp:(.text+0x5dc): undefined reference to `sem_destroy' CB.cpp:(.text+0x5f7): undefined reference to `sem_init' CB.cpp:(.text+0x62f): undefined reference to `sem_destroy'
You need to link to libpthread i.e. add -lpthread to the compiler options.
Philipp
PS opensuse-programing would have been the better place top ask such questions.
Original mail was sent to Cc. You stripped that out :p -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, 25 Apr 2008 20:22:33 +0200 (CEST), Jan Engelhardt wrote:
Original mail was sent to Cc. You stripped that out :p
Nope, it was sent to programming@opensuse.org which is a non-existing address :-) Philipp -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sat, 26 Apr 2008 16:49:08 +0200
Philipp Thomas
On Fri, 25 Apr 2008 20:22:33 +0200 (CEST), Jan Engelhardt wrote:
Original mail was sent to Cc. You stripped that out :p
Nope, it was sent to programming@opensuse.org which is a non-existing address :-)
S/B
opensuse-programming@opensuse.org
--
--
Jerry Feldman
participants (6)
-
Bogdan Cristea
-
Jan Engelhardt
-
Jerry Feldman
-
Philipp Thomas
-
Philipp Thomas
-
Roger Oberholtzer