有关编译,库相关问题,未定义的引用

博客作者在记录CMake构建过程中遇到的问题及其解决方案。首先,由于缺少torch/torch.h文件,作者添加了torch的正确头文件路径。接着,构建时出现未定义的符号错误,通过检查库链接,发现需要添加c10库。最后,通过分析错误信息,作者发现还需要链接torch库的其他部分以解决所有未定义引用。经过一系列调整,成功解决了链接错误。
摘要由CSDN通过智能技术生成

有关编译,库相关问题
博客园关闭了?没法发、修改文章了,就在这里记录一下吧。
之前的cmakelist是这么写的,没有问题

cmake_minimum_required(VERSION 2.6)

project(refinedet)

add_definitions(-std=c++11)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)

# tensorrt
include_directories(/data_2/tensorrt/TensorRT-7.0.0.11/include/) #include_directories(/usr/include/x86_64-linux-gnu/)
link_directories(/data_2/tensorrt/TensorRT-7.0.0.11/lib/) #link_directories(/usr/lib/x86_64-linux-gnu/)


find_package(CUDA REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)

#find_package(OpenCV)
#include_directories(OpenCV_INCLUDE_DIRS)

include_directories(/home/software_install/opencv3.4.6/include)
link_directories(/home/software_install/opencv3.4.6/lib)


set(CMAKE_PREFIX_PATH "/data_1/torch1.1.0") ###torch1.1.0
find_package(Torch REQUIRED)

include_directories(/data_1/torch1.1.0/include)
link_directories(/data_1/torch1.1.0/lib)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")

add_executable(refinedet ${PROJECT_SOURCE_DIR}/calibrator.cpp ${PROJECT_SOURCE_DIR}/refinedet.cpp)
target_link_libraries(refinedet nvinfer)
target_link_libraries(refinedet cudart)
target_link_libraries(refinedet "${TORCH_LIBRARIES}")
target_link_libraries(refinedet opencv_calib3d opencv_core opencv_dnn opencv_imgproc opencv_highgui opencv_imgcodecs caffe2)

add_definitions(-O2 -pthread)

find_package(Torch REQUIRED)
libtorch库是用find_package来找的,这种方法不利于打包发布,因为能用find_package前提是要有个share文件。如下图是我自己编译的libtorch库。
在这里插入图片描述中间有个share文件夹,就是供find_package来用的,opencv也有share文件夹。
现在不用find_package,需要自己指定库,注释了#find_package(Torch REQUIRED),就用这两条语句:

#find_package(Torch REQUIRED)
include_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/include)
link_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/lib)

首先就报错
/data_2/project_2021/tensorrt_refinedet/tensorRT_RefineDet-master/refinedet.cpp:15:25: fatal error: torch/torch.h: 没有那个文件或目录

我去找了找,确实torch/torch.h文件夹torch下面没有torch.h,然后我就搜索torch.h,发现在
torch/include/torch/csrc/api/include
这个文件夹下面有个torch文件夹下面。
然后加上这句就不报这个错误了

include_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/include)
include_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/api/include) ###加上这句就不报这个错误了
link_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/lib)

然后重新构建,又报错:

