Closed wangzhankun closed 4 years ago
关于链接报错问题,感觉跟我原先在这个issue提到的问题很像。但是那个问题的解决结果是安装动态链接库解决了。而这次我的opencv安装的确实是动态链接的,ls /usr/local/lib
输出结果如下
cmake libluajit-5.1.so.2 libopencv_dnn.so.3.4.7 libopencv_imgcodecs.so libopencv_objdetect.so.3.4 libopencv_stitching.so.3.4.7 libopencv_videostab.so
libcjson.so libluajit-5.1.so.2.0.4 libopencv_features2d.so libopencv_imgcodecs.so.3.4 libopencv_objdetect.so.3.4.7 libopencv_superres.so libopencv_videostab.so.3.4
libcjson.so.1 libopencv_calib3d.so libopencv_features2d.so.3.4 libopencv_imgcodecs.so.3.4.7 libopencv_photo.so libopencv_superres.so.3.4 libopencv_videostab.so.3.4.7
libcjson.so.1.7.13 libopencv_calib3d.so.3.4 libopencv_features2d.so.3.4.7 libopencv_imgproc.so libopencv_photo.so.3.4 libopencv_superres.so.3.4.7 libopencv_viz.so
libjemalloc.a libopencv_calib3d.so.3.4.7 libopencv_flann.so libopencv_imgproc.so.3.4 libopencv_photo.so.3.4.7 libopencv_videoio.so libopencv_viz.so.3.4
libjemalloc_pic.a libopencv_core.so libopencv_flann.so.3.4 libopencv_imgproc.so.3.4.7 libopencv_shape.so libopencv_videoio.so.3.4 libopencv_viz.so.3.4.7
libjemalloc.so libopencv_core.so.3.4 libopencv_flann.so.3.4.7 libopencv_ml.so libopencv_shape.so.3.4 libopencv_videoio.so.3.4.7 lua
libjemalloc.so.2 libopencv_core.so.3.4.7 libopencv_highgui.so libopencv_ml.so.3.4 libopencv_shape.so.3.4.7 libopencv_video.so pkgconfig
libluajit-5.1.a libopencv_dnn.so libopencv_highgui.so.3.4 libopencv_ml.so.3.4.7 libopencv_stitching.so libopencv_video.so.3.4 python2.7
libluajit-5.1.so libopencv_dnn.so.3.4 libopencv_highgui.so.3.4.7 libopencv_objdetect.so libopencv_stitching.so.3.4 libopencv_video.so.3.4.7 python3.6
奇怪,不知道为啥,现在执行成功了又,可以正常编译了。就是打开了打开了vscode,然后第一次编译还是失败,当再次把add_requires("opencv 3.x")
改成add_requires("opencv")
并在debug模式下进行编译就成功了(使用的是插件)。不知道可能的原因在哪里。在此之前搞了好久都是无法编译。
首先,你来回切add_requires版本的时候,记得 xmake f -c
带 -c 强制清下配置cache,触发重新检测依赖包,不然会使用缓存的结果
error: package(opencv): version conflict, '4.2.0' does not satisfy '3.x'!
这个通常是由于,其他依赖包里面可能也add_deps指定了3.x的opencv依赖,或者其他地方还有 add_requries opencv 的依赖,导致版本冲突了,你可以找找
/usr/bin/g++ -o build/linux/x86_64/release/CV build/.objs/CV/linux/x86_64/release/Main/src/actions.cpp.o build/.objs/CV/linux/x86_64/release/Main/src/main.cpp.o build/.objs/CV/linux/x86_64/release/Share/Camera/src/GxCamera.cpp.o build/.objs/CV/linux/x86_64/release/Share/Camera/src/RMVideoCapture.cpp.o build/.objs/CV/linux/x86_64/release/Share/Camera/src/OrdinaryCapture.cpp.o build/.objs/CV/linux/x86_64/release/Share/Camera/src/VirtualCamera.cpp.o build/.objs/CV/linux/x86_64/release/Share/Controller/src/Controller.cpp.o build/.objs/CV/linux/x86_64/release/Share/SerialPort/src/SerialPort.cpp.o build/.objs/CV/linux/x86_64/release/Share/Socket/src/Socket.cpp.o build/.objs/CV/linux/x86_64/release/Infantry/src/InfantryPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/release/Infantry/src/InfantryArmorDetector.cpp.o build/.objs/CV/linux/x86_64/release/Sentry/src/SentryArmorDetector.cpp.o build/.objs/CV/linux/x86_64/release/Sentry/src/SentryAngleCalculate.cpp.o build/.objs/CV/linux/x86_64/release/Sentry/src/SentryPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/release/Hero/src/HeroArmorDetector.cpp.o build/.objs/CV/linux/x86_64/release/Hero/src/HeroAngleCalculate.cpp.o build/.objs/CV/linux/x86_64/release/Hero/src/HeroPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/release/Buff/src/SolveAngle.cpp.o build/.objs/CV/linux/x86_64/release/Buff/src/BuffPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/release/Buff/src/BuffDetector.cpp.o -s -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -L/usr/lib -lssl -lcrypto -lz -lpthread -lgxiapi -lcjson -m64 error: build/.objs/CV/linux/x86_64/release/Main/src/actions.cpp.o: In function
showPicture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, cv::Mat const&, int)': actions.cpp:(.text+0x5a): undefined reference to
cv::String::allocate(unsigned long)' a
这个错误,你看下输出里面的实际link命令,opencv的库没有link进去,可以按刚说的 强制 xmake f -c 清下cache触发重新检测试试
另外,既然你本地有装,不想用远程的包,你可以人为指定不远程下载 add_requires("opencv", {system = true})
仅从系统探测使用
默认模式是先从系统探测(指定了4.x就会探测系统对应版本,不匹配也会忽略),如果探测不到就会自动从远程下载
主要是无法链接问题的解决方案我很奇怪。因为当时尝试了很多种方法。sudo ldconfig
重启都试了都是不行。opencv也重装了几遍也是不可以,就是启动vscode之后使用插件尝试编译就成功了。不知道可能问题在哪里。现在link
是正常的。按我当时贴的报错的话,应该是没链接上的。正常的链接信息如下:
/usr/bin/g++ -o build/linux/x86_64/debug/CV build/.objs/CV/linux/x86_64/debug/Main/src/actions.cpp.o build/.objs/CV/linux/x86_64/debug/Main/src/main.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/GxCamera.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/RMVideoCapture.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/OrdinaryCapture.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/VirtualCamera.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Controller/src/Controller.cpp.o build/.objs/CV/linux/x86_64/debug/Share/SerialPort/src/SerialPort.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Socket/src/Socket.cpp.o build/.objs/CV/linux/x86_64/debug/Infantry/src/InfantryPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Infantry/src/InfantryArmorDetector.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/SentryArmorDetector.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/SentryAngleCalculate.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/SentryPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/Detector.cpp.o build/.objs/CV/linux/x86_64/debug/Hero/src/HeroArmorDetector.cpp.o build/.objs/CV/linux/x86_64/debug/Hero/src/HeroAngleCalculate.cpp.o build/.objs/CV/linux/x86_64/debug/Hero/src/HeroPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Buff/src/SolveAngle.cpp.o build/.objs/CV/linux/x86_64/debug/Buff/src/BuffPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Buff/src/BuffDetector.cpp.o -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib -lopencv_dnn -lopencv_highgui -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_videoio -lopencv_imgcodecs -lopencv_features2d -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_viz -lopencv_core -lssl -lcrypto -lz -lpthread -lgxiapi -lcjson -m64
可以看到最后面是链接了opencv的,但是在之前的报错中似乎是没有正常链接。
主要是无法链接问题的解决方案我很奇怪。因为当时尝试了很多种方法。
sudo ldconfig
重启都试了都是不行。opencv也重装了几遍也是不可以,就是启动vscode之后使用插件尝试编译就成功了。不知道可能问题在哪里。现在link
是正常的。按我当时贴的报错的话,应该是没链接上的。正常的链接信息如下:/usr/bin/g++ -o build/linux/x86_64/debug/CV build/.objs/CV/linux/x86_64/debug/Main/src/actions.cpp.o build/.objs/CV/linux/x86_64/debug/Main/src/main.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/GxCamera.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/RMVideoCapture.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/OrdinaryCapture.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Camera/src/VirtualCamera.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Controller/src/Controller.cpp.o build/.objs/CV/linux/x86_64/debug/Share/SerialPort/src/SerialPort.cpp.o build/.objs/CV/linux/x86_64/debug/Share/Socket/src/Socket.cpp.o build/.objs/CV/linux/x86_64/debug/Infantry/src/InfantryPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Infantry/src/InfantryArmorDetector.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/SentryArmorDetector.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/SentryAngleCalculate.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/SentryPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Sentry/src/Detector.cpp.o build/.objs/CV/linux/x86_64/debug/Hero/src/HeroArmorDetector.cpp.o build/.objs/CV/linux/x86_64/debug/Hero/src/HeroAngleCalculate.cpp.o build/.objs/CV/linux/x86_64/debug/Hero/src/HeroPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Buff/src/SolveAngle.cpp.o build/.objs/CV/linux/x86_64/debug/Buff/src/BuffPictureManipulator.cpp.o build/.objs/CV/linux/x86_64/debug/Buff/src/BuffDetector.cpp.o -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib -lopencv_dnn -lopencv_highgui -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_videoio -lopencv_imgcodecs -lopencv_features2d -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_viz -lopencv_core -lssl -lcrypto -lz -lpthread -lgxiapi -lcjson -m64
可以看到最后面是链接了opencv的,但是在之前的报错中似乎是没有正常链接。
通常是配置缓存问题,所以你可以按我之前说的xmake f -c 强制忽略历史缓存,重新检测所有就好,
好的,谢谢
描述问题
在本地创建了一个新的环境。安装完opencv4之后发现环境问题,将其卸载后(sudo make uninstall),安装了opencv3版本(手动编译安装),在编译时出现链接错误如下(最后面)。但是
xmake l find_packages opencv
可以找到opencv
,信息如下:当强制指定opencv版本之后
add_requires("opencv 3.x")
,报错如下:不知道opencv版本时,报错如下:
期待的结果
希望能够正常编译。个人认为可能是远程仓库的锅。因为我在本地安装的是opencv4.4.0和opencv3.4.7的版本,不存在报错中的4.2版本的问题。
相关环境