simple thread program hardtocompile/link with 1.46.1
Dear boost program(for c++,(or g++)):
after I download 1.46.1 and try to baseon it to compile a simple
program from book C++cookbook, at page 447, 12.1 Creating a Thread
----------
// example 12-1. Creating a thread
#include <iostream>
#include
AMDG On 05/21/2011 11:23 PM, Eric Lin wrote:
Dear boost program(for c++,(or g++)): after I download 1.46.1 and try to base on it to compile a simple program from book C++cookbook, at page 447, 12.1 Creating a Thread
You need to build the thread library. See http://www.boost.org/more/getting_started/unix-variants.html If you've already compiled the library, try -lboost_thread. If you didn't install the libraries to a system location, then you'll also need -L/path/to/compiled/libraries
----------
// example 12-1. Creating a thread #include <iostream> #include
#include struct MyThreadFunc { void operator()() { // Do something long-running... } } threadFun;
int main() { boost::thread myThread(threadFun); // Create a thread that starts // running threadFun boost::thread::yield(); // give up the main thread's timeslice // so the child thread can get some work // done.
// Go do some other work...
myThread.join(); // The current (i.e., main) thread will wait // for myThread to finish before it returns }
-----------------------------------------------------------
eric@eric-laptop:~/cppcookbook$ ls example12-1.cpp eric@eric-laptop:~/cppcookbook$ g++ -I/home/eric/boost1/boost_1_46_1/ example12-1.cpp -lboost_thread-mt /usr/bin/ld: cannot find -lboost_thread-mt collect2: ld returned 1 exit status eric@eric-laptop:~/cppcookbook$ g++ -I/home/eric/boost1/boost_1_46_1/ example12-1.cpp -lboost /usr/bin/ld: cannot find -lboost collect2: ld returned 1 exit status eric@eric-laptop:~/cppcookbook$ cd ../boost1/boost_1_46_1/ eric@eric-laptop:~/boost1/boost_1_46_1$
--------------------------
I am in Ubuntu linux 10.04, g++ 4.4.3
looking to see any suggestion and thanks a lot in advance, Eric Lin, Us citizen, in Los Angeles I am glad to meet anyone in Los Angeles on computer science meeting
In Christ, Steven Watanabe
Dear Steven or any boost programers/users: I tried ./bootstrap.sh ./bjam ./bjam install in my /boost_1_46_1/ directory which is auto extracted by my ubuntu linux after download but I got the following build/compile errors:(these are just small portion of all errors)(c++ compiler is g++ of gnu on intel) ------------------------------ cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a" "/usr/local/lib/libboost_math_c99f.a" ...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a': Permission denied cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99l.a" "/usr/local/lib/libboost_math_c99l.a" ...failed common.copy /usr/local/lib/libboost_math_c99l.a... common.copy /usr/local/lib/libboost_program_options.a cp: cannot create regular file `/usr/local/lib/libboost_program_options.a': Permission denied cp "bin.v2/libs/program_options/build/gcc-4.4.3/release/link-static/threading-multi/libboost_program_options.a" "/usr/local/lib/libboost_program_options.a" ...failed common.copy /usr/local/lib/libboost_program_options.a... common.copy /usr/local/lib/libboost_python.a cp: cannot create regular file `/usr/local/lib/libboost_python.a': Permission denied cp "bin.v2/libs/python/build/gcc-4.4.3/release/link-static/threading-multi/libboost_python.a" "/usr/local/lib/libboost_python.a" ...failed common.copy /usr/local/lib/libboost_python.a... common.copy /usr/local/lib/libboost_random.a cp: cannot create regular file `/usr/local/lib/libboost_random.a': Permission denied cp "bin.v2/libs/random/build/gcc-4.4.3/release/link-static/threading-multi/libboost_random.a" "/usr/local/lib/libboost_random.a" ...failed common.copy /usr/local/lib/libboost_random.a... common.copy /usr/local/lib/libboost_serialization.a cp: cannot create regular file `/usr/local/lib/libboost_serialization.a': Permission denied cp "bin.v2/libs/serialization/build/gcc-4.4.3/release/link-static/threading-multi/libboost_serialization.a" "/usr/local/lib/libboost_serialization.a" ...failed common.copy /usr/local/lib/libboost_serialization.a... common.copy /usr/local/lib/libboost_wserialization.a cp: cannot create regular file `/usr/local/lib/libboost_wserialization.a': Permission denied cp "bin.v2/libs/serialization/build/gcc-4.4.3/release/link-static/threading-multi/libboost_wserialization.a" "/usr/local/lib/libboost_wserialization.a" ...failed common.copy /usr/local/lib/libboost_wserialization.a... common.copy /usr/local/lib/libboost_signals.a cp: cannot create regular file `/usr/local/lib/libboost_signals.a': Permission denied cp "bin.v2/libs/signals/build/gcc-4.4.3/release/link-static/threading-multi/libboost_signals.a" "/usr/local/lib/libboost_signals.a" ...failed common.copy /usr/local/lib/libboost_signals.a... common.copy /usr/local/lib/libboost_prg_exec_monitor.a cp: cannot create regular file `/usr/local/lib/libboost_prg_exec_monitor.a': Permission denied cp "bin.v2/libs/test/build/gcc-4.4.3/release/link-static/threading-multi/libboost_prg_exec_monitor.a" "/usr/local/lib/libboost_prg_exec_monitor.a" ...failed common.copy /usr/local/lib/libboost_prg_exec_monitor.a... common.copy /usr/local/lib/libboost_unit_test_framework.a cp: cannot create regular file `/usr/local/lib/libboost_unit_test_framework.a': Permission denied cp "bin.v2/libs/test/build/gcc-4.4.3/release/link-static/threading-multi/libboost_unit_test_framework.a" "/usr/local/lib/libboost_unit_test_framework.a" ...failed common.copy /usr/local/lib/libboost_unit_test_framework.a... common.copy /usr/local/lib/libboost_thread.a cp: cannot create regular file `/usr/local/lib/libboost_thread.a': Permission denied cp "bin.v2/libs/thread/build/gcc-4.4.3/release/link-static/threading-multi/libboost_thread.a" "/usr/local/lib/libboost_thread.a" ...failed common.copy /usr/local/lib/libboost_thread.a... common.copy /usr/local/lib/libboost_wave.a cp: cannot create regular file `/usr/local/lib/libboost_wave.a': Permission denied cp "bin.v2/libs/wave/build/gcc-4.4.3/release/link-static/threading-multi/libboost_wave.a" "/usr/local/lib/libboost_wave.a" ...failed common.copy /usr/local/lib/libboost_wave.a... ...failed updating 46 targets... ...skipped 8335 targets... eric@eric-laptop:~/boost1/boost_1_46_1$ ----------------------------------------- looking to see any boost programers or users's help, thanks a lot in advnace, Eric ---------------------------------------- Date: Sun, 22 May 2011 08:05:02 -0700 From: watanabesj@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hardtocompile/link with 1.46.1 AMDG On 05/21/2011 11:23 PM, Eric Lin wrote:
Dear boost program(for c++,(or g++)): after I download 1.46.1 and try to base on it to compile a simple program from book C++cookbook, at page 447, 12.1 Creating a Thread
You need to build the thread library. See http://www.boost.org/more/getting_started/unix-variants.html If you've already compiled the library, try -lboost_thread. If you didn't install the libraries to a system location, then you'll also need -L/path/to/compiled/libraries
----------
// example 12-1. Creating a thread #include #include #include
struct MyThreadFunc { void operator()() { // Do something long-running... } } threadFun;
int main() { boost::thread myThread(threadFun); // Create a thread that starts // running threadFun boost::thread::yield(); // give up the main thread's timeslice // so the child thread can get some work // done.
// Go do some other work...
myThread.join(); // The current (i.e., main) thread will wait // for myThread to finish before it returns }
-----------------------------------------------------------
eric@eric-laptop:~/cppcookbook$ ls example12-1.cpp eric@eric-laptop:~/cppcookbook$ g++ -I/home/eric/boost1/boost_1_46_1/ example12-1.cpp -lboost_thread-mt /usr/bin/ld: cannot find -lboost_thread-mt collect2: ld returned 1 exit status eric@eric-laptop:~/cppcookbook$ g++ -I/home/eric/boost1/boost_1_46_1/ example12-1.cpp -lboost /usr/bin/ld: cannot find -lboost collect2: ld returned 1 exit status eric@eric-laptop:~/cppcookbook$ cd ../boost1/boost_1_46_1/ eric@eric-laptop:~/boost1/boost_1_46_1$
--------------------------
I am in Ubuntu linux 10.04, g++ 4.4.3
looking to see any suggestion and thanks a lot in advance, Eric Lin, Us citizen, in Los Angeles I am glad to meet anyone in Los Angeles on computer science meeting
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On May 22, 2011, at 7:09 PM, Eric Lin wrote:
Dear Steven or any boost programers/users:
I tried ./bootstrap.sh ./bjam ./bjam install
in my /boost_1_46_1/ directory which is auto extracted by my ubuntu linux after download
but I got the following build/compile errors:(these are just small portion of all errors)(c++ compiler is g++ of gnu on intel) ------------------------------ cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a" "/usr/local/lib/libboost_math_c99f.a"
...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a': Permission denied
Looks like you'll need to do sudo ./bjam install in order to get the permissions to install there. or use ./bootstrap.sh --prefix=path/to/installation/prefix to install somewhere else.
AMDG On 05/22/2011 05:09 PM, Eric Lin wrote:
Dear Steven or any boost programers/users:
I tried ./bootstrap.sh ./bjam ./bjam install
in my /boost_1_46_1/ directory which is auto extracted by my ubuntu linux after download
but I got the following build/compile errors:(these are just small portion of all errors)(c++ compiler is g++ of gnu on intel) ------------------------------ cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a" "/usr/local/lib/libboost_math_c99f.a"
...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a': Permission denied
sudo bjam install? Alternately, just use -L/path/to/boost_1_46_1/stage/lib. In Christ, Steven Watanabe
Dear boost programers(especially on linux/g++) : I copied that book's C++ Cookbook example12-1, and download boost lib's 1.46.1 on my Ubuntu Linux/ gnu-g++ system, I am not sure I am configure/install good enough or not. Anyway, I get a.out but when I run a.out ----------- eric@eric-laptop:~/cppcookbook$ ./a.out ./a.out: error while loading shared libraries: libboost_thread.so.1.46.1: cannot open shared object file: No such file or directory ------------- is this what you suppose to get?/* I email both first 2 authors: D. Ryan Stephens and Christopher Diggins, they not yet reply */ /* last 2 authors Jonathan Turkanis and Jeff Cogswell, I can not get their email address */ if not(I guess), where go wrong and how to fix it? --------- I am pretty novice on g++ and linux. Hope the following link help you debug. http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html I also tried root@eric-laptop:/# ldconfig -p | grep -i boost root@eric-laptop:/# -------- I read that link, it seem link will go through my /etc/ld.so.conf.d there are atlas.conf GL.conf i486-linux-gnu.conf libasound2.conf libc.conf Xen.conf so I cat /etc/ld.so.conf.d/libc.conf which show #libc default configuration /usr/local/lib and in my /usr/local/lib I do have libboost_thread.a libboost_thread.so libboost_thread.so.1.46.1 so I really have no idea how to debug/fix plz help Eric, in Los Angeles ---------------------------------------- Date: Sun, 22 May 2011 18:43:01 -0700 From: watanabesj@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hard to compile/link with 1.46.1 AMDG On 05/22/2011 05:09 PM, Eric Lin wrote:
Dear Steven or any boost programers/users:
I tried ./bootstrap.sh ./bjam ./bjam install
in my /boost_1_46_1/ directory which is auto extracted by my ubuntu linux after download
but I got the following build/compile errors:(these are just small portion of all errors)(c++ compiler is g++ of gnu on intel) ------------------------------ cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a" "/usr/local/lib/libboost_math_c99f.a"
...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a': Permission denied
sudo bjam install? Alternately, just use -L/path/to/boost_1_46_1/stage/lib. In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
You need to link it statically. By default gcc will link dynamically. use
g++ -static flag, and you should be good to go
On Mon, May 23, 2011 at 10:24 PM, Eric Lin
Dear boost programers(especially on linux/g++) : I copied that book's C++ Cookbook example12-1, and download boost lib's 1.46.1 on my Ubuntu Linux/ gnu-g++ system, I am not sure I am configure/install good enough or not. Anyway, I get a.out but when I run a.out ----------- eric@eric-laptop:~/cppcookbook$ ./a.out ./a.out: error while loading shared libraries: libboost_thread.so.1.46.1: cannot open shared object file: No such file or directory ------------- is this what you suppose to get?/* I email both first 2 authors: D. Ryan Stephens and Christopher Diggins, they not yet reply */ /* last 2 authors Jonathan Turkanis and Jeff Cogswell, I can not get their email address */ if not(I guess), where go wrong and how to fix it? --------- I am pretty novice on g++ and linux. Hope the following link help you debug.
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
I also tried root@eric-laptop:/# ldconfig -p | grep -i boost root@eric-laptop:/# -------- I read that link, it seem link will go through my /etc/ld.so.conf.d there are atlas.conf GL.conf i486-linux-gnu.conf libasound2.conf libc.conf Xen.conf
so I cat /etc/ld.so.conf.d/libc.conf
which show #libc default configuration /usr/local/lib
and in my /usr/local/lib I do have libboost_thread.a libboost_thread.so libboost_thread.so.1.46.1
so I really have no idea how to debug/fix plz help Eric, in Los Angeles ---------------------------------------- Date: Sun, 22 May 2011 18:43:01 -0700 From: watanabesj@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hard to compile/link with 1.46.1
AMDG
On 05/22/2011 05:09 PM, Eric Lin wrote:
Dear Steven or any boost programers/users:
I tried ./bootstrap.sh ./bjam ./bjam install
in my /boost_1_46_1/ directory which is auto extracted by my ubuntu linux
after download
but I got the following build/compile errors:(these are just small
portion of all errors)(c++ compiler is g++ of gnu on intel)
------------------------------ cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a" "/usr/local/lib/libboost_math_c99f.a"
...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a': Permission denied
sudo bjam install? Alternately, just use -L/path/to/boost_1_46_1/stage/lib.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
dear Kaz (and/or boost of c++ programers, especially on Linux/gnu-g++): I tried to follow your suggestion -------- eric@eric-laptop:~/cppcookbook$ g++ -static example12-1.cpp -lboost_thread /tmp/cc0nDT5t.o: In function `boost::mutex::mutex()': example12-1.cpp:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x17): undefined reference to `pthread_mutex_init' /tmp/cc0nDT5t.o: In function `boost::mutex::~mutex()': example12-1.cpp:(.text._ZN5boost5mutexD1Ev[boost::mutex::~mutex()]+0xd): undefined reference to `pthread_mutex_destroy' /tmp/cc0nDT5t.o: In function `boost::condition_variable::condition_variable()': example12-1.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x17): undefined reference to `pthread_mutex_init' example12-1.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x67): undefined reference to `pthread_cond_init' example12-1.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x7b): undefined reference to `pthread_mutex_destroy' /tmp/cc0nDT5t.o: In function `boost::condition_variable::~condition_variable()': example12-1.cpp:(.text._ZN5boost18condition_variableD1Ev[boost::condition_variable::~condition_variable()]+0xd): undefined reference to `pthread_mutex_destroy' example12-1.cpp:(.text._ZN5boost18condition_variableD1Ev[boost::condition_variable::~condition_variable()]+0x43): undefined reference to `pthread_cond_destroy' /usr/local/lib/libboost_thread.a(thread.o): In function `boost::detail::(anonymous namespace)::create_current_thread_tls_key()': thread.cpp:(.text+0x196): undefined reference to `pthread_key_create' /usr/local/lib/libboost_thread.a(thread.o): In function `T.1155': thread.cpp:(.text+0x1d3): undefined reference to `pthread_mutex_lock' thread.cpp:(.text+0x205): undefined reference to `pthread_mutex_unlock' thread.cpp:(.text+0x240): undefined reference to `pthread_cond_wait' thread.cpp:(.text+0x27c): undefined reference to `pthread_mutex_unlock' thread.cpp:(.text+0x290): undefined reference to `pthread_key_create' thread.cpp:(.text+0x29c): undefined reference to `pthread_mutex_lock' thread.cpp:(.text+0x2cf): undefined reference to `pthread_cond_broadcast' thread.cpp:(.text+0x2ed): undefined reference to `pthread_mutex_unlock' /usr/local/lib/libboost_thread.a(thread.o): In function `boost::detail::get_current_thread_data()': ----------------------------------------------------------------------------------------- ----------------------------------This is just small portion of whole error of compile from my g++ ------------------------------------------------------------------------------------------------- But if I follow Brian's suggestion, it work ------------ eric@eric-laptop:~/cppcookbook$ g++ example12-1.cpp -lboost_thread eric@eric-laptop:~/cppcookbook$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./a.out eric@eric-laptop:~/cppcookbook$ -------------------------- any comment on first example is welcome any simplify setup(like change link lib process(I guess, but not sure), chage env or path on my Linux Bash shell) is welcome thanks a lot in advance, Eric/*love to attend any free meeting on topic of computer science in LA */ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ________________________________
Date: Mon, 23 May 2011 23:19:56 +0100 From: sfx810@googlemail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hard to compile/link with 1.46.1
You need to link it statically. By default gcc will link dynamically. use g++ -static flag, and you should be good to go
On Mon, May 23, 2011 at 10:24 PM, Eric Lin
wrote:
Dear boost programers(especially on linux/g++) : I copied that book's C++ Cookbook example12-1, and download boost lib's 1.46.1 on my Ubuntu Linux/ gnu-g++ system, I am not sure I am configure/install good enough or not. Anyway, I get a.out but when I run a.out ----------- eric@eric-laptop:~/cppcookbook$ ./a.out ./a.out: error while loading shared libraries: libboost_thread.so.1.46.1: cannot open shared object file: No such file or directory ------------- is this what you suppose to get?/* I email both first 2 authors: D. Ryan Stephens and Christopher Diggins, they not yet reply */ /* last 2 authors Jonathan Turkanis and Jeff Cogswell, I can not get their email address */ if not(I guess), where go wrong and how to fix it? --------- I am pretty novice on g++ and linux. Hope the following link help you debug.
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
I also tried root@eric-laptop:/# ldconfig -p | grep -i boost root@eric-laptop:/# -------- I read that link, it seem link will go through my /etc/ld.so.conf.d there are atlas.conf GL.conf i486-linux-gnu.conf libasound2.conf libc.conf Xen.conf
so I cat /etc/ld.so.conf.d/libc.conf
which show #libc default configuration /usr/local/lib
and in my /usr/local/lib I do have libboost_thread.a libboost_thread.so libboost_thread.so.1.46.1
so I really have no idea how to debug/fix plz help Eric, in Los Angeles ---------------------------------------- Date: Sun, 22 May 2011 18:43:01 -0700 From: watanabesj@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hard to compile/link with 1.46.1
AMDG
On 05/22/2011 05:09 PM, Eric Lin wrote:
Dear Steven or any boost programers/users:
I tried ./bootstrap.sh ./bjam ./bjam install
in my /boost_1_46_1/ directory which is auto extracted by my ubuntu
linux after download
but I got the following build/compile errors:(these are just small
portion of all errors)(c++ compiler is g++ of gnu on intel)
------------------------------ cp "bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a" "/usr/local/lib/libboost_math_c99f.a"
...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a': Permission denied
sudo bjam install? Alternately, just use -L/path/to/boost_1_46_1/stage/lib.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I think you are not linking pthread.
you need to link both ( -lpthread -lboost_thread ).
g++ -static -I(Path to boost include) -L(path to boost library) yourfile.cpp
-lboost_thread -lpthread -o yourOutputExe.out
(plz ignore any typo).
Thanks.
Kaz
On Tue, May 24, 2011 at 6:15 AM, Eric Lin
dear Kaz (and/or boost of c++ programers, especially on Linux/gnu-g++):
I tried to follow your suggestion -------- eric@eric-laptop:~/cppcookbook$ g++ -static example12-1.cpp -lboost_thread /tmp/cc0nDT5t.o: In function `boost::mutex::mutex()': example12-1.cpp:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x17): undefined reference to `pthread_mutex_init' /tmp/cc0nDT5t.o: In function `boost::mutex::~mutex()': example12-1.cpp:(.text._ZN5boost5mutexD1Ev[boost::mutex::~mutex()]+0xd): undefined reference to `pthread_mutex_destroy' /tmp/cc0nDT5t.o: In function `boost::condition_variable::condition_variable()': example12-1.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x17): undefined reference to `pthread_mutex_init' example12-1.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x67): undefined reference to `pthread_cond_init' example12-1.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x7b): undefined reference to `pthread_mutex_destroy' /tmp/cc0nDT5t.o: In function `boost::condition_variable::~condition_variable()': example12-1.cpp:(.text._ZN5boost18condition_variableD1Ev[boost::condition_variable::~condition_variable()]+0xd): undefined reference to `pthread_mutex_destroy' example12-1.cpp:(.text._ZN5boost18condition_variableD1Ev[boost::condition_variable::~condition_variable()]+0x43): undefined reference to `pthread_cond_destroy' /usr/local/lib/libboost_thread.a(thread.o): In function `boost::detail::(anonymous namespace)::create_current_thread_tls_key()': thread.cpp:(.text+0x196): undefined reference to `pthread_key_create' /usr/local/lib/libboost_thread.a(thread.o): In function `T.1155': thread.cpp:(.text+0x1d3): undefined reference to `pthread_mutex_lock' thread.cpp:(.text+0x205): undefined reference to `pthread_mutex_unlock' thread.cpp:(.text+0x240): undefined reference to `pthread_cond_wait' thread.cpp:(.text+0x27c): undefined reference to `pthread_mutex_unlock' thread.cpp:(.text+0x290): undefined reference to `pthread_key_create' thread.cpp:(.text+0x29c): undefined reference to `pthread_mutex_lock' thread.cpp:(.text+0x2cf): undefined reference to `pthread_cond_broadcast' thread.cpp:(.text+0x2ed): undefined reference to `pthread_mutex_unlock' /usr/local/lib/libboost_thread.a(thread.o): In function `boost::detail::get_current_thread_data()':
----------------------------------------------------------------------------------------- ----------------------------------This is just small portion of whole error of compile from my g++
------------------------------------------------------------------------------------------------- But if I follow Brian's suggestion, it work ------------ eric@eric-laptop:~/cppcookbook$ g++ example12-1.cpp -lboost_thread eric@eric-laptop:~/cppcookbook$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./a.out eric@eric-laptop:~/cppcookbook$
-------------------------- any comment on first example is welcome any simplify setup(like change link lib process(I guess, but not sure), chage env or path on my Linux Bash shell) is welcome
thanks a lot in advance, Eric/*love to attend any free meeting on topic of computer science in LA */
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
________________________________
Date: Mon, 23 May 2011 23:19:56 +0100 From: sfx810@googlemail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hard to compile/link with 1.46.1
You need to link it statically. By default gcc will link dynamically. use g++ -static flag, and you should be good to go
On Mon, May 23, 2011 at 10:24 PM, Eric Lin
wrote:
Dear boost programers(especially on linux/g++) : I copied that book's C++ Cookbook example12-1, and download boost lib's 1.46.1 on my Ubuntu Linux/ gnu-g++ system, I am not sure I am configure/install good enough or not. Anyway, I get a.out but when I run a.out ----------- eric@eric-laptop:~/cppcookbook$ ./a.out ./a.out: error while loading shared libraries: libboost_thread.so.1.46.1: cannot open shared object file: No such file or directory ------------- is this what you suppose to get?/* I email both first 2 authors: D. Ryan Stephens and Christopher Diggins, they not yet reply */ /* last 2 authors Jonathan Turkanis and Jeff Cogswell, I can not get their email address */ if not(I guess), where go wrong and how to fix it? --------- I am pretty novice on g++ and linux. Hope the following link help you debug.
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
I also tried root@eric-laptop:/# ldconfig -p | grep -i boost root@eric-laptop:/# -------- I read that link, it seem link will go through my /etc/ld.so.conf.d there are atlas.conf GL.conf i486-linux-gnu.conf libasound2.conf libc.conf Xen.conf
so I cat /etc/ld.so.conf.d/libc.conf
which show #libc default configuration /usr/local/lib
and in my /usr/local/lib I do have libboost_thread.a libboost_thread.so libboost_thread.so.1.46.1
so I really have no idea how to debug/fix plz help Eric, in Los Angeles ---------------------------------------- Date: Sun, 22 May 2011 18:43:01 -0700 From: watanabesj@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] simple thread program hard to compile/link with 1.46.1
AMDG
On 05/22/2011 05:09 PM, Eric Lin wrote:
Dear Steven or any boost programers/users:
I tried ./bootstrap.sh ./bjam ./bjam install
in my /boost_1_46_1/ directory which is auto extracted by my ubuntu
linux after download
but I got the following build/compile errors:(these are just small
portion of all errors)(c++ compiler is g++ of gnu on intel)
------------------------------ cp
"bin.v2/libs/math/build/gcc-4.4.3/release/link-static/threading-multi/libboost_math_c99f.a"
"/usr/local/lib/libboost_math_c99f.a"
...failed common.copy /usr/local/lib/libboost_math_c99f.a... common.copy /usr/local/lib/libboost_math_c99l.a cp: cannot create regular file `/usr/local/lib/libboost_math_c99l.a':
Permission denied
sudo bjam install? Alternately, just use -L/path/to/boost_1_46_1/stage/lib.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Mon, May 23, 2011 at 2:24 PM, Eric Lin
and in my /usr/local/lib I do have libboost_thread.a libboost_thread.so libboost_thread.so.1.46.1
The easy way to deal with this is to add /usr/local/lib to your LD_LIBRARY_PATH variable, which would look like this: eric@eric-laptop:~/cppcookbook$ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./a.out Brian
participants (5)
-
Brian Budge
-
Eric Lin
-
Gordon Woodhull
-
Kaz
-
Steven Watanabe