[100%] Linking CXX executable refinedet
/usr/bin/ld: CMakeFiles/refinedet.dir/refinedet.cpp.o: undefined reference to symbol '_ZN3c1011XLATensorIdEv'
/data_1/everyday/old/2020_xia/0901/pytorch/torch/lib/libc10.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/refinedet.dir/build.make:98: recipe for target 'refinedet' failed
make[2]: *** [refinedet] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/refinedet.dir/all' failed
make[1]: *** [CMakeFiles/refinedet.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

恩,这个提示的很明显,
torch/lib/libc10.so: error adding symbols: DSO missing from command line
我再最后加上c10这个库,就解决了这个报错

target_link_libraries(refinedet opencv_calib3d opencv_core opencv_dnn opencv_imgproc opencv_highgui opencv_imgcodecs caffe2 c10)

重新构建,又是一大堆报错

[100%] Linking CXX executable refinedet
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘torch::jit::Graph::insertNode(torch::jit::Node*)’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/jit/ir.h:1131:对‘torch::jit::Node::insertBefore(torch::jit::Node*)’未定义的引用
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> > c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> >::make<at::Tensor, std::unique_ptr<torch::autograd::Variable::AutogradMeta, std::default_delete<torch::autograd::Variable::AutogradMeta> >, bool&>(at::Tensor&&, std::unique_ptr<torch::autograd::Variable::AutogradMeta, std::default_delete<torch::autograd::Variable::AutogradMeta> >&&, bool&)’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/c10/util/intrusive_ptr.h:356:对‘torch::autograd::Variable::Impl::Impl(at::Tensor, std::unique_ptr<torch::autograd::Variable::AutogradMeta, std::default_delete<torch::autograd::Variable::AutogradMeta> >, bool, torch::autograd::Edge)’未定义的引用
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘torch::jit::tracer::isTracing()’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/jit/tracing_state.h:129:对‘torch::jit::tracer::getTracingState()’未定义的引用
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘torch::zeros(c10::ArrayRef<long>, c10::TensorOptions const&)’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1378:对‘torch::jit::tracer::getTracingState()’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1381:对‘torch::jit::Graph::create(c10::Symbol, unsigned long)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1382:对‘torch::jit::tracer::recordSourceLocation(torch::jit::Node*)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1383:对‘torch::jit::tracer::addInputs(torch::jit::Node*, char const*, c10::ArrayRef<long>)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1384:对‘torch::jit::tracer::addInputs(torch::jit::Node*, char const*, c10::TensorOptions const&)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1387:对‘torch::jit::tracer::setTracingState(std::shared_ptr<torch::jit::tracer::TracingState>)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1393:对‘torch::jit::tracer::setTracingState(std::shared_ptr<torch::jit::tracer::TracingState>)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:1394:对‘torch::jit::tracer::addOutput(torch::jit::Node*, at::Tensor const&)’未定义的引用
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘torch::jit::tracer::isTracing()’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/jit/tracing_state.h:129:对‘torch::jit::tracer::getTracingState()’未定义的引用
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘torch::full_like(at::Tensor const&, c10::Scalar)’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:508:对‘torch::jit::tracer::getTracingState()’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:511:对‘torch::jit::Graph::create(c10::Symbol, unsigned long)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:512:对‘torch::jit::tracer::recordSourceLocation(torch::jit::Node*)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:513:对‘torch::jit::tracer::addInputs(torch::jit::Node*, char const*, at::Tensor const&)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:514:对‘torch::jit::tracer::addInputs(torch::jit::Node*, char const*, c10::Scalar const&)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:517:对‘torch::jit::tracer::setTracingState(std::shared_ptr<torch::jit::tracer::TracingState>)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:523:对‘torch::jit::tracer::setTracingState(std::shared_ptr<torch::jit::tracer::TracingState>)’未定义的引用
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/autograd/generated/variable_factories.h:524:对‘torch::jit::tracer::addOutput(torch::jit::Node*, at::Tensor const&)’未定义的引用
CMakeFiles/refinedet.dir/refinedet.cpp.o:在函数‘c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> > c10::intrusive_ptr<torch::autograd::Variable::Impl, c10::detail::intrusive_target_default_null_type<torch::autograd::Variable::Impl> >::make<at::Tensor&, std::unique_ptr<torch::autograd::Variable::AutogradMeta, std::default_delete<torch::autograd::Variable::AutogradMeta> >, bool&>(at::Tensor&, std::unique_ptr<torch::autograd::Variable::AutogradMeta, std::default_delete<torch::autograd::Variable::AutogradMeta> >&&, bool&)’中:
/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/c10/util/intrusive_ptr.h:356:对‘torch::autograd::Variable::Impl::Impl(at::Tensor, std::unique_ptr<torch::autograd::Variable::AutogradMeta, std::default_delete<torch::autograd::Variable::AutogradMeta> >, bool, torch::autograd::Edge)’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/refinedet.dir/build.make:98: recipe for target 'refinedet' failed
make[2]: *** [refinedet] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/refinedet.dir/all' failed
make[1]: *** [CMakeFiles/refinedet.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

放做之前我肯定心态爆炸,经历了太多这些都习惯了,习惯就好。见得多了之后这些都不是问题。
这个问题还是搞了会儿,恩!未定义的引用。咋解决,之前经过遇到,都咋解决了的呢。翻开之前记录的一些小笔记:

相关函数未定义
a. 需要检查cmake中include_directories是否包含相关路径
b. 能找到头文件,但是头文件里确实没有相关定义,需要看下头文件是否找错,正常头文件都会找3rdparty下的。找到/usr目录下,就可以找错了,最终原因可能是include_directories没有,或者3rdparty下没有对应文件。
    undefine symbol
一般是没有指定链接对应的库或者库找错了。
a. 需要link_directories的路径是否正确。
b. target_link 需要添加对应的库名字
find libtorch 错误
通常发生在服务器上,服务器本身不会安装cuda,不能通过find_package去找torch

这里好像没有记录未定义的引用错误解决方法。
然后仔细看报错信息,无解。
然后打开lib文件夹,
在这里插入图片描述发现这些我只加了c10库,最下面一排的torch库应该是蛮重要的,然后我加上去试试,果真可以!
改完之后是这样的

cmake_minimum_required(VERSION 2.6)
project(refinedet)
add_definitions(-std=c++11)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)

# tensorrt
include_directories(/data_2/tmp_paper/Model-Compression-Deploy/tensorrt/TensorRT-7.0.0.11/include/) #include_directories(/usr/include/x86_64-linux-gnu/)
link_directories(/data_2/tmp_paper/Model-Compression-Deploy/tensorrt/TensorRT-7.0.0.11/lib/)

find_package(CUDA REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/include)
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different
# cuda
include_directories(/usr/local/cuda/include)
link_directories(/usr/local/cuda/lib64)
#find_package(OpenCV)
#include_directories(OpenCV_INCLUDE_DIRS)
include_directories(/home/yhl/software_install/opencv3.4.6/include)
link_directories(/home/yhl/software_install/opencv3.4.6/lib)

#set(CMAKE_PREFIX_PATH "/data_1/everyday/old/2020_xia/0901/pytorch/torch") ###torch1.1.0
#find_package(Torch REQUIRED)

#set(CMAKE_PREFIX_PATH /data_1/everyday/old/2020_xia/0901/pytorch/torch)
include_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/include)
include_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/include/torch/csrc/api/include)
link_directories(/data_1/everyday/old/2020_xia/0901/pytorch/torch/lib)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")

