我正在尝试编译以下示例代码:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[]) {
cout << "Using OpenCV version " << CV_VERSION << endl;
Point2f *p = new Point2f(1, 2);
cout << p << endl;
cout << *p << endl;
string filename = "test";
Mat A;
imshow("asd", A);
return 0;
}
我正在使用以下CMakeLists.txt:
cmake_minimum_required (VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /FindOpenCV.cmake)
find_package(OpenCV)
message(STATUS "OpenCV_FOUND: " ${OpenCV_FOUND})
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})
这就是我得到的:
-- OpenCV_FOUND: 1
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/daviderler/Desktop/new/src/test
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
Linking CXX executable main
Undefined symbols for architecture x86_64:
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
我不明白为什么imread无法链接,Point2f的东西只编译得很好...... 例如,行:
Mat A;
findFundamentalMat(A, A, 1 ,2.0);
被编译。
我基本上遵循这个: http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
所以我尝试手动编译代码,这一行似乎有效:
clang++ -mmacosx-version-min=10.7 -I/usr/local/include/opencv2 -I/opt/local/include main.cpp -lopencv_core -lopencv_highgui
所以唯一的区别是-mmacosx-version-min = 10.7标志......但是我不知道如何将它一直带到编译器调用...:/
答案 0 :(得分:0)
所以这条小线就行了......
set(CMAKE_CXX_FLAGS "-mmacosx-version-min=10.7")
虽然我很感激解释。