Closed Con-Mi closed 4 years ago
Compare exact full compiler/linker command lines.
@alalek what do you mean? Compile for example with g++ with pkg-config?
No.
Use make VERBOSE=1
and compare logs for both cases.
Ok this is what I have tried: If I do:
g++ -std=c++11 main.cpp -o test pkg-config opencv4 --cflags --clibs
Then this works.
If I also run the above CMakeLists.txt file with:
find_package(OpenCV REQUIRED)
it finds OpenCV 3.4.2 that I have in my system installed for python and then this also works.
Any ideas why? I installed OpenCV 4.0-beta from downloading the zip file that is in the website and I build it with cmake.
These lines are required for OpenCV 4.0 apps:
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
finds OpenCV 3.4.2 I have in my system installed
Into /usr/local ? Side-by-side installations may not work in this case (too many possible conflicts).
Try to pass -DOpenCV_DIR=<path to OpenCVConfig.cmake>
to CMake (and clear build dir before that to drop CMake cache).
We don't help with remote investigation of problems which we are not able to reproduce on our side (because it is very time consuming and usually configuration problem without any following fix into OpenCV), but we can take a look on the clear reason of the problem and suggest some fix/workaround.
No I have opencv 3.4.2 on Miniconda folder not on usr/local and that what cmake finds.
I have removed opencv 4 beta and I have build the 3.4.3.
I did the same steps again with find_package(OpenCV 3.4.3 REQUIRED) and everything seems to work just fine with the above code I have provided. I have also set the flags for c++11.
I don't know if I am missing something, but it seemed that with imread, imwrite and other io functions opencv 4.0.0 beta didn't work. I guess I will work with opencv 3.4.3. for now.
These lines are required for OpenCV 4.0 apps:
# Enable C++11 set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
I have not looked into OpenCV 4.0 yet, but C++11 requirements should be set by OpenCV itself through target_compile_features
. Requiring users to set these two lines constitutes incorrect CMake usage.
target_compile_features(target PUBLIC cxx_std_11)
is supported by CMake 3.8+ only.
Produced CMake configuration files can't be reused by CMake less than CMake 3.8:
CMake Error in cpp/CMakeLists.txt:
Specified unknown feature "cxx_std_11" for target "example_cpp_edge".
Current minimal supported CMake version is 3.5.x (Ubuntu 16.04 has 3.5.1 by default).
You are not supposed to use cxx_std_11
, but explicit feature requirements such as cxx_auto_type
etc.
rebuild your opencv4 from source with "add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)", have fun.
I faced the same problem
main.cpp:(.text+0x113): undefined reference to
cv::imread(std::string const&, int)'
main.cpp:(.text+0x179): undefined reference to cv::imread(std::string const&, int)' main.cpp:(.text+0x567): undefined reference to
cv::imshow(std::string const&, cv::_InputArray const&)'
main.cpp:(.text+0x856): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' main.cpp:(.text+0xa17): undefined reference to
cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocatorcv::imshow(std::string const&, cv::_InputArray const&)' /home/sy/anaconda3/lib/libpng16.so.16: undefined reference to
inflateValidate@ZLIB_1.2.9'
liblbd_mod.so: undefined reference to cv::write(cv::FileStorage&, std::string const&, int)' liblbd_mod.so: undefined reference to
cv::FileNode::string() const'
liblbd_mod.so: undefined reference to cv::Algorithm::getDefaultName() const' liblbd_mod.so: undefined reference to
cv::error(int, std::string const&, char const, char const, int)'
liblbd_mod.so: undefined reference to cv::operator<<(cv::FileStorage&, std::string const&)' liblbd_mod.so: undefined reference to
cv::FileStorage::FileStorage(std::string const&, int, std::string const&)'
liblbd_mod.so: undefined reference to cv::Algorithm::save(std::string const&) const' collect2: error: ld returned 1 exit status
And the relative content of CMakeLists is as follows:
`...
find_package(OpenCV COMPONENTS core imgproc highgui imgcodecs REQUIRED) ... target_link_libraries(lbd_mod ${OpenCV_LIBRARIES}) target_link_libraries(lbd_mod_test lbd_mod ${OpenCV_LIBRARIES}) ... target_include_directories(${PYPROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/cpp/include" ${Boost_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${LBD_MOD_INCLUDE} )
target_link_libraries(${PYPROJECT_NAME} ${Boost_LIBRARIES} ${OpenCV_LIBRARIES} ${PYTHON_LIBRARIES} ) ...` @alalek I tried lots of ideas published in the net, but those didn't work. Please help me, thank u
@alalek I also tried u mentioned
make VERBOSE=1
It shows
Linking CXX executable lbd_mod_test /usr/local/bin/cmake -E cmake_link_script CMakeFiles/lbd_mod_test.dir/link.txt --verbose=1 /usr/bin/c++ -rdynamic CMakeFiles/lbd_mod_test.dir/main.cpp.o -o lbd_mod_test -Wl,-rpath,/home/sy/code/lbdmod-master/build:/usr/local/lib liblbd_mod.so /usr/local/lib/libopencv_highgui.so.4.1.0 /usr/local/lib/libopencv_videoio.so.4.1.0 /usr/local/lib/libopencv_imgcodecs.so.4.1.0 /usr/local/lib/libopencv_imgproc.so.4.1.0 /usr/local/lib/libopencv_core.so.4.1.0 CMakeFiles/lbd_mod_test.dir/main.cpp.o: In function
main': main.cpp:(.text+0x113): undefined reference to
cv::imread(std::string const&, int)' main.cpp:(.text+0x179): undefined reference tocv::imread(std::string const&, int)' main.cpp:(.text+0x567): undefined reference to
cv::imshow(std::string const&, cv::_InputArray const&)' main.cpp:(.text+0x856): undefined reference tocv::imshow(std::string const&, cv::_InputArray const&)' main.cpp:(.text+0xa17): undefined reference to
cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator> const&)' main.cpp:(.text+0xabc): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' /home/sy/anaconda3/lib/libpng16.so.16: undefined reference to
inflateValidate@ZLIB_1.2.9' liblbd_mod.so: undefined reference tocv::write(cv::FileStorage&, std::string const&, int)' liblbd_mod.so: undefined reference to
cv::FileNode::string() const' liblbd_mod.so: undefined reference tocv::Algorithm::getDefaultName() const' liblbd_mod.so: undefined reference to
cv::error(int, std::string const&, char const, char const, int)' liblbd_mod.so: undefined reference tocv::operator<<(cv::FileStorage&, std::string const&)' liblbd_mod.so: undefined reference to
cv::FileStorage::FileStorage(std::string const&, int, std::string const&)' liblbd_mod.so: undefined reference to `cv::Algorithm::save(std::string const&) const' collect2: error: ld returned 1 exit status CMakeFiles/lbd_mod_test.dir/build.make:89: recipe for target 'lbd_mod_test' failed make[2]: [lbd_mod_test] Error 1 make[2]: Leaving directory '/home/sy/code/lbdmod-master/build' CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/lbd_mod_test.dir/all' failed make[1]: [CMakeFiles/lbd_mod_test.dir/all] Error 2 make[1]: Leaving directory '/home/sy/code/lbdmod-master/build' Makefile:129: recipe for target 'all' failed make: *** [all] Error 2
So what happened?
I believe there is mess with std::string
vs std::__cxx11::string
.
Check compiler command line options too (before linking).
Try -std=c++11
or other options from the comments above.
@alalek It has been set in the CMakeLists.txt
============= C++11 support====================================
if(${CMAKE_VERSION} VERSION_LESS "3.1") include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if (COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") elseif (COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") else () message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif () else() set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif()
How did you get OpenCV binaries?
Please dump symbols:
$ nm -g ./lib/libopencv_imgcodecs.so | grep 6imread
00000000000a2386 T _ZN2cv6imreadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
$ nm -g liblbd_mod.so | grep 6imread
The result is as follows:
$ nm -g /usr/local/lib/libopencv_imgcodecs.so | grep 6imread 000000000006b700 T _ZN2cv6imreadERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
$ nm -g liblbd_mod.so | grep 6imread U _ZN2cv6imreadERKSsi
I also tried "g++" instead of "make", it turns
$ g++ main.cpp -L/usr/local/lib -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -o lbd_mod_test In file included from main.cpp:22:0: cpp/src/precomp.hpp:54:36: fatal error: opencv2/core/utility.hpp: No such file or directory
include "opencv2/core/utility.hpp"
But "utility.hpp" do exists.
_ZN2cv6imreadERKSsi
So, -std=c++11
is not applied during build of liblbd_mod.so
.
I add
CXXFLAGS := -std=c++11
in the Makefile, it also doesn't work.
It seems that the opencv libraries are messed up, but I didn't figure out how to resolve it.
Finally I reinstalled opencv on another machine, it solved.
Finally I reinstalled opencv on another machine, it solved. @alalek Please close the subject, thx.
Before building use:
cmake -D CMAKE_BUILD_TYPE=Release -D GLIBCXX_USE_CXX11_ABI=0 -D CMAKE_INSTALL_PREFIX=/usr/local ..
Instead of what is recommended on the official website.
Full steps (ubuntu 18.04):
git clone https://github.com/opencv/opencv.git
cd ~/opencv && mkdir release && cd release
cmake -D CMAKE_BUILD_TYPE=Release -D GLIBCXX_USE_CXX11_ABI=0 -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
Then compile .cpp file with:
g++ main.cpp -I/opencv2/include/ -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_videoio
target_link_libraries(your_name ${OpenCV_LIBS})
PKG_CONFIG_PATH should contain the path the opencv pkg_config dir or some such. In my case
PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:"$PKG_CONFIG_PATH"
helped. You might need a variation of this.
locate opencv
should help.
rebuild your opencv4 from source with "add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)", have fun.
It works for me. Thanks a lot. ^O^
Same issue solved for me : https://github.com/pytorch/pytorch/issues/14620#issuecomment-735236765
bro i am getting this error on colab so how do i run it on colab using g++?
For me, It works well when you change the libtorch compiler to libtorch-shared-with-deps-1.9.0%2Bcu111.zip -> libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcu111.zip.
hi all, I foud one solution. I have two versions of c++(4.8 and 9.4), I remove the 4.8 version of c++ by run yum remove g++, then I can compile my code.
and here is my CMakeLists.txt content:
cmake_minimum_required(VERSION 3.0)
project(project)
find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})
message("OpenCV_INCLUDE_DIRS: " ${OpenCV_INCLUDE_DIRS})
add_executable(executableFileName main.cpp)
target_link_libraries( executableFileName ${OpenCV_LIBS} )
Hi if I use c++ 17 for example, do I need to add GLIBCXX_USE_CXX17_ABI=0?
Hi if I use c++ 17 for example, do I need to add GLIBCXX_USE_CXX17_ABI=0?
yes
Hello I get the same issue on FreeBSD 13.1:
[ 98%] Building CXX object CMakeFiles/darknet_l.dir/src/image_opencv.cpp.o
[ 99%] Building C object CMakeFiles/darknet.dir/examples/darknet.c.o
[100%] Linking CXX static library libdarknet_s.a
[100%] Built target darknet_s
[100%] Linking CXX shared library libdarknet_l.so
[100%] Linking CXX executable darknet
[100%] Built target darknet_l
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `open_video_stream':
/home/user/darknet/src/image_opencv.cpp:186: undefined reference to `cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `show_image_frame_cv':
/home/user/darknet/src/image_opencv.cpp:208: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `make_window_cv':
/home/user/darknet/src/image_opencv.cpp:216: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/local/bin/ld: /home/user/darknet/src/image_opencv.cpp:218: undefined reference to `cv::setWindowProperty(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double)'
/usr/local/bin/ld: /home/user/darknet/src/image_opencv.cpp:220: undefined reference to `cv::resizeWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)'
/usr/local/bin/ld: /home/user/darknet/src/image_opencv.cpp:221: undefined reference to `cv::moveWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `cv_capture_from_file':
/home/user/darknet/src/image_opencv.cpp:283: undefined reference to `cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `is_invalid_file_to_imread_cv':
/home/user/darknet/src/image_opencv.cpp:397: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `load_image_cv':
/home/user/darknet/src/image_opencv.cpp:422: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `save_image_jpg_cv':
/home/user/darknet/src/image_opencv.cpp:489: undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `mark_image_and_save_cv':
/home/user/darknet/src/image_opencv.cpp:274: undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
/usr/local/bin/ld: CMakeFiles/darknet.dir/examples/detector.c.o: in function `test_ddetector':
/home/user/darknet/examples/detector.c:756: undefined reference to `empty'
collect2: error: ld returned 1 exit status
--- darknet ---
*** [darknet] Error code 1
make[2]: stopped in /usr/home/user/darknet/build
1 error
make[2]: stopped in /usr/home/user/darknet/build
--- CMakeFiles/darknet.dir/all ---
*** [CMakeFiles/darknet.dir/all] Error code 2
make[1]: stopped in /usr/home/user/darknet/build
1 error
make[1]: stopped in /usr/home/user/darknet/build
*** [all] Error code 2
make: stopped in /usr/home/user/darknet/build
1 error
make: stopped in /usr/home/user/darknet/build
Tried many online solutions, nothing works.
I haven't tried the GLIBCXX_USE_CXX17_ABI=0
solution since I use FreeBSD 13.1 ports version of OpenCV 4.6 and not sure how to add this line of code during compilation from source, since we install from source with the following:
make install clean
Installing the GitHub version of OpenCV does not work and requires a lot of patching for FreeBSD...
Not sure how to solve the issue.
Thanks.
Hello I get the same issue on FreeBSD 13.1:
[ 98%] Building CXX object CMakeFiles/darknet_l.dir/src/image_opencv.cpp.o [ 99%] Building C object CMakeFiles/darknet.dir/examples/darknet.c.o [100%] Linking CXX static library libdarknet_s.a [100%] Built target darknet_s [100%] Linking CXX shared library libdarknet_l.so [100%] Linking CXX executable darknet [100%] Built target darknet_l /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `open_video_stream': /home/user/darknet/src/image_opencv.cpp:186: undefined reference to `cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `show_image_frame_cv': /home/user/darknet/src/image_opencv.cpp:208: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `make_window_cv': /home/user/darknet/src/image_opencv.cpp:216: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /usr/local/bin/ld: /home/user/darknet/src/image_opencv.cpp:218: undefined reference to `cv::setWindowProperty(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double)' /usr/local/bin/ld: /home/user/darknet/src/image_opencv.cpp:220: undefined reference to `cv::resizeWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)' /usr/local/bin/ld: /home/user/darknet/src/image_opencv.cpp:221: undefined reference to `cv::moveWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `cv_capture_from_file': /home/user/darknet/src/image_opencv.cpp:283: undefined reference to `cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `is_invalid_file_to_imread_cv': /home/user/darknet/src/image_opencv.cpp:397: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `load_image_cv': /home/user/darknet/src/image_opencv.cpp:422: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `save_image_jpg_cv': /home/user/darknet/src/image_opencv.cpp:489: undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' /usr/local/bin/ld: CMakeFiles/darknet.dir/src/image_opencv.cpp.o: in function `mark_image_and_save_cv': /home/user/darknet/src/image_opencv.cpp:274: undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)' /usr/local/bin/ld: CMakeFiles/darknet.dir/examples/detector.c.o: in function `test_ddetector': /home/user/darknet/examples/detector.c:756: undefined reference to `empty' collect2: error: ld returned 1 exit status --- darknet --- *** [darknet] Error code 1 make[2]: stopped in /usr/home/user/darknet/build 1 error make[2]: stopped in /usr/home/user/darknet/build --- CMakeFiles/darknet.dir/all --- *** [CMakeFiles/darknet.dir/all] Error code 2 make[1]: stopped in /usr/home/user/darknet/build 1 error make[1]: stopped in /usr/home/user/darknet/build *** [all] Error code 2 make: stopped in /usr/home/user/darknet/build 1 error make: stopped in /usr/home/user/darknet/build
Tried many online solutions, nothing works.
I haven't tried the
GLIBCXX_USE_CXX17_ABI=0
solution since I use FreeBSD 13.1 ports version of OpenCV 4.6 and not sure how to add this line of code during compilation from source, since we install from source with the following:
make install clean
Installing the GitHub version of OpenCV does not work and requires a lot of patching for FreeBSD...
Not sure how to solve the issue.
Thanks.
cmake -D GLIBCXX_USE_CXX11_ABI=0
If you are using Visual Studio Code Try to change the kit used for project. select Visual Studio Build Tool 2017 Release-x86_amd64. It uses compilers 15.9.37( x86_x64 architecture)
It worked for me...
gcc version: gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.5.0
CMakeLists.txt:
` cmake_minimum_required(VERSION 3.10) project(main)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(OpenCV_DIR "D:/Tensorrt/Opencv/opencv453/build") find_package(OpenCV QUIET) message(STATUS "OpenCV library status:") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
include_directories( "${OpenCV_DIR}/include" )
add_executable(main main.cpp)
find_package(fmt CONFIG REQUIRED)
target_link_libraries(main PRIVATE "${OpenCV_DIR}/x64/vc15/lib/opencv_world453.lib" fmt::fmt fmt::fmt-header-only ) `
[main] 正在配置项目: Step2 [proc] 执行命令: "D:\Program Files\CMake\bin\cmake.exe" --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_TOOLCHAIN_FILE:STRING=D:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET:STRING=x64-windows -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=D:\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:\mingw64\bin\g++.exe -SD:/Source/Learn_Vcpkg/Step2 -Bd:/Source/Learn_Vcpkg/Step2/build -G "MinGW Makefiles" [cmake] Not searching for unused variables given on the command line. [cmake] -- OpenCV library status: [cmake] -- version: 4.5.3 [cmake] -- libraries: [cmake] -- include path: [cmake] -- Configuring done [cmake] -- Generating done [cmake] -- Build files have been written to: D:/Source/Learn_Vcpkg/Step2/build
build:
[build] [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.obj [build] [100%] Linking CXX executable main.exe [build] D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\main.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x42): undefined reference to
cv::imread(std::cxx11::basic_string<char, std::char_traitscv::Mat::empty() const' [build] D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\main.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0xa0): undefined reference to
cv::imshow(std::cv::waitKey(int)' [build] D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\main.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0xc2): undefined reference to
cv::Mat::~Mat()'
[build] D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\main.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0xfc): undefined reference to cv::Mat::~Mat()' [build] D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\main.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x10c): undefined reference to
cv::Mat::~Mat()'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make.exe[2]: [CMakeFiles\main.dir\build.make:101: main.exe] Error 1
[build] mingw32-make.exe[1]: [CMakeFiles\Makefile2:82: CMakeFiles/main.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:90: all] Error 2`
@Byxs20 ,
"${OpenCV_DIR}/x64/vc15/lib/opencv_world453.lib"
you cannot use this with mingw, it is for VS compilers only (to use opencv, you must first build the libs from src)
@berak , Thanks for your help! You're right, I'm using this repository to build the already-built. link: https://github.com/huihut/OpenCV-MinGW-Build Already fixed the linking problem.
I am building a project with OpenCV 4 beta and when I use the function cv::imread or cv::imwrite I get an undefined reference to the functions.
My CMakeLists.txt is as follows:
cmake_minimum_required(VERSION 3.1.0)
project(myImageProgram)
set(CMAKE_PREFIX_PATH /home/marios-cellink/libtorch)
find_package(OpenCV 4.0.0 REQUIRED) find_package(Torch REQUIRED) add_executable(${PROJECT_NAME} "main.cpp")
message(STATUS "OpenCV library status:") message(STATUS " config: ${OPENCV_DIR}") message(STATUS " version: ${OpenV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include_path: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "Torch library status:") message(STATUS " include_path: ${TORCH_INCLUDE_DIRS}") message(STATUS " TORCHLIB: ${TORCH_LIBRARIES}")
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) target_link_libraries(${PROJECT_NAME} ${TORCH_LIBRARIES})
And the program is as follows:
include
include <torch/script.h>
include <opencv2/core.hpp>
include <opencv2/highgui.hpp>
include <opencv2/imgproc.hpp>
include <opencv2/imgcodecs.hpp>
int main() { cv::Mat orig = cv::imread("../myImageProgram/0003.png"); cv::Mat img = cv::imread("../myImagePorgram/0003.png", cv::IMREAD_COLOR); std::shared_ptr module = torch::jit::load("../myImageProgram/model.pt");
return 0;
}
Am I linking OpenCV correctly with cmake? It seems that if I comment out the torch parts from CMake, the program build succesfully. Any ideas?