簡體   English   中英

無法使用cmake在OSX上使用OpenCV

[英]Can't get OpenCV to work on OSX using cmake

我正在嘗試編譯以下示例代碼:

#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標志...但是我不知道如何一直將其傳遞給編譯器調用...:/

所以這條小線起到了作用...

set(CMAKE_CXX_FLAGS "-mmacosx-version-min=10.7")

雖然我希望得到一個解釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM