Error installing OpenCV on Ubuntu 16.04 - opencv

I have being trying to install OpenCV on Ubuntu 16.04 unsing several tutorials and i always end up with an error. This is the last one i've got following this tutorial:
https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-OpenCV-3.1-Installation-Guide
What can i do?
[ 48%] Linking CXX executable ../../bin/opencv_test_viz
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadDirectory#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFIsTiled#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFDefaultStripSize#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadTile#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFWriteScanline#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `_TIFFfree#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFGetField#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFScanlineSize#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFTileSize#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFClose#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFClientOpen#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFGetFieldDefaulted#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFNumberOfDirectories#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFOpen#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadRGBAImage#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetField#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetWarningHandler#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetErrorHandler#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `_TIFFmalloc#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetDirectory#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadScanline#LIBTIFF_4.0'
//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFNumberOfTiles#LIBTIFF_4.0'
collect2: error: ld returned 1 exit status
modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:236: recipe for target 'bin/opencv_test_viz' failed
make[2]: *** [bin/opencv_test_viz] Error 1
CMakeFiles/Makefile2:3306: recipe for target 'modules/viz/CMakeFiles/opencv_test_viz.dir/all' failed
make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

I followed the same tutorial for install opencv and I had the same problem.
This works for me:
sudo apt-get autoremove libtiff5-dev
sudo apt-get install libtiff5-dev
Enter the opencv directory.
cd build/ (I guess that is already created,otherwise create it)
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make
then continue with the tutorial.

According to this, OpenCV needs libtiff4, which Ubuntu has dropped, i.e. the package that replaced it is libtiff5-dev.
As a temporary workaround you can specify -DBUILD_TIFF=ON on cmake when configuring, in order to build the libtiff4 version that is distributed with OpenCV.
This worked for me in Ubuntu 16.04, with OpenCV 3.2.1.

Looks like you need to install/reinstall libpng.

Try make clean ,and then again execute the make command. Generally after one failure if you try the make command without cleaning the earlier installation, you get errors.

I had similar issue. I was building openCV 3.3.0 together with opencv_contrib repository. It turned out that including the flag -D BUILD_TIFF=ON with cmake command resolved the issue as pointed out by gevang already.
Ps.: Since I'm only acknowledging the solution provided by gevang, this should rather a be comment instead of an answer, but I'm missing the corresponding rights. Sorry for that.

Related

Compiling opencv3 get "libgdal.so.20 undefined reference"

While I try to compile opencv3 I got this error:
../../lib/libopencv_imgcodecs.so.3.4.2: undefined reference
"TIFFReadDirectory#LIBTIFF_4.0" //usr/lib/libgdal.so.20: undefined
reference "TIFFLastDirectory#LIBTIFF_4.0"
../../lib/libopencv_imgcodecs.so.3.4.2: undefined reference
"TIFFWriteEncodedStrip#LIBTIFF_4.0"
../../lib/libopencv_imgcodecs.so.3.4.2: undefined reference
"TIFFIsTiled#LIBTIFF_4.0" //usr/lib/libgdal.so.20: undefined reference
"TIFFSwabArrayOfShort#LIBTIFF_4.0" //usr/lib/libgdal.so.20: undefined
reference "TIFFIsByteSwapped#LIBTIFF_4.0" //usr/lib/libgdal.so.20:
undefined reference "TIFFFlushData#LIBTIFF_4.0"
//usr/lib/libgdal.so.20: undefined reference
"TIFFFreeDirectory#LIBTIFF_4.0"
../../lib/libopencv_imgcodecs.so.3.4.2: undefined reference
"TIFFScanlineSize#LIBTIFF_4.0" //usr/lib/libgdal.so.20: undefined
reference "TIFFWriteEncodedTile#LIBTIFF_4.0"
OS: Ubuntu 18.04
How can I solve? I already installed libgdal20 and libgdal-dev
I solved using this (modules) https://github.com/opencv/opencv_contrib
As the README shows I did this:
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
Having directory "opencv" and opencv_contrib in the same directory (my home directory) I typed:
$ cd opencv/build
$ cmake -DOPENCV_EXTRA_MODULES_PATH=/home/helias/opencv/modules /home/helias/opencv
$ make -j 8
Note: 8 = is the number of my CPU cores

