Linker errors in compiling a simple pthread code under MingW - pthreads

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.

Related

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

Using LLVM Libraries in C++ Project

I'm currently having problem with simple project(or llvm-example for that matter). My assignment requires me to use llvm libraries, however this isn't as easy as I had hoped.
I've build LLVM using MinGW GCC and CMake. After build I can compile with clang fine. However if I create simple hello world type of program
#include "llvm-c/Core.h"
int main(int argc, char**argv)
{
return 0;
}
and try to compile it with
clang++ main.cpp
I get
In file included from main.cpp:1:
./llvm-c/Core.h:18:10: fatal error: 'llvm-c/ErrorHandling.h' file not found
#include "llvm-c/ErrorHandling.h"
For this example I have copied contents of include directory into directory with main.cpp. After getting this issue I tried to inspect those headers and all of them have position llvm/ or llvm-c/, instead of pure relative address. I figured these libs were used to build/make llvm and libs for me to use are actually in build directory, which is where I have built llvm, but include directory in build has only about 1/2 *.h files.
I can't seem to find anything in documentation related to this and even basic llvm examples are expecting to include libs in format like llvm/Core.h
EDIT
After solving inclusion problem, now I get several other problems which seems to be linked to mingw.
This is how new program looks.
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include <llvm-c/Core.h>
using namespace std;
int main()
{
LLVMModuleRef rff = LLVMModuleCreateWithName("testname");
return 0;
}
this generates
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(CommandLine.cpp.obj):CommandLine.cpp|| undefined reference to `__mingw_strtod'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(regerror.c.obj):regerror.c|| undefined reference to `__ms_vsnprintf'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `SHGetKnownFolderPath#16'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `_imp__CoTaskMemFree#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `_imp___chsize_s'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_Profile'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(Path.cpp.obj):Path.cpp|| undefined reference to `FOLDERID_LocalAppData'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libLLVMSupport.a(TimeValue.cpp.obj):TimeValue.cpp|| undefined reference to `_localtime32'|
I used llvm-config --libs core for linker additions.
Tried commands:
g++ main.cpp -lLLVMCore -lLLVMSupport
clang++ main.cpp -lLLVMCore -lLLVMSupport
Those are WinAPI references. The easiest way is to find those are google for documentation for it or go to the mingw library directory ( ..\mingw530_32\i686-w64-mingw32\lib\ ) and find in files.
So
FOLDERID_LocalAppData is defined in libuuid.a so use the -luuid compile parameter
_imp__CoTaskMemFree#4 is defined in libole32.a so use the -lole32 compile parameter
For me g++ -std=c++11 -ID:\Devel\install\include main.cc -LD:\Devel\install\lib -lLLVMCore -lLLVMSupport -luuid -lole32
is working as I installed the llvm to D:\Devel\install
If you need the headers from your-llvm/include directory instead of copying the contents of the include directory you should just specify the include path to your-llvm/include with -I option or whatever the build system requires.

mips-openwrt-linux-gcc: link the lua lib error

