|
Boost Users : |
From: mailbox44_at_[hidden]
Date: 2007-01-01 19:57:23
I think my problem is a simple linking problem. I have looked through the
archives and tried a few things to no avail.
I am trying to compile the simple thread example from the boost site (see
end of message).
I am using 64 bit Redhat linux on a dual core opteron box.
g++ -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
I believe the boost libraries come pre-installed on linux, but just in case
I followed all the directions online and installed the libraries (I just
used whatever defaults the installed runs).
I compile the program below with:
g++ test.cpp (I renamed the sample program test)
and get these errors:
/tmp/cctHP3Df.o(.text+0x169): In function `main':
: undefined reference to `boost::thread::thread(boost::function0<void,
std::allocator<boost::function_base> > const&)'
/tmp/cctHP3Df.o(.text+0x19b): In function `main':
: undefined reference to `boost::thread::join()'
/tmp/cctHP3Df.o(.text+0x1ae): In function `main':
: undefined reference to `boost::thread::~thread()'
/tmp/cctHP3Df.o(.text+0x1c4): In function `main':
: undefined reference to `boost::thread::~thread()'
/tmp/cctHP3Df.o(.gnu.linkonce.t._ZN12thread_alarmclEv+0x16): In function
`thread_alarm::operator()()':
: undefined reference to `boost::xtime_get(boost::xtime*, int)'
/tmp/cctHP3Df.o(.gnu.linkonce.t._ZN12thread_alarmclEv+0x2f): In function
`thread_alarm::operator()()':
: undefined reference to `boost::thread::sleep(boost::xtime const&)'
collect2: ld returned 1 exit status
Based on a few previous messages from the archives, I tried linking in the
thread library (shouldn't gcc find it by itself??)
g++ test.cpp -lboost_thread
and get these errors:
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0x54): In function
`boost::thread::~thread()':
: undefined reference to `pthread_detach'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0x74): In function
`boost::thread::~thread()':
: undefined reference to `pthread_detach'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0xca): In function
`boost::thread::join()':
: undefined reference to `pthread_join'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0x251): In function
`boost::thread_group::join_all()':
: undefined reference to `pthread_join'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0x8b4): In function
`boost::thread_group::~thread_group()':
: undefined reference to `pthread_detach'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0x924): In function
`boost::thread_group::~thread_group()':
: undefined reference to `pthread_detach'
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/libboost_thread.a(t
hrea d.o)(.text+0xb4e): In function
`boost::thread_group::create_thread(boost::functi
on0<void, std::allocator<boost::function_base> > const&)':
: undefined reference to `pthread_detach'
collect2: ld returned 1 exit status
Thanks in advance for any help.
Steve
test.cpp:
#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <iostream>
struct thread_alarm
{
thread_alarm(int secs) : m_secs(secs) { }
void operator()()
{
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += m_secs;
boost::thread::sleep(xt);
std::cout << "alarm sounded..." << std::endl;
}
int m_secs;
};
int main(int argc, char* argv[])
{
int secs = 5;
std::cout << "setting alarm for 5 seconds..." << std::endl;
thread_alarm alarm(secs);
boost::thread thrd(alarm);
thrd.join();
}
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