add_executable(refinedet ${PROJECT_SOURCE_DIR}/calibrator.cpp ${PROJECT_SOURCE_DIR}/refinedet.cpp)
target_link_libraries(refinedet nvinfer)
target_link_libraries(refinedet cudart)
#target_link_libraries(refinedet "${TORCH_LIBRARIES}")
target_link_libraries(refinedet opencv_calib3d opencv_core opencv_dnn opencv_imgproc opencv_highgui opencv_imgcodecs caffe2 c10 torch)
add_definitions(-O2 -pthread)

20210401 更新==========

g++ -Wl,-rpath,/home/yhl/Qt5.9.2/5.9.2/gcc_64/lib -o lstm main.o   -L/home/yhl/software_install/opencv3.2/lib -L/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib -L/usr/local/cuda-8.0/lib64 -L/usr/local/ssl/lib -L/usr/local/cuda/lib -L/usr/local/cuda-8.0/lib64/ -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/usr/lib/ -L/lib/x86_64-linux-gnu/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_imgcodecs -lopencv_videoio -lopencv_flann -lboost_serialization -lboost_system -lboost_filesystem -lboost_regex -lcaffe-d -lglog -lhdf5 -lhdf5_hl -lboost_thread -latlas -lcublas_static -lcudart -lculibos -lcurand_static -lssl3 -ldl -lrt /usr/lib/x86_64-linux-gnu/libgflags.a -L/home/yhl/Qt5.9.2/5.9.2/gcc_64/lib -lQt5Core -lpthread 
/usr/bin/ld: warning: libopencv_highgui.so.2.4, needed by /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so, may conflict with libopencv_highgui.so.3.2
/usr/bin/ld: warning: libopencv_imgproc.so.2.4, needed by /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so, may conflict with libopencv_imgproc.so.3.2
/usr/bin/ld: warning: libopencv_core.so.2.4, needed by /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so, may conflict with libopencv_core.so.3.2
/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so:对‘boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)’未定义的引用
/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so:对‘boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::find()’未定义的引用
/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so:对‘boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const’未定义的引用
/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so:对‘boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)’未定义的引用
collect2: error: ld returned 1 exit status
make: *** [lstm] Error 1
Makefile:228: recipe for target 'lstm' failed
17:20:05: 进程"/usr/bin/make"退出,退出代码 2 。
Error while building/deploying project lstm (kit: Desktop Qt 5.9.2 GCC 64bit)
When executing step "Make"
17:20:05: Elapsed time: 00:09.

今天这个错误实在解决不了。我是lstm跑前向的qt工程,pro里面写的如下:

QT += core
QT -= gui

CONFIG += c++11

TARGET = lstm
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

QMAKE_CXXFLAGS += -std=c++11



OPENCV_ROOT_PATH = /home/yhl/software_install/opencv3.2
CAFFE_ROOT_PATH = /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021

INCLUDEPATH += $${OPENCV_ROOT_PATH}/include \
               $${OPENCV_ROOT_PATH}/include/opencv \
               $${OPENCV_ROOT_PATH}/include/opencv2 \
               $${CAFFE_ROOT_PATH}/include \
               $${CAFFE_ROOT_PATH}/cmake-build-debug/src \
               $${CAFFE_ROOT_PATH}/cmake-build-debug/include \
               /usr/local/cuda-8.0/include

