Undefined reference to cv::solvePnP...

asked 2018-04-26 08:38:12 -0500

Kamel gravatar image

Hi,

I am using OpenCV on Windows. I develop on CodeBlocks. I linked the librairies, like you can see here :

image description

I don't have any problem to use functions that are declared in opencv2/imgproc/imgproc.hpp library. Thus, I can't use functions that are declared in opencv2/calib3d/calib3d.hpp such as cv::solvePnP and others. The compiler returns me this error :

  undefined reference to `cv::solvePnP(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, bool, int)'

I guess that the origin of the problem is that there is no dynamic library for calib3d that is linked. But I don't know how to add it.

Thanks for any help,

edit retag flag offensive close merge delete

Comments

we cannot help you with "how to use your ide", but:

just add a similar line for opencv_calib3d341 there ?

berak gravatar imageberak ( 2018-04-26 08:40:55 -0500 )edit

Thanks for answer,

This is the error that occurs after doing that :

mingw32-g++.exe: error: C:\opencv\build\x64\mingw\lib\libopencv_calib3d_pch_dephelp.a: No such file or directory
    mingw32-g++.exe: error: C:\opencv\build\x64\mingw\lib\libopencv_calib3d341.dll.a: No such file or directory
Kamel gravatar imageKamel ( 2018-04-26 08:59:56 -0500 )edit

@Kamel, in this case you have to back at building the opencv libs (cmake, make), and try to find out, why it was not built/installed.

try, and report back.

you also have to build mingw libs with:

cmake -DENABLE_PRECOMPILED_HEADERS=OFF

last: using mingw32-g++.exe will produce 32bit libs/executables. unless your os is 32bit only, that's a terrible choice. consider changing your compiler toolchain to latest mingw-64 (7.3.0)

berak gravatar imageberak ( 2018-04-26 09:09:25 -0500 )edit

@berak Thanks for answer,

I attempted to build mingw libs by this way :

C:\opencv\build\x64\mingw>cmake -DENABLE_PRECOMPILED_HEADERS=OFF C:\opencv\sources

CMake Error at CMakeLists.txt:11 (message):

  FATAL: In-source builds are not allowed.

         You should create a separate directory for build files.

-- Configuring incomplete, errors occurred!

An error occurs. Therefore, if I use existing libs, it works :

C:\opencv\build\x64\mingw>cmake -DENABLE_PRECOMPILED_HEADERS=OFF C:\opencv\build\x64\mingw

I read :

-- Configuring done
-- Generating done
-- Build files have been written to: C:/opencv/build/x64/mingw

But there is still no calib3d library.

Concerning mingw version, I tried to set 64b version, but there is no change.

Regards,

Kamel gravatar imageKamel ( 2018-04-27 05:42:07 -0500 )edit

you should start cmake from C:/opencv/build

maybe try to use cmake-gui instead, you get a better overview, what's on or off this way

berak gravatar imageberak ( 2018-04-27 05:58:44 -0500 )edit

@berak There is no problem when I run cmake. But when I do :

mingw32-make

The installation continues until this line :

[ 66%] Building CXX object modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/detection_based_tracker.cpp.obj

Here, errors are occuring :

C:\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:175:14: error: 'thread' in namespace 'std' does not name a type
         std::thread second_workthread;
              ^~~~~~
C:\opencv\sources\modules\objdetect\src\detection_based_tracker.cpp:176:14: error: 'mutex' in namespace 'std' does not name a type
         std::mutex mtx;
              ^~~~~

And so ones. I think that the installation stop before calib3d library is installed. May be the problem is the MinGW version (6.3.0) ?

Kamel gravatar imageKamel ( 2018-04-27 08:29:03 -0500 )edit

yes. it expects your compiler to have c++11 support here

berak gravatar imageberak ( 2018-04-27 09:07:32 -0500 )edit

I updated MinGW, now the version is the latest :

gcc version 7.3.0 (GCC)

I ran cmake again, no problem. Then I tried to build opencv libraries with mingw :

mingw32-make

It continued until this line :

[ 41%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.obj

Here, the program stopped and I read :

mingw32-make[2]: *** [modules\imgcodecs\CMakeFiles\opencv_imgcodecs.dir\build.make:63: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:4424: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
mingw32-make: *** [Makefile:162: all] Error 2

Thanks for any help,

Kamel gravatar imageKamel ( 2018-04-27 10:00:31 -0500 )edit

that's not the actual error (which should be a few lines up)

berak gravatar imageberak ( 2018-04-27 10:06:21 -0500 )edit

@berak What do you mean ?

Kamel gravatar imageKamel ( 2018-04-27 10:10:05 -0500 )edit