【问题标题】:How to compile caffe without next error "libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'"如何在没有下一个错误的情况下编译 caffe “libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'”
【发布时间】:2019-05-27 13:35:34
【问题描述】:

我已经看到了许多解决该问题的方法,但没有人帮助我。 我尝试在 Makefile 中添加 opencv_imgcodecs,使用 cmake 等。

Makefile.config

CPU_ONLY := 1
OPENCV_VERSION := 3
CUSTOM_CXX := g++
CUDA_DIR := /usr/local/cuda
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
        -gencode arch=compute_20,code=sm_21 \
        -gencode arch=compute_30,code=sm_30 \
        -gencode arch=compute_35,code=sm_35 \
        -gencode arch=compute_50,code=sm_50 \
        -gencode arch=compute_52,code=sm_52 \
        -gencode arch=compute_60,code=sm_60 \
        -gencode arch=compute_61,code=sm_61 \
        -gencode arch=compute_61,code=compute_61

BLAS := atlas
PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
PYTHON_LIB := /usr/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
TEST_GPUID := 0
Q ?= @

当我执行 make all 时,我在输出中收到下一个错误:

CXX/LD -o .build_release/tools/extract_features.bin
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
.build_release/lib/libcaffe.so: undefined reference to `cv::String::allocate(unsigned long)'
.build_release/lib/libcaffe.so: undefined reference to `cv::String::deallocate()'
.build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status
Makefile:635: recipe for target '.build_release/tools/extract_features.bin' failed
make: *** [.build_release/tools/extract_features.bin] Error 1

Ubuntu 18.04。 那是我使用的最后一个指南Here

从输出来看:

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0
CXX tools/extract_features.cpp
CXX/LD -o .build_release/tools/extract_features.bin
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'

看来我们要去动态库libcaffe.so 并在我们使用它与extract_features.bin 交互之后。如果您要了解 libcaffe.so 编译自的内容,也许可以在任何源文件中包含 OpenCV 连接。 但是如何确定创建libcaffe.so的源文件我不明白。 我试图查看Makefile,感觉好像他被混淆了,什么都不清楚。

【问题讨论】:

  • 一点建议?
  • 遇到了同样的问题?任何解决方案@AlmostAI
  • @KhanHafizurRahman 为我的案例添加了解决方案

标签: opencv cmake caffe


【解决方案1】:

问题与 opencv 版本有关。 我引用:

错误不是关于如何编译,如果我们改变什么都不会发生 Makefile 或 CMakeLists.txt。 OpenCV模块导致的错误 在版本 3 和 4 中有变化。

修复它,在每个要构建的错误文件中:

在#ifdef USE_OPENCV 部分,添加:

#include "opencv2/imgcodecs/imgcodecs.hpp"

所以它看起来像这样:

#ifdef USE_OPENCV #include #include #include #include #include "opencv2/imgcodecs/imgcodecs.hpp" 然后,包含代码的文件: cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);

改为:cv_img = cv::imread(image.first,cv::IMREAD_COLOR);

以及其他具有:

int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE);改为:

int cv_read_flag = (is_color ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE);

找到了解决方案here

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 2014-10-18
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多