Sorry for my poor english.
I want to call lua functions in c app on the openwrt 14.07.
When cross compile the project, i can not find the header and .so files for lua in the toolchain. So i copy the lua51 folder from ubuntu 14.04 and liblua.so from target os to the toolchain.Then try to compile the project, i get the undefined reference errors.
mips-openwrt-linux-gcc airkiss.c luaconf.c -lpthread -llua libairkiss_log.a
-L. -o airkiss -Wl,-rpath-link=/opt/OpenWrt-Toolchain-ar71xx-for-mips_34kc-gcc-4.8-linaro_uClibc-0.9.33.2/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib
I got the error:
luaconf.c:(.text+0x18): undefined reference to `luaL_newstate'
luaconf.c:(.text+0x28): undefined reference to `luaL_openlibs'
luaconf.c:(.text+0x3c): undefined reference to `luaL_loadfile'
luaconf.c:(.text+0x54): undefined reference to `lua_getfield'
luaconf.c:(.text+0x64): undefined reference to `lua_pushstring'
luaconf.c:(.text+0x74): undefined reference to `lua_pushstring'
luaconf.c:(.text+0x8c): undefined reference to `lua_pcall'
luaconf.c:(.text+0xa0): undefined reference to `lua_tolstring'
luaconf.c:(.text+0xc0): undefined reference to `lua_close'
Anyone knows how to fix it? Thanks!
The best way would be to have OpenWrt-style Makefile project to compile your code.
For reference, look at feeds/packages/multimedia/xupnpd/Makefile - it also uses liblua.
This manual will help you: https://wiki.openwrt.org/doc/devel/packages
It seems lua is enable by default config. Could you check if CONFIG_PACKAGE_liblua and CONFIG_PACKAGE_lua is 'y' in your .config file?
By default the header file locate at staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/include and lib file at staging_dir/target-mips_r2_uClibc-0.9.33.2/usr/lib.
Also check if you do full build before.

OpenCV build error

If this is not out of place here, would like to know about the source and fix for an error I get when I am building OpenCV under Cygwin (On Windows 7 64 bit).
I have Cygwin installed with MingW- pthread pacgae installed in that cygwin installation.
I have downloaded OpenCV ver. 2.3.1 source package.
EDIT:
After some tweaks, and changes to build process OpenCV builds fine now.
But when I compile a simple test openCV code(C source code), as below it gives lot of linker errors of undefined references to many basic openCV functions. I tried setting LD_LIBRARY_PATH correctly but still errors persit:
cc -L/usr/local/lib -I/usr/local/include/opencv2 -/usr/local/include/opencv -lop encv_imgproc -lopencv_highgui -lopencv_video -lopencv_calib3d test1.c -o test_op encv
cc: unrecognized option '-/usr/local/include/opencv'
/tmp/ccfEqFK0.o:test1.c:(.text+0x9dd): undefined reference to `_cvFree_'
/tmp/ccfEqFK0.o:test1.c:(.text+0xa4e): undefined reference to `_cvFree_'
/tmp/ccfEqFK0.o:test1.c:(.text+0xb44): undefined reference to `_cvGetRows'
/tmp/ccfEqFK0.o:test1.c:(.text+0xb6f): undefined reference to `_cvGetCols'
/tmp/ccfEqFK0.o:test1.c:(.text+0xb82): undefined reference to `_cvReleaseMat'
/tmp/ccfEqFK0.o:test1.c:(.text+0xcd2): undefined reference to `_cvAddS'
/tmp/ccfEqFK0.o:test1.c:(.text+0x1137): undefined reference to `_cvRead'
/tmp/ccfEqFK0.o:test1.c:(.text+0x11e1): undefined reference to `_cvLoadImage'
/tmp/ccfEqFK0.o:test1.c:(.text+0x129d): undefined reference to `_cvCreateImage'
/tmp/ccfEqFK0.o:test1.c:(.text+0x12dd): undefined reference to `_cvResize'
/tmp/ccfEqFK0.o:test1.c:(.text+0x12f1): undefined reference to `_cvNamedWindow'
/tmp/ccfEqFK0.o:test1.c:(.text+0x1305): undefined reference to `_cvNamedWindow'
'
/tmp/ccfEqFK0.o:test1.c:(.text+0x13ad): undefined reference to `_cvDestroyWindow
... ... Many more undefined references.
'
collect2: ld returned 1 exit status
Makefile:10: recipe for target `test_opencv' failed
make: *** [test_opencv] Error 1
EDIT
Below message is still there, but it is not an error but a message during build process.
*Then while building OpenCV under cygwin, when I do make , it gives a error message
c++: unrecognized option '-pthread'
[ 36%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/grfmt_sunras.o*
and for many other files i see the same error c++: unrecognized option '-pthread'
I would like to know if anyone has experience in building openCV under Cygwin , how to get OpenCV going under cygwin? . Now I know there is windows setup for OpenCV but that is not what is an option to me.
Your cmd line arguments has a few problems. It seems that it was not fully pasted in your question (some indentation problems suggests so).
One obvious mistake can be easily identified since CC is telling you about it: cc: unrecognized option '-/usr/local/include/opencv':
When adding headers directories in the command line, you must specify each of them with -I. Notice how you failed to do so with: -/usr/local/include/opencv. It should be -I/usr/local/include/opencv
You also seem to be missing -lopencv_core in the cmd-line
In the future, use pkg-config (if its properly configured) to help you include opencv headers and libraries:
cc test.c -o test_op `pkg-config --cflags --libs opencv` -lop
Thanks for pointers:
What I found was the problem was as follows:
In my Makefile of my openCV test app I was linking with the import libraries (*.a). Which was the problem.
Problematic Makefile was linking against files
-l:/usr/local/lib/libopencv_core.dll.a ...etc...
I changed that to link with actual dll libs, then it worked(linked) fine, w/o any errors as above.
Changes Makefile looks:
LIBS = -l:/usr/local/bin/cygopencv_core-2.3.dll -l:/usr/local/bin/cygopencv_imgproc-2.3.dll -l:/usr/local/bin/cygopencv_highgui-2.3.dll -l:/usr/local/bin/cygopencv_video-2.3.dll -l:/usr/local/bin/cygopencv_calib3d-2.3.dll

OpenCV compilation error in eclipse

I have been coding in python before and included the library of openCV without any problem. Now, I want to code in C++ so I downloaded eclipse and openCV libraries and included their path in the includes from eclipse ..
I have simple example of openCV and I am trying to run it, but I get this error -->
**** Build of configuration Debug for project Example ****
make all
Building file: ../Test.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test.d" -MT"Test.d" -o "Test.o" "../Test.cpp"
Finished building: ../Test.cpp
Building target: Example
Invoking: GCC C++ Linker
g++ -o "Example" ./Test.o
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../crt1.o: In function _start':
(.text+0x20): undefined reference tomain'
./Test.o: In function gh::main()':
/home/shamma/workspace/Example/Debug/../Test.cpp:16: undefined reference tocvCreateImage'
/home/shamma/workspace/Example/Debug/../Test.cpp:21: undefined reference to cvNamedWindow'
/home/shamma/workspace/Example/Debug/../Test.cpp:22: undefined reference tocvShowImage'
/home/shamma/workspace/Example/Debug/../Test.cpp:23: undefined reference to cvWaitKey'
/home/shamma/workspace/Example/Debug/../Test.cpp:24: undefined reference tocvDestroyWindow'
/home/shamma/workspace/Example/Debug/../Test.cpp:25: undefined reference to `cvReleaseImage'
collect2: ld returned 1 exit status
make: * [Example] Error 1enter code here
any idea what might be the cause of the problem, I have tried lots of things without use
thanks in advance
It seems you have not properly configured OpenCV libraries. I recommend you to follow the OpenCV tutorial to start using it with Eclipse.
In eclipse go to project->properties->settings and under GCC C++ linker-> libraries and assuming you're just testing, add "opencv_core" and "opencv_highgui" there are many more and for each library you need to manually include them so that eclipse can tell the compiler to link these libraries when you run your program.
Also as a note generally "cvE______" is opencv for C where as for C++ it would be cv::E____ , its really confusing that sometime you can get away with both, but not always, so stick the the function in the namespace without cv prefixes.

Resources