Opencv'对'cv :: namedWindow ....'的未定义引用(链接错误)

时间:2015-09-11 22:50:00

标签: opencv linker cmake makefile undefined

我正在使用以下CMake文件使用 cmake 命令构建一个opencv项目,后跟 make

<script runat=server>
    Public Sub execvalchanged(Sender As Object, e As EventArgs) Handles ownerdpdnlst.SelectedIndexChanged
        executortxtbx.Text = ownerdpdnlst.SelectedValue
        MsgBox(ownerdpdnlst.SelectedValue)
    End Sub
</SCRIPT>

cmake 完成正常,但 make 会出现以下错误:

  

CMakeFiles / t.dir / t.cpp.o:在函数cmake_minimum_required(VERSION 2.8) project(t) #set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /home/keiths/opencv/opencv-2.4.11_build/build) SET(CMAKE_C_COMPILER mpicc) SET(CMAKE_CXX_COMPILER mpicxx) #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") include_directories(${OpenCV_INCLUDE_DIRS}) find_package(OpenCV REQUIRED) find_package(MPI REQUIRED) add_executable(t t.cpp) target_link_libraries(t ${OpenCV_LIBS} ${OpenCV_LIBRARIES} opencv_core opencv_highgui opencv_calib3d opencv_contrib opencv_core opencv_features2d opencv_flann opencv_gpu opencv_highgui opencv_imgproc opencv_legacy opencv_ml opencv_nonfree opencv_objdetect opencv_ocl opencv_photo opencv_stitching opencv_superres opencv_ts opencv_video opencv_videostab rt pthread m dl) MESSAGE(${OpenCV_LIBS}) MESSAGE(${OpenCV_INCLUDE_DIRS}) cv :: namedWindow(std :: __ cxx11 :: basic_string,std :: allocator&gt; const&amp;,int)'collect2:   错误:ld返回1退出状态make [2]: * [t]错误1 make [1]:*   [CMakeFiles / t.dir / all]错误2 make:*** [all]错误2

我尝试过运行以下命令

g ++ t.cpp $(pkg-config --libs opencv --cflags)

但是收到以下错误

  

/home/keiths/tmp/ccWFcaXH.o:在函数main': t.cpp:(.text+0x56): undefined reference to cv :: namedWindow(std :: __ cxx11 :: basic_string,std :: allocator&gt; const&amp;,int)'collect2:   错误:ld返回1退出状态

我正在运行以下简单代码

main': t.cpp:(.text+0x56):
  undefined reference to
  

我尽可能多地尝试了很多建议而没有成功。平台是CentOS,我是一个有限的用户(非root用户),我的本地安装(更新)版本的g ++ / gcc。我为pkg-config命令获取了正确的库列表,并为我的本地opencv文件夹配置了库路径和PATH

只是添加一个非常重要的一点,我尝试编译相同的代码,同时明确指定stock g ++编译器(/ usr / bin / g ++),一切顺利。所以似乎问题出在我的本地g ++编译器'/ home / keiths / lbin'上。我需要这个最新版本,但是对于c ++ 11的功能(旧的是4.4.7,系统管理员需要很长时间才能升级它)

1 个答案:

答案 0 :(得分:3)

在构建最新的g ++之前,我使用旧的g ++编译器(在系统bin文件夹中)构建了我的OpenCV库。使用新的g ++编译器重建OpenCV库为我做了这件事。出于好奇,我尝试使用旧的编译器构建OpenCV示例,并返回了许多“未定义的引用”行,但我很乐意交换问题,因为我还是不需要它!