Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-13-2006, 05:25 AM
|
#1
|
LQ Newbie
Registered: Feb 2006
Posts: 4
Rep:
|
boost library
hi..
I've installed Boost library from an rpm (Mandriva.2006) and now I want to use Boost.Thread..
I've tried to compile an example file but I've received many errors from, I think, the linker. How can I link boost shared library? They are in /usr/include/boost..
thanks
|
|
|
04-13-2006, 05:45 AM
|
#2
|
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851
Rep:
|
What are the errors? Post your compiler/linker output, and possibly your program's source code (or just the section with which you're having trouble) please.
Last edited by scuzzman; 04-13-2006 at 05:46 AM.
|
|
|
04-13-2006, 12:32 PM
|
#3
|
LQ Newbie
Registered: Feb 2006
Posts: 4
Original Poster
Rep:
|
source code:
Code:
#include <iostream>
#include <vector>
#include <boost/utility.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/thread.hpp>
class bounded_buffer : private boost::noncopyable
{
public:
typedef boost::mutex::scoped_lock lock;
bounded_buffer(int n) : begin(0), end(0), buffered(0), circular_buf(n) { }
void send (int m) {
lock lk(monitor);
while (buffered == circular_buf.size())
buffer_not_full.wait(lk);
circular_buf[end] = m;
end = (end+1) % circular_buf.size();
++buffered;
buffer_not_empty.notify_one();
}
int receive() {
lock lk(monitor);
while (buffered == 0)
buffer_not_empty.wait(lk);
int i = circular_buf[begin];
begin = (begin+1) % circular_buf.size();
--buffered;
buffer_not_full.notify_one();
return i;
}
private:
int begin, end, buffered;
std::vector<int> circular_buf;
boost::condition buffer_not_full, buffer_not_empty;
boost::mutex monitor;
};
bounded_buffer buf(2);
void sender() {
int n = 0;
while (n < 100) {
buf.send(n);
std::cout << "sent: " << n << std::endl;
++n;
}
buf.send(-1);
}
void receiver() {
int n;
do {
n = buf.receive();
std::cout << "received: " << n << std::endl;
} while (n != -1); // -1 indicates end of buffer
}
int main(int, char*[])
{
boost::thread thrd1(&sender);
boost::thread thrd2(&receiver);
thrd1.join();
thrd2.join();
return 0;
}
the command is: g++ condition.cpp -o condition
Code:
/home/juri/tmp/ccsbveqQ.o: In function `main':
condition.cpp:(.text+0x3f): undefined reference to `boost::thread::thread(boost::function0<void, std::allocator<boost::function_base> > const&)'
condition.cpp:(.text+0x9c): undefined reference to `boost::thread::thread(boost::function0<void, std::allocator<boost::function_base> > const&)'
condition.cpp:(.text+0xd6): undefined reference to `boost::thread::join()'
condition.cpp:(.text+0xe5): undefined reference to `boost::thread::join()'
condition.cpp:(.text+0xfb): undefined reference to `boost::thread::~thread()'
condition.cpp:(.text+0x112): undefined reference to `boost::thread::~thread()'
condition.cpp:(.text+0x126): undefined reference to `boost::thread::~thread()'
condition.cpp:(.text+0x143): undefined reference to `boost::thread::~thread()'
/home/juri/tmp/ccsbveqQ.o: In function `boost::condition::condition()':
condition.cpp:(.gnu.linkonce.t._ZN5boost9conditionC1Ev[boost::condition::condition()]+0x21): undefined reference to `boost::detail::condition_impl::condition_impl()'
/home/juri/tmp/ccsbveqQ.o: In function `boost::condition::~condition()':
condition.cpp:(.gnu.linkonce.t._ZN5boost9conditionD1Ev[boost::condition::~condition()]+0x12): undefined reference to `boost::detail::condition_impl::~condition_impl()'
/home/juri/tmp/ccsbveqQ.o: In function `boost::condition::notify_one()':
condition.cpp:(.gnu.linkonce.t._ZN5boost9condition10notify_oneEv[boost::condition::notify_one()]+0x11): undefined reference to `boost::detail::condition_impl::notify_one()'
/home/juri/tmp/ccsbveqQ.o: In function `boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&)':
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread8lock_opsINS_5mutexEE4lockERS3_[boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&)]+0xd): undefined reference to `boost::mutex::do_lock()'
/home/juri/tmp/ccsbveqQ.o: In function `boost::detail::thread::scoped_lock<boost::mutex>::lock()':
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE4lockEv[boost::detail::thread::scoped_lock<boost::mutex>::lock()]+0x29): undefined reference to `boost::lock_error::lock_error()'
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE4lockEv[boost::detail::thread::scoped_lock<boost::mutex>::lock()]+0x34): undefined reference to `boost::lock_error::~lock_error()'
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE4lockEv[boost::detail::thread::scoped_lock<boost::mutex>::lock()]+0x39): undefined reference to `typeinfo for boost::lock_error'
/home/juri/tmp/ccsbveqQ.o: In function `boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&)':
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread8lock_opsINS_5mutexEE6unlockERS3_[boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&)]+0xd): undefined reference to `boost::mutex::do_unlock()'
/home/juri/tmp/ccsbveqQ.o: In function `boost::detail::thread::scoped_lock<boost::mutex>::unlock()':
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE6unlockEv[boost::detail::thread::scoped_lock<boost::mutex>::unlock()]+0x2c): undefined reference to `boost::lock_error::lock_error()'
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE6unlockEv[boost::detail::thread::scoped_lock<boost::mutex>::unlock()]+0x37): undefined reference to `boost::lock_error::~lock_error()'
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread11scoped_lockINS_5mutexEE6unlockEv[boost::detail::thread::scoped_lock<boost::mutex>::unlock()]+0x3c): undefined reference to `typeinfo for boost::lock_error'
/home/juri/tmp/ccsbveqQ.o: In function `boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&, boost::mutex::cv_state&)':
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread8lock_opsINS_5mutexEE6unlockERS3_RNS3_8cv_stateE[boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&, boost::mutex::cv_state&)]+0x10): undefined reference to `boost::mutex::do_unlock(boost::mutex::cv_state&)'
/home/juri/tmp/ccsbveqQ.o: In function `boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&, boost::mutex::cv_state&)':
condition.cpp:(.gnu.linkonce.t._ZN5boost6detail6thread8lock_opsINS_5mutexEE4lockERS3_RNS3_8cv_stateE[boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&, boost::mutex::cv_state&)]+0x10): undefined reference to `boost::mutex::do_lock(boost::mutex::cv_state&)'
/home/juri/tmp/ccsbveqQ.o: In function `void boost::condition::do_wait<boost::mutex>(boost::mutex&)':
condition.cpp:(.gnu.linkonce.t._ZN5boost9condition7do_waitINS_5mutexEEEvRT_[void boost::condition::do_wait<boost::mutex>(boost::mutex&)]+0x27): undefined reference to `boost::detail::condition_impl::do_wait(pthread_mutex_t*)'
/home/juri/tmp/ccsbveqQ.o: In function `void boost::condition::wait<boost::detail::thread::scoped_lock<boost::mutex> >(boost::detail::thread::scoped_lock<boost::mutex>&)':
condition.cpp:(.gnu.linkonce.t._ZN5boost9condition4waitINS_6detail6thread11scoped_lockINS_5mutexEEEEEvRT_[void boost::condition::wait<boost::detail::thread::scoped_lock<boost::mutex> >(boost::detail::thread::scoped_lock<boost::mutex>&)]+0x36): undefined reference to `boost::lock_error::lock_error()'
condition.cpp:(.gnu.linkonce.t._ZN5boost9condition4waitINS_6detail6thread11scoped_lockINS_5mutexEEEEEvRT_[void boost::condition::wait<boost::detail::thread::scoped_lock<boost::mutex> >(boost::detail::thread::scoped_lock<boost::mutex>&)]+0x41): undefined reference to `boost::lock_error::~lock_error()'
condition.cpp:(.gnu.linkonce.t._ZN5boost9condition4waitINS_6detail6thread11scoped_lockINS_5mutexEEEEEvRT_[void boost::condition::wait<boost::detail::thread::scoped_lock<boost::mutex> >(boost::detail::thread::scoped_lock<boost::mutex>&)]+0x46): undefined reference to `typeinfo for boost::lock_error'
/home/juri/tmp/ccsbveqQ.o: In function `bounded_buffer::bounded_buffer(int)':
condition.cpp:(.gnu.linkonce.t._ZN14bounded_bufferC1Ei[bounded_buffer::bounded_buffer(int)]+0x78): undefined reference to `boost::mutex::mutex()'
/home/juri/tmp/ccsbveqQ.o: In function `bounded_buffer::~bounded_buffer()':
condition.cpp:(.gnu.linkonce.t._ZN14bounded_bufferD1Ev[bounded_buffer::~bounded_buffer()]+0x12): undefined reference to `boost::mutex::~mutex()'
collect2: ld returned 1 exit status
thanks
|
|
|
06-09-2006, 03:50 AM
|
#4
|
LQ Newbie
Registered: Jun 2006
Posts: 2
Rep:
|
I also have such a problem. I am using cygwin enviroment.
The library path, as I think, is correct, since if you change the librayname like
g++ -lboost-whats-going-on y.cpp -o y.exe
then the following reported
..../ld cannot find -lboost-whats-going-on
after I corrected it as
g++ -L/usr/lib -boost-program_options_gcc-mt-s-1_33_1 y.cpp -o y.exe
then the name mangling problem found because collect2 cannot find all the boost library
I use
ar -t /usr/lib/libboost-program_options_gcc-mt-s-1_33_1.a
And it shows meaningful results, whereas g++ seemed to do name mangling on my y.cpp
I guess C Linkage has to be applied in y.cpp, but I dont know how...
Best Regards,
|
|
|
07-01-2006, 04:54 AM
|
#5
|
Member
Registered: Jan 2005
Distribution: Archlinux, Debian, Centos
Posts: 222
Rep:
|
Code:
SOURCE := threadtest.cpp
PROG := threadsample
INCLUDES := -I/usr/local/include/boost-1_33_1
LIBPATH := -L/usr/local/lib
LIBS := -lboost_thread-gcc-mt-d
all: $(PROG)
$(PROG): threadtest.o
cc -o $(PROG) threadtest.o $(LIBPATH) $(LIBS)
threadtest.o: $(SOURCE)
cc -c $(SOURCE) $(INCLUDES)
Can you try the following makefile? For my version of boost it worked.
After building the exe, make sure to set the LD_LIBRARY_PATH.
|
|
|
07-04-2006, 10:53 AM
|
#6
|
LQ Newbie
Registered: Jun 2006
Posts: 2
Rep:
|
Hi,
I still get the error report shown in this mail series.
I just
(1) download cygwin, gcc, boost lib from cygwin
(2) copy the threadtest.cpp
(3) copy the makefile
(4) modify includes to /usr/include and libs to /usr/lib because cygwin put boost to those directories
(5) modify to -lboost_thread-gcc-mt-s because i cannot find libboost_thread-gcc-mt-d.a
(6) set LD_LIBRARY_PATH to /usr/lib and verify it through echoing in the shell
Then, should i get a copy of source code of bin utility to debug "collect2" behavior???
Best Regards,
|
|
|
All times are GMT -5. The time now is 10:39 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|