Boost logo

Boost Users :

Subject: Re: [Boost-users] simple thread program
From: Kaz (sfx810_at_[hidden])
Date: 2011-05-24 04:36:02


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 <kingdavid1_at_[hidden]> wrote:

>
> dear Kaz (and/or boost of c++ programers, especially on Linux/gnu-g++):
>
> I tried to follow your suggestion
> --------
> eric_at_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_at_eric-laptop:~/cppcookbook$ g++ example12-1.cpp -lboost_thread
> eric_at_eric-laptop:~/cppcookbook$
> LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./a.out
> eric_at_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_at_[hidden]
> > To: boost-users_at_[hidden]
> > 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_at_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_at_eric-laptop:/# ldconfig -p | grep -i boost
> > root_at_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_at_[hidden]
> > To: boost-users_at_[hidden]
> > 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_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
> >
> > _______________________________________________ Boost-users mailing
> > list Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net