OpenCV 学习笔记——symbol(s) not found for architecture x86_64(CLion环境)

一开始很着急,以为是Open CV没有配置好,少了什么库(明天晚上是DDL……)

所有和OpenCV相关的函数都调用错误。

编译器输出:

[ 50%] Linking CXX executable untitled9
Undefined symbols for architecture x86_64:
  "cv::Mat::deallocate()", referenced from:
      cv::Mat::release() in main.cpp.o
  "cv::String::deallocate()", referenced from:
      cv::String::~String() in main.cpp.o
  "cv::String::allocate(unsigned long)", referenced from:
      cv::String::String(char const*) in main.cpp.o
  "cv::imread(cv::String const&, int)", referenced from:
      _main in main.cpp.o
  "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
      _main in main.cpp.o
  "cv::fastFree(void*)", referenced from:
      cv::Mat::~Mat() 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[3]: *** [untitled9] Error 1
make[2]: *** [CMakeFiles/untitled9.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled9.dir/rule] Error 2
make: *** [untitled9] Error 2

试了之前可以通过的几个程序,发现都跑不了(这几个程序第一次运行成功都是在同一个工程下面跑的,所以后面要解释)

然后测试了一下第一个程序Untitled1,发现居然正常运行!然后打开Untitled6,发现代码和Untitled1居然一模一样,但是出现了上述一模一样的链接错误信息!说明不是库配置的问题。

想了一下,问题出在CLion的CMakeLists.txt上面:第一次配置CLion的时候是用Untitled1配置的,修改的也只是这个工程的CMakeLists.txt;后续程序测试也是拿第一个工程运行的,所以一直没有发现链接错误;

但是新建工程的时候忘了配置CMakeLists.txt,所以自然就库链接错误了

附上可以配置好的CMakeLists.txt(参考了一些博客,如有相同请联系,我将注明作者)

cmake_minimum_required(VERSION 3.9)
project(untitled1)

set(CMAKE_CXX_STANDARD 11)

#find_library(OpenCV)
find_package(OpenCV)

include_directories(${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)

add_executable(untitled1 main.cpp)
target_link_libraries(untitled1 ${OpenCV_LIBS})
然后把这个CMakeLists用到其他工程里面时,所有Untitled1改成对应工程的名字就好了



  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值