gpt4 book ai didi

c++ - 使用 gcc 5.1 未定义 OpenCV 符号

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:35 37 4
gpt4 key购买 nike

我有一个非常基本的程序来测试 OpenCV 是否有效。

#include <opencv2/opencv.hpp>

int main() {
cv::namedWindow("Window", CV_WINDOW_AUTOSIZE);

cv::VideoCapture video_capture;
video_capture.open(0);

while (true) {
cv::Mat image;
video_capture.read(image);

cv::imshow("Window", image);

if (cv::waitKey(1) == 27) {
break;
}
}

return 0;
}

还有一个像这样找到 OpenCV 的 CMakeLists.txt 文件:

find_package(OpenCV REQUIRED)
...
target_link_libraries(Project ${OpenCV_LIBS})

这适用于使用 OpenCV 2.4.10 和 clang 602.0.49 的 Mac OSX 10.10,但是如果我尝试通过将 set(CMAKE_CXX_COMPILER/usr/gcc-5.1.0/bin/g++-5.1 .0) 在我的 CMakeLists.txt 中,出现以下错误:

Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in main.cpp.o
"cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in main.cpp.o

有什么问题,我该如何解决?

最佳答案

请使用您用于编译上述代码的相同版本的 gcc 重新编译您的 OpenCV。这个问题应该会消失。来自官方 gcc 页面,

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.

关于c++ - 使用 gcc 5.1 未定义 OpenCV 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30064618/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com