2015-04-02 207 views
2

我跟着this tutorial試圖創建一些OpenCV項目。 它在Windows和Visual Studio偉大的工作,但後來我試着用CMake的使用下面的CMakeLists.txt在我Ubunto虛擬機來運行它:用CMake編譯OpenCV項目時出錯

cmake_minimum_required(VERSION 2.8) 
project(TrackObj) 
find_package(OpenCV REQUIRED) 
add_executable(TrackObj Source.cpp Fruit.cpp Fruit.h) 
target_link_libraries(TrackObj ${OpenCV_LIBS}) 

當我運行cmake .好像一切都很好:

[email protected]:~/Desktop/TrackObj$ cmake . 
-- The C compiler identification is GNU 4.8.2 
-- The CXX compiler identification is GNU 4.8.2 
-- Check for working C compiler: /usr/bin/cc 
-- Check for working C compiler: /usr/bin/cc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Check for working CXX compiler: /usr/bin/c++ 
-- Check for working CXX compiler: /usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Configuring done 
-- Generating done 
-- Build files have been written to: /home/vm/Desktop/TrackObj 

但是當我運行make我得到以下錯誤:

[email protected]:~/Desktop/TrackObj$ make 
Scanning dependencies of target TrackObj 
[ 50%] Building CXX object CMakeFiles/TrackObj.dir/Source.cpp.o 
In file included from /usr/include/c++/4.8/thread:35:0, 
       from /home/vm/Desktop/TrackObj/Source.cpp:10: 
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 
#error This file requires compiler and library support for the \ 
^
make[2]: *** [CMakeFiles/TrackObj.dir/Source.cpp.o] Error 1 
make[1]: *** [CMakeFiles/TrackObj.dir/all] Error 2 
make: *** [all] Error 2 

我很新的CMake的,但我敢確定問題是事實我使用多個.cpp文件和我使用CMake的方式。原因是當我試圖運行一個previews step in the tutorial,當這個項目只包含一個.cpp文件時,這一切都很好。

你可以看到源代碼,沒有工作here(與像去除#include <opencv\highgui.h> #include <opencv\cv.h>和寫作,而不是小的變化:。#include <opencv2/opencv.hpp> 和源代碼,沒有工作here用相同的微小變化除了,該項目包括非常簡單Fruit.cpp和Fruit.h如視頻描述。

我走過去的CMake的不那麼友好official tutorial和更友好johnlampOpenCV教程,但找不到我什麼正在做在這裏。

回答

4

該錯誤告訴您需要爲編譯器啓用C++ 11功能。您可以通過設置編譯器標誌-std=c++11(或舊版編譯器的-std=c++0x)來完成此操作。在CMake中,根據目標語言,在CMAKE_C_FLAGS/CMAKE_CXX_FLAGS變量中定義編譯器標誌。

你的情況:

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")