Monday, December 7, 2009

compiling C++ pthreads code from vim or eclipse

In vim I used this for compiling an ordinary C++ program with
set makeprg=g++\ -ggdb\ -o\ %<\ %




But if I'm using pthreads, I need to specify the pthread library
set makeprg=g++\ -ggdb\ -lpthread\ -o\ %<\ %

And if using Boost::thread this is required
set makeprg=g++\ -ggdb\ -I/usr/include\ -lpthread\ -lboost_thread\ -o\ %<\ %

In eclipse we must specify the pthread library:
1) Select the Project
2) Go to
File->Properties->GCC C++ Linker
3) Add pthread to "Libraries (-l)

No comments: