在使用vcpkg安装了mathGL和OpenCV之后,我想使用mathGL画出图像,OpenCV显示图像,但是在库链接无误,Cmake无误之后,构建过程却一直报错:

[ 50%] Building CXX object CMakeFiles/007.dir/main.cpp.obj
[100%] Linking CXX executable E:\Code\CLion\007\debug\007.exe
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj):E:/Code/CLion/007/main.cpp:17: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `main':
E:/Code/CLion/007/main.cpp:19: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/main.cpp:20: undefined reference to `cv::waitKey(int)'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/main.cpp:22: 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&)'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/main.cpp:25: undefined reference to `cv::Mat::~Mat()'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/main.cpp:25: undefined reference to `cv::Mat::~Mat()'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglDataA::mglDataA()':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:264: undefined reference to `__imp__ZTV8mglDataA'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:264: undefined reference to `__imp_mglDataList'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglDataA::~mglDataA()':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:266: undefined reference to `__imp__ZTV8mglDataA'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:267: undefined reference to `__imp_mglDataList'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:268: undefined reference to `__imp_mglDataList'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:269: undefined reference to `__imp_mglDataList'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:269: undefined reference to `__imp_mglDataList'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglDataA::Get[abi:cxx11](long) const':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/abstract.h:318: undefined reference to `__imp__Z18mgl_data_to_stringB5cxx11PK8mglDataAl'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglData::mglData(double const*, int)':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/data.h:67: undefined reference to `__imp__ZTV7mglData'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglData::~mglData()':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/data.h:80: undefined reference to `__imp__ZTV7mglData'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglData::valueD(double, double, double, double*, double*, double*) const':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/data.h:543: undefined reference to `__imp__Z10mglSpline3PKdllldddPdS1_S1_'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglData::value(double, double, double) const':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/data.h:546: undefined reference to `__imp__Z11mglSpline3sPKdlllddd'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglGraph::mglGraph(int)':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/mgl.h:39: undefined reference to `__imp__ZTV8mglGraph'
E:\CLion\CLion 2023.1.3\bin\mingw\bin/ld.exe: CMakeFiles\007.dir/objects.a(main.cpp.obj): in function `mglGraph::~mglGraph()':
E:/Code/CLion/007/cmake-build-debug/vcpkg_installed/x64-windows/include/mgl2/mgl.h:65: undefined reference to `__imp__ZTV8mglGraph'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\007.dir\build.make:117: E:/Code/CLion/007/debug/007.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/007.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/007.dir/rule] Error 2
mingw32-make: *** [Makefile:123: 007] Error 2

然后我就去网上搜索了,比较靠谱的回答是因为:

默认的libtorch在编译的时候,可能会将-D_GLIBCXX_USE_CXX11_ABI置为0。这个是为了兼容旧版的C++ 编译器做的设置。

然后说在cmakelist.txt中添加add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)可以解决问题。

但是我实测是不行的,还说可以降低OpenCV版本的,具体我没有尝试,不知道是否有效啊。

但是说一下我的解决办法吧:使用Visual Studio的相关工具链(添加工具链的方法各位小伙伴自行搜索啊)

也许是因为vcpkg和VS绑定效果更好?反正不用修改任何代码就可以运行了……

参考博客:https://blog.csdn.net/KKKiwiXU/article/details/115872573

参考链接(解决办法就是受到的这篇博客启发):https://www.cnblogs.com/wcvanvan/p/15707617.html

吐槽:说实话我感觉vcpkg真的挺搞的,也不知道是我运气背还是怎么滴,昨天使用vcpkg安装OpenCV和mathGL死活不行,就是卡在nasm那里无法下载,nasm官网也进不去,我怀疑是我使用的梯子屏蔽了.us网站,我就跑去看审计规则啊这些,没用,喊我朋友看看官网能打开不,他也不行,反复折腾我几个小时。结果今天一看,哦,可以了。我靠啊,吐血了真的兄弟们。然后就是遇到Clion链接opencv的问题,又搞我几个小时,啧,还好误打误撞解决了。

Logo

音视频技术社区,一个全球开发者共同探讨、分享、学习音视频技术的平台,加入我们,与全球开发者一起创造更加优秀的音视频产品!

更多推荐