LIBS += -L$${OPENCV_ROOT_PATH}/lib \
        -L$${CAFFE_ROOT_PATH}/cmake-build-debug/lib \
        -L/usr/local/cuda-8.0/lib64

LIBS += -lopencv_core \
        -lopencv_highgui \
        -lopencv_imgproc \
        -lopencv_imgcodecs \
        -lopencv_videoio \
        -lopencv_calib3d \
        -lcaffe-d \


LIBS += -L/usr/local/ssl/lib
LIBS += -L/usr/local/cuda/lib
LIBS += -L/usr/local/cuda-8.0/lib64/
LIBS += -L/usr/lib/x86_64-linux-gnu/hdf5/serial
LIBS += -L/usr/lib/
LIBS += -L/usr/local/cuda-8.0/lib64
LIBS += -L/lib/x86_64-linux-gnu/

LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_imgcodecs
LIBS += -lopencv_videoio
LIBS += -lopencv_flann
LIBS += -lboost_serialization
LIBS += -lboost_system
LIBS += -lboost_filesystem
LIBS += -lboost_regex ##################

LIBS += -lcaffe-d


LIBS += -lglog
LIBS += -lhdf5
LIBS += -lhdf5_hl
LIBS += -lboost_thread
#LIBS += -lprotobuf
LIBS += -latlas
LIBS += -lcublas_static
LIBS += -lcudart
LIBS += -lculibos
LIBS += -lcurand_static
LIBS += -lssl3
LIBS += -lpthread
LIBS += -ldl
LIBS += -lrt
LIBS += /usr/lib/x86_64-linux-gnu/libgflags.a

SOURCES += main.cpp

根据错误提示

libcaffe-d.so:对‘boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char,

这句话是缺boost_regex库,可是我加了啊还是报这个啊
LIBS += -lboost_regex ##################

locate libboost_regex.so 也显示系统目录下面有这个库

/usr/lib/x86_64-linux-gnu/libboost_regex.so
/usr/lib/x86_64-linux-gnu/libboost_regex.so.1.58.0

找来jiamin,他看了一会儿也没有看出啥问题,然后在main.cpp目录下面敲

g++ main.cpp -I//data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/include -I/usr/local/cuda/include -I/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/include -I/home/yhl/software_install/opencv3.2/include --std=c++11 -lglog -lgflags -L/home/yhl/software_install/opencv3.2/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -L/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib -lcaffe-d -lboost_system -lboost_regex

当然不是一次性敲出这么多,边敲边运行缺什么库添加什么.

 g++ main.cpp -I//data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/include -I/usr/local/cuda/include -I/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/include -I/home/yhl/software_install/opencv3.2/include --std=c++11 -lglog -lgflags -L/home/yhl/software_install/opencv3.2/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -L/data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib -lcaffe-d -lboost_system -lboost_regex
main.cpp:350:0: warning: "TABLE_SIZE" redefined
 #define TABLE_SIZE 7117
 ^
main.cpp:96:0: note: this is the location of the previous definition
 #define TABLE_SIZE 7022
 ^
/usr/bin/ld: warning: libopencv_highgui.so.2.4, needed by /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so, may conflict with libopencv_highgui.so.3.2
/usr/bin/ld: warning: libopencv_imgproc.so.2.4, needed by /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so, may conflict with libopencv_imgproc.so.3.2
/usr/bin/ld: warning: libopencv_core.so.2.4, needed by /data_1/Yang/project/OCR/3rdlib/caffe_ocr_2021/cmake-build-debug/lib/libcaffe-d.so, may conflict with libopencv_core.so.3.2

目录下生成了a.out文件
运行

./a.out 
./a.out: error while loading shared libraries: libcaffe-d.so.1.0.0-rc5: cannot open shared object file: No such file or directory

当然这里会提示这些,但是已经能够说明代码没有问题。
然后再去看qt 的pro。

。。。


LIBS += -lopencv_flann
LIBS += -lboost_serialization
LIBS += -lboost_system
LIBS += -lboost_filesystem
LIBS += -lboost_regex ##################

#LIBS += -lcaffe-d

LIBS += -lglog
LIBS += -lhdf5
LIBS += -lhdf5_hl
LIBS += -lboost_thread
。。。

把#LIBS += -lcaffe-d这句话注释掉,居然就可以了!!!
caffe-d上面已经加过了。
这个难道还和库的先后顺序有关系吗?

。。。jiamin说不知道,让百度。
厉害厉害啊,我是解决不了这种错误。。。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值