Using LAPACK with MINGW64

I am trying to incorporate LAPACK into a program I am trying to compile. I am currently using the msys2 toolchain with the MINGW64 gfortran compiler. I used the following process to obtain LAPACK:
To get BLAS and LAPACK together
In Msys2 64 bit environment type in:
Pacman –S mingw-w64-x86_64-cmake #gets cmake
Pacman –S git #gets git
Git clone https://github.com/msys2/MINGW-packages.git
Cd MINGW-packages/mingw-w64-lapack
Then navigate to ~/MINGW-packages/mingw-w64-lapack and open the file called PKGBUILD. Do a find and replace all from ‘RESPOSE’ to ‘RESPONSE’. Save the file and exit the text editor.
In the msys environment, type:
Makepkg-mingw
Pacman –U mingw-w64-x86_64-lapack*.pkg.tar.gz
BLAS and LAPACK are now installed.
To test lapack, do the following.
> cd ~
> wget http://www.math.ucla.edu/~wotaoyin/software/lapack_test.cpp # download
> g++ lapack_test.cpp -llapack -o lapack_test # build
> ./lapack_test # run
I then attempt to compile the program using LAPACK. My program only calls sgetrf and sgetrs. However, when I compile I receive the following errors:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrf.f.obj):(.text+0x43a): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrf.f.obj):(.text+0x524): undefined reference to `sgemm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x159): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x1c5): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x340): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x3ac): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x1c3): undefined reference to `isamax_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x212): undefined reference to `sswap_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x36c): undefined reference to `sger_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x3ca): undefined reference to `sscal_'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile.all:20: avl] Error 1
What am I missing in linking liblapack.a?
My command is:
gfortran -m64 -o avl avl.o aoper.o amode.o amass.o asetup.o amake.o ainput.o
aoutput.o aero.o atrim.o atpforc.o aic.o cdcl.o airutil.o autil.o aplotvl.o aplo
ttp.o aplotmd.o limits.o pltops.o hidden.o plsubs.o userio.o plutil.o arrow3d.o
getvm.o matrix.o spline.o sgutil.o second.o -static ../plotlib/libPlt_mingwSP.a
../eispack/libeispack.a -lgdi32 -luser32 -lblas -llapack
I wanted to answer my own question as I believe I found the error.
First, it looks like these calls are related to BLAS. So I needed to add -lblas to compile call. However, I initially tried this to no effect and then called -lblas AFTER the -llapack call and it worked.
Here is another solution. Get the code from https://www.gnu.org/software/gcc/testing/testing-lapack.html. Download by clicking on the link lapack.tgz. The make.inc file is already setup (you may have to rename it), so all you have to do is run make.
I went down several blind alleys before getting to this point. I tried them in google order.
http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries gave me four files which are not compatible with gfortran. Maybe I missread the webpage, but at any rate, if the compatible libraries are there, I didn't find them.
https://packages.msys2.org/package/mingw-w64-x86_64-lapack - downloading and unpacking the tar file gives files which don't work with gfortran.
http://www.netlib.org/lapack/ - download and unpack lapack-3.9.0.tar.gz. This is designed to be made on a wide variety of systems, but doesn’t include mingw gfortran. The make files and other scripts are more complicated than I wanted to tackle. One solution is given at https://gcc.gnu.org/wiki/LAPACK%20on%20Windows, but it is 8 years old and would have to be updated.
You know, it is no wonder everyone has abandoned Fortran when it is this difficult do use these standard libraries. The same stuff is built into Python, Matlab or Octave

OpenCV build undefined reference to protobuf built from source

I'm trying to build OpenCV from source. I have protobuf installed to my home directory; it was built with --enable-shared. LD_LIBRARY_PATH has $HOME/lib at the head; LIBRARY_PATH and LD_RUN_PATH are set to $LD_LIBRARY_PATH, and CPATH is set to $HOME/include. PKG_CONFIG_PATH is to $HOME/lib/pkgconfig.
Here are some relevant versions:
opencv==3.1.0
gcc==4.8.5
g++==4.8.5
python==3.5.2
protobuf==2.6.1
My CMake command is
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$HOME -D OPENCV_EXTRA_MODULES_PATH=$HOME/opencv_contrib-3.1.0/modules -D PYTHON_DEFAULT_EXECUTABLE=$HOME/bin/python -D CMAKE_PREFIX_PATH=$HOME ..
cmake succeeds and even says that it found PROTOBUF at <~>/lib/libprotobuf.so. But make fails to find it.
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::InitEmptyString()'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::empty_string_once_init_'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::internal::empty_string_'
../../lib/libopencv_dnn.so.3.1.0: undefined reference to `google::protobuf::io::CodedInputStream::BytesUntilTotalBytesLimit() const'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/opencv_test_dnn] Error 1
make[1]: *** [modules/dnn/CMakeFiles/opencv_test_dnn.dir/all] Error 2
A couple of other places mention that multiple versions of protobuf can cause problems. There is another protobuf in /lib64, but I can't remove it since I don't have root access. So I'm not sure what the workaround is.
I met the same issue recently because I installed the latest protobuf (3.1.0) and built my opencv with GCC 4.9. When I switched back to GCC 5, OpenCV 3.1 can be built successfully.
If you want to use Matlab together with OpenCV 3.1 I think you may need to downgrade your protobuf version, like protobuf-2.5.0, then you can use GCC 4.9 to rebuilt the OpenCV.

tcpreplay installation failed, libpcap/collect

I could not install tcpreplay on RHEL 6.6
When I try to run ./configure I got following error
checking for inet_addr... yes
checking for libpcap... no
configure: error: libpcap not found
[root#tcpreplay-4.1.0]# ldconfig -p | grep libpca
libpcap.so.1 (libc6,x86-64) => /usr/lib64/libpcap.so.1
[root#tcpreplay-4.1.0]#
ldconfig output shows that there is installed libpcap
I also tried with --with-libpcap=/usr/lib64 option but I got same error.
I have another RHEL 6.6 with similar config, I uninstalled tcpdump, libpcap with yum. Installed latest libpcap and tcpdump from tarball without error. I got no error on ./configure command of tcpreplay tarball. (In this installation libpcap installed into /usr/local/lib)
But when I try to make I got following error.
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_activate':
/directory/libpcap-1.7.4/./pcap-dbus.c:185: undefined reference to `dbus_connection_open'
/directory/libpcap-1.7.4/./pcap-dbus.c:191: undefined reference to `dbus_bus_register'
/directory/libpcap-1.7.4/./pcap-dbus.c:230: undefined reference to `dbus_bus_add_match'
/directory/libpcap-1.7.4/./pcap-dbus.c:231: undefined reference to `dbus_error_is_set'
/directory/libpcap-1.7.4/./pcap-dbus.c:232: undefined reference to `dbus_error_free'
/directory/libpcap-1.7.4/./pcap-dbus.c:235: undefined reference to `dbus_bus_add_match'
/directory/libpcap-1.7.4/./pcap-dbus.c:236: undefined reference to `dbus_error_is_set'
/directory/libpcap-1.7.4/./pcap-dbus.c:238: undefined reference to `dbus_error_free'
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_cleanup':
/directory/libpcap-1.7.4/./pcap-dbus.c:143: undefined reference to `dbus_connection_unref'
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_activate':
/directory/libpcap-1.7.4/./pcap-dbus.c:169: undefined reference to `dbus_bus_get'
/directory/libpcap-1.7.4/./pcap-dbus.c:178: undefined reference to `dbus_error_free'
/directory/libpcap-1.7.4/./pcap-dbus.c:227: undefined reference to `dbus_connection_set_max_received_size'
/directory/libpcap-1.7.4/./pcap-dbus.c:176: undefined reference to `dbus_bus_get'
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_cleanup':
/directory/libpcap-1.7.4/./pcap-dbus.c:143: undefined reference to `dbus_connection_unref'
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_activate':
/directory/libpcap-1.7.4/./pcap-dbus.c:193: undefined reference to `dbus_error_free'
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_write':
/directory/libpcap-1.7.4/./pcap-dbus.c:114: undefined reference to `dbus_message_demarshal'
/directory/libpcap-1.7.4/./pcap-dbus.c:120: undefined reference to `dbus_connection_send'
/directory/libpcap-1.7.4/./pcap-dbus.c:121: undefined reference to `dbus_connection_flush'
/directory/libpcap-1.7.4/./pcap-dbus.c:123: undefined reference to `dbus_message_unref'
/directory/libpcap-1.7.4/./pcap-dbus.c:116: undefined reference to `dbus_error_free'
/usr/local/lib/libpcap.a(pcap-dbus.o): In function `dbus_read':
/directory/libpcap-1.7.4/./pcap-dbus.c:70: undefined reference to `dbus_connection_read_write'
/directory/libpcap-1.7.4/./pcap-dbus.c:66: undefined reference to `dbus_connection_pop_message'
/directory/libpcap-1.7.4/./pcap-dbus.c:83: undefined reference to `dbus_message_is_signal'
/directory/libpcap-1.7.4/./pcap-dbus.c:88: undefined reference to `dbus_message_marshal'
/directory/libpcap-1.7.4/./pcap-dbus.c:100: undefined reference to `dbus_free'
collect2: ld returned 1 exit status
make[3]: *** [tcpreplay] Error 1
make[3]: Leaving directory `/directory/tcpreplay-4.1.0/src'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/directory/tcpreplay-4.1.0/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/directory/tcpreplay-4.1.0/src'
make: *** [all-recursive] Error 1
Do you have any idea / solution to install tcpreplay
Thanks
sudo apt-get install tcpreplay

Linker errors in compiling a simple pthread code under MingW

I am trying to compile a single c++ source file test.cpp, which has a very simple code which demonstrates pthread_create(); pthread_cond_signal/pthread_cond_wait() functionality.
I have installed Mingw / Ansys on Windows XP where I am working. In the MingW prompt I do:
g++ -IC:/MinGW/include/ -lpthread test.cpp
//-IC:/MinGW/include to get pthread.h
//-LC:/MinGW/bin to get pthreadGC2.dll
The cpp includes pthread.h as:
#include <pthread.h>
But this gave me multiple linker undefined reference errors to all pthread library functions.
What am I doing wrong here. Is it possible to build a pthread code on MingW environment on windows or not?
How to resolve this errors?
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x23): undefined reference to `_imp__pthread_mutex_lock'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x67): undefined reference to `_imp__pthread_cond_signal'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x75): undefined reference to `_imp__pthread_mutex_unlock'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x98): undefined reference to `_imp__pthread_exit'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0xbc): undefined reference to `_imp__pthread_mutex_lock'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0xe8): undefined reference to `_imp__pthread_cond_wait'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x10f): undefined reference to `_imp__pthread_mutex_unlock'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x135): undefined reference to `_imp__pthread_exit'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x153): undefined reference to `_imp__pthread_attr_init'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x169): undefined reference to `_imp__pthread_mutex_init'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x17f): undefined reference to `_imp__pthread_attr_setdetachstate'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x195): undefined reference to `_imp__pthread_cond_init'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x1bc): undefined reference to `_imp__pthread_create'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x1e3): undefined reference to `_imp__pthread_create'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x201): undefined reference to `_imp__pthread_join'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x21f): undefined reference to `_imp__pthread_join'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x239): undefined reference to `_imp__pthread_mutex_destroy'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x247): undefined reference to `_imp__pthread_cond_destroy'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x255): undefined reference to `_imp__pthread_attr_destroy'
C:\DOCUME~1\ADESHP~1\LOCALS~1\Temp\ccUQhu7D.o:pthread_cond.c:(.text+0x263): undefined reference to `_imp__pthread_exit'
collect2: ld returned 1 exit status
You need to specify the library on the gcc/g++ command line after the files that depend on the library. So try:
g++ -IC:/MinGW/include/ test.cpp -lpthread
I kicked myself when I stumbled on the answer (it's kind of a FAQ for libraries and gcc). For most gcc options order doesn't matter, but for libraries it's critical.
You should not have to specify the library path if the pthread library came with your MinGW distribution (as it seems is the case for you). Also, remember that the command line above will produce an a.exe executable; pass -o test.exe to avoid that.

Resources