问题记录 --> 未定义的引用 ||| not found
- 例子0 对‘myprojectApi::myprojectApi(bool, int, int, bool)’未定义的引用
- 例子1 源码编译opencv,报错 libopencv_imgcodecs.so.3.2.0:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
- 例子2 之前编译caffe的时候也会报这个错误 对‘TIFFWriteEncodedStrip@LIBTIFF_4.0’未定义的引用
- 例子3 libpng16so16:对inflatevalidatezlib_129未定义的引用
- 例子4 /data_1/3rdparty/caffe/include/caffe/util/device_alternate.hpp:34:23: fatal error: cublas_v2.h: 没有那个文件或目录
- 例子5 not found libopencv_highgui.so:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
- 例子6 一个可执行文件包换到另外一个平台跑, 提示缺库问题
例子0 对‘myprojectApi::myprojectApi(bool, int, int, bool)’未定义的引用
这是我自己写一个库的测试工程时候报的错误。比如这个库名字叫libyanzhengma_chejian.so
在CMakeLists.txt下面这么写:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yzm_test)
SET(CMAKE_BUILD_TYPE "Debug")
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv-3.4.10/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv-3.4.10/lib)
# caffe
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/lib)
set(INC_DIR ${CMAKE_SOURCE_DIR}/api)
set(LINK_DIR ${CMAKE_SOURCE_DIR}/lib)
include_directories(${INC_DIR})
link_directories(${LINK_DIR})
add_executable(yzm_test main.cpp)
set_property(TARGET yzm_test PROPERTY CXX_STANDARD 11)
库的头文件就在${CMAKE_SOURCE_DIR}/api,库文件就在${CMAKE_SOURCE_DIR}/lib目录下libyanzhengma_chejian.so
这个时候编译就报错未定义的引用
====================[ Build | all | Debug ]=====================================
/home/yhl/software/clion-2018.3.4/bin/cmake/linux/bin/cmake --build /data_1/everyday/1028/yzm/cmake-build-debug --target all -- -j 4
[ 50%] Building CXX object CMakeFiles/yzm_test.dir/main.cpp.o
[100%] Linking CXX executable yzm_test
CMakeFiles/yzm_test.dir/main.cpp.o:在函数‘main’中:
/data_1/everyday/1028/yzm/main.cpp:8:对‘myprojectApi::myprojectApi(bool, int, int, bool)’未定义的引用
/data_1/everyday/1028/yzm/main.cpp:14:对‘cv::imread(cv::String const&, int)’未定义的引用
/data_1/everyday/1028/yzm/main.cpp:16:对‘myprojectApi::yanzhengma_api_process(cv::Mat&, YZM_ImgOutMsg&)’未定义的引用
/data_1/everyday/1028/yzm/main.cpp:8:对‘myprojectApi::~myprojectApi()’未定义的引用
CMakeFiles/yzm_test.dir/main.cpp.o:在函数‘cv::String::~String()’中:
/data_1/everyday/1028/yzm/3rdparty/opencv-3.4.10/include/opencv2/core/cvstd.hpp:648:对‘cv::String::deallocate()’未定义的引用
CMakeFiles/yzm_test.dir/main.cpp.o:在函数‘cv::String::operator=(cv::String const&)’中:
/data_1/everyday/1028/yzm/3rdparty/opencv-3.4.10/include/opencv2/core/cvstd.hpp:656:对‘cv::String::deallocate()’未定义的引用
CMakeFiles/yzm_test.dir/main.cpp.o:在函数‘cv::Mat::~Mat()’中:
/data_1/everyday/1028/yzm/3rdparty/opencv-3.4.10/include/opencv2/core/mat.inl.hpp:789:对‘cv::fastFree(void*)’未定义的引用
CMakeFiles/yzm_test.dir/main.cpp.o:在函数‘cv::Mat::release()’中:
/data_1/everyday/1028/yzm/3rdparty/opencv-3.4.10/include/opencv2/core/mat.inl.hpp:901:对‘cv::Mat::deallocate()’未定义的引用
CMakeFiles/yzm_test.dir/main.cpp.o:在函数‘cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’中:
/data_1/everyday/1028/yzm/3rdparty/opencv-3.4.10/include/opencv2/core/cvstd.inl.hpp:82:对‘cv::String::allocate(unsigned long)’未定义的引用
collect2: error: ld returned 1 exit status
在CMakeLists加上这句话就不报这个错误了。target_link_libraries(yzm_test yanzhengma_chejian)
set(INC_DIR ${CMAKE_SOURCE_DIR}/api)
set(LINK_DIR ${CMAKE_SOURCE_DIR}/lib)
include_directories(${INC_DIR})
link_directories(${LINK_DIR})
add_executable(yzm_test main.cpp)
target_link_libraries(yzm_test yanzhengma_chejian)
现在CMakeLists.txt如下:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yzm_test)
SET(CMAKE_BUILD_TYPE "Debug")
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv-3.4.10/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv-3.4.10/lib)
# caffe
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/caffe_8)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/cuda_8)
set(INC_DIR ${CMAKE_SOURCE_DIR}/api)
set(LINK_DIR ${CMAKE_SOURCE_DIR}/lib)
include_directories(${INC_DIR})
link_directories(${LINK_DIR})
add_executable(yzm_test main.cpp)
target_link_libraries(yzm_test yanzhengma_chejian opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui opencv_ml opencv_video opencv_videoio)
target_link_libraries(yzm_test caffe)
set_property(TARGET yzm_test PROPERTY CXX_STANDARD 11)
然后又报protobuf未定义的引用
/data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so:对‘google::protobuf::io::CodedInputStream::ReadVarint64Fallback()’未定义的引用
/data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so:对‘google::protobuf::MessageLite::ParseFromString2(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’未定义的引用
/data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so:对‘google::protobuf::io::CodedInputStream::IncrementRecursionDepthAndPushLimit(int)’未定义的引用
/data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so:对‘google::protobuf::internal::WireFormat::ReadPackedEnumPreserveUnknowns(google::protobuf::io::CodedInputStream*, unsigned int, bool (*)(int), google::protobuf::UnknownFieldSet*, google::protobuf::RepeatedField<int>*)’未定义的引用
/data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so:对‘google::protobuf::io::CodedInputStream::ReadVarint32Fallback(unsigned int)’未定义的引用
/data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so:对‘google::protobuf::io::CodedOutputStream::WriteVarint32SlowPath(unsigned int)’未定义的引用
添加link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/protobuf)就可以了。
# caffe
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/caffe_8)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/cuda_8)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/protobuf)
总结:
调用由一个caffe封装好的一个识别的api,只需要提供这个识别api和.so文件,然后其他库只需要提供so不需要提供头文件。opencv因为需要用还是需要提供头文件。
比如我这里只用到了caffe,但是编译caffe又依赖cuda,protobuf等,一开始不加相应库会报相应的问题。这个时候只需要添加库的搜索路径就可以了。头文件不需要,因为已经编译到库里面了。
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/cuda_8)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/protobuf)
所以,我最后的CMakeLists.txt如下:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(yzm_test)
SET(CMAKE_BUILD_TYPE "Debug")
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv-3.4.10/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/opencv-3.4.10/lib)
# caffe
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/caffe_8)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/cuda_8)
link_directories(${CMAKE_SOURCE_DIR}/3rdparty/others/protobuf)
set(INC_DIR ${CMAKE_SOURCE_DIR}/api)
set(LINK_DIR ${CMAKE_SOURCE_DIR}/lib)
include_directories(${INC_DIR})
link_directories(${LINK_DIR})
add_executable(yzm_test main.cpp)
target_link_libraries(yzm_test yanzhengma_chejian opencv_core opencv_imgproc opencv_imgcodecs opencv_highgui opencv_ml opencv_video opencv_videoio)
target_link_libraries(yzm_test caffe)
set_property(TARGET yzm_test PROPERTY CXX_STANDARD 11)
我把原本的opencv3.4.10库换成了opencv3.2.0库。报错如下:
====================[ Build | all | Debug ]=====================================
/home/yhl/software/clion-2018.3.4/bin/cmake/linux/bin/cmake --build /data_1/everyday/1028/yzm/cmake-build-debug --target all -- -j 4
[ 50%] Building CXX object CMakeFiles/yzm_test.dir/main.cpp.o
[100%] Linking CXX executable yzm_test
/usr/bin/ld: warning: libopencv_core.so.3.4, needed by /data_1/everyday/1028/yzm/lib/libyanzhengma_chejian.so, may conflict with libopencv_core.so.3.2
/usr/bin/ld: warning: libopencv_imgproc.so.3.4, needed by /data_1/everyday/1028/yzm/lib/libyanzhengma_chejian.so, may conflict with libopencv_imgproc.so.3.2
/usr/bin/ld: warning: libopencv_videoio.so.3.4, needed by /data_1/everyday/1028/yzm/lib/libyanzhengma_chejian.so, may conflict with libopencv_videoio.so.3.2
/usr/bin/ld: warning: libopencv_highgui.so.3.4, needed by /data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libopencv_imgcodecs.so.3.4, needed by /data_1/everyday/1028/yzm/3rdparty/others/caffe_8/libcaffe.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libpng16.so.16, needed by //data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicui18n.so.58, needed by //data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.58, needed by //data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicudata.so.58, needed by //data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_interlace_handling@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_image_width@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_IHDR@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_io_ptr@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_longjmp_fn@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_bgr@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_PLTE@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_x_pixels_per_meter@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_getTimeZoneDisplayName_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_read_row@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_setSubstChars_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_tRNS@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_error_fn@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_packing@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_clone_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_read_end@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_create_write_struct@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_write_fn@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_error@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucol_strcoll_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_strip_16@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_oFFs@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucol_open_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_compression_level@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_text@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_gAMA@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_filler@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_open_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘uenum_close_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_countAliases_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucol_close_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucol_getSortKey_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_read_update_info@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_write_image@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_gamma@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_get_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘uenum_next_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_read_info@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_toUnicode_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘u_errorName_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_getAlias_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_gray_to_rgb@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_inDaylightTime_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_valid@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_write_rows@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_sig_bytes@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘u_strToLower_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_write_chunk@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_getStandardName_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_pHYs@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘u_strToUpper_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_destroy_read_struct@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_option@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_getMaxCharSize_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_fromUnicode_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_open_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_getDefaultName_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_getDefaultTimeZone_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_read_fn@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_write_end@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_invert_mono@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_getDSTSavings_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_tRNS@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_destroy_write_struct@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_packswap@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_text@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_create_read_struct@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_close_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_countAvailable_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_openCountryTimeZones_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_compareNames_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_PLTE@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucnv_getAvailableName_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_openTimeZoneIDEnumeration_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_close_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_openTimeZones_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucol_setAttribute_58’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_IHDR@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_expand@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_write_info@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_oFFs@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_create_info_struct@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_y_pixels_per_meter@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_image_height@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_read_image@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_get_channels@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Gui.so.5:对‘png_set_gAMA@PNG16_0’未定义的引用
//data_1/Yang/software_install/Anaconda1105/lib/libQt5Core.so.5:对‘ucal_setMillis_58’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/yzm_test.dir/build.make:83: recipe for target 'yzm_test' failed
make[2]: *** [yzm_test] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/yzm_test.dir/all' failed
make[1]: *** [CMakeFiles/yzm_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
例子1 源码编译opencv,报错 libopencv_imgcodecs.so.3.2.0:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/data_1/everyday/1028/opencv-3.2.0/my_install -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON -D BUILD_EXAMPLES=ON -D WITH_CUDA=OFF -D WITH_MATLAB=OFF ..
[ 25%] Building CXX object modules/ts/CMakeFiles/opencv_ts.dir/src/cuda_test.cpp.o
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFReadDirectory@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFWriteEncodedStrip@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFIsTiled@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFWriteScanline@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFGetField@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFNumberOfStrips@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFScanlineSize@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFReadEncodedTile@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFReadRGBATile@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFClose@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFRGBAImageOK@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘T 缺的库都会在/usIFFOpen@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFReadEncodedStrip@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFSetField@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFSetWarningHandler@LIBTIFF_4.0’未定义的引用
../../lib/libopencv_imgcodecs.so.3.2.0:对‘TIFFSetErrorHandler@LIBTIFF_4.0’未定义的引用
collect2: error: ld returned 1 exit status
apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:104: recipe for target 'bin/opencv_annotation' failed
make[2]: *** [bin/opencv_annotation] Error 1
CMakeFiles/Makefile2:3924: recipe for target 'apps/annotation/CMakeFiles/opencv_annotation.dir/all' failed
make[1]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
这个错误网上很多,仔细看报错,什么tiff4版本的。然后
ldd libopencv_imgcodecs.so.3.2.0
会出来:
linux-vdso.so.1 => (0x00007ffd3ec99000)
libopencv_imgproc.so.3.2 => /data_1/everyday/1028/opencv-3.2.0/build/lib/libopencv_imgproc.so.3.2 (0x00007f08a0082000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f089fe65000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f089fc0c000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f089f9e7000)
libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f089f772000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007f089f51c000)
libopencv_core.so.3.2 => /data_1/everyday/1028/opencv-3.2.0/build/lib/libopencv_core.so.3.2 (0x00007f089e79b000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f089e581000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f089e247000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f089df3e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f089dd28000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f089d95e000)
libtbb.so.2 => /usr/lib/x86_64-linux-gnu/libtbb.so.2 (0x00007f089d721000)
/lib64/ld-linux-x86-64.so.2 (0x00007f08a1d7d000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f089d4ff000)
libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f089d2f1000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f089d0ed000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f089cee5000)
libGL.so.1 => /usr/lib/nvidia-440/libGL.so.1 (0x00007f089cc3c000)
libopenblas.so.0 => /usr/lib/libopenblas.so.0 (0x00007f089aba8000)
libGLX.so.0 => /usr/lib/nvidia-440/libGLX.so.0 (0x00007f089a978000)
libGLdispatch.so.0 => /usr/lib/nvidia-440/libGLdispatch.so.0 (0x00007f089a6a5000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f089a37a000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f089a040000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f0899e2e000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f0899bef000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f08999cd000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f08997c9000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f08995c3000)
可以看到libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f089f772000) 这里是5版本的。我是凌乱了到底需要多少!?
网上有人说把anchonda注释掉,再重新打开一个终端编译就可以。我试了我这边不好使。
locate libtiff.so
出来一大堆库,但是没有看到4版本的。
这里有人解释,https://github.com/BVLC/caffe/issues/1559
I'm looking at a similar problem, and thought I'd chime in.
There is no libtiff5. libtiff.so.5 is the libtiff 4.X ABI. They had to jump an ABI number because of a mistake in an earlier version.
I'm seeing this exact same problem; Cmake is building against the system libtiff.so.5, but is linking against anaconda's libtiff.so.5. The ABI versions aren't that different, but the symbols in the system version include a suffix of @@LIBTIFF_4.0, and the anaconda version doesn't.
这个解释好像是对的。可能原本应该链接系统下面的libtiff.so.5,但是先在conda下面找到了这个库就用它了,由于两个库有点儿差异导致的。
我注释了conda但是报另外的错误,什么qt。可能用到了conda下面的库。然后,又在网上找到了一个法子,就是在编译选项中加这个:
-D BUILD_TIFF=ON
这个意思就是说源码编译tiff这个库!恩,可以查看opencv目录下面的3rdparty自带了这个库的源码,可以用来源码编译。
恩,加上这句话确实可以了。
例子2 之前编译caffe的时候也会报这个错误 对‘TIFFWriteEncodedStrip@LIBTIFF_4.0’未定义的引用
https://www.cnblogs.com/yanghailin/p/11255346.html#5-cmakelist-编译caffe报错
另外网友的例子:
网上人家编译caffe也报这个错,解决办法就是重新编译opencv和caffe,确保都是用的同一个地方的libtiff.so库。
https://github.com/BVLC/caffe/issues/1559
I solved the problem by manually compiling libtiff and setting CMAKE_PREFIX_PATH, which makes caffe and opencv link to the same libtiff. I think this is a better way without side effects.
The error of undefined reference to TIFFxxxxxx comes from the following fact:
Opencv links to the libtiff found by cmake. By default, cmake only searches on the standard library path, e.g., /usr/local/lib/, by find_package() in /usr/local/share/cmake-xx/Modules/FindTIFF.cmake. If libtiff was not found there, opencv will compile it on the fly from its distribution /path/to/opencv_source_code/3rdparty/libtiff/.
While, caffe links to the libtiff pre-compiled by anaconda, located in $HOME/anaconda3/lib/
So, caffe and opencv link to different versions of libtiff.
solution
The way is to make opencv and caffe link to the same libtiff.
Step 1: manually compile the libtiff
wget http://download.osgeo.org/libtiff/tiff-4.0.10.tar.gz
tar -zxvf tiff-4.0.10.tar.gz && cd tiff-4.0.10
./configure --prefix=/path/to/libtiff/
make
make install (**Note**: no `sudo` since most people have no `root` privilege)
This will install libtiff into /path/to/libtiff/ in your home directory.
Step 2: recompile opencv with the newly installed libtiff
cd /path/to/opencv_source_code/
mkdir release && cd release
cmake -DCMAKE_PREFIX_PATH=/path/to/libtiff/ -DBUILD_LIST=core,highgui,improc,python3 -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -DPYTHON3_EXECUTABLE=$(which python) -DPYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
(you can choose other modules)
make
make install (**Note**: no `sudo`)
The critical in step 2 is that set CMAKE_PREFIX_PATH to force cmake to follow the newly installed libtiff.
PYTHON3_EXECUTABLE, PYTHON3_INCLUDE_DIR, and PYTHON3_PACKAGES_PATH point to the anaconda python.
I only choose four modules of opencv, core,highgui,improc,python3, by setting BUILD_LIST, which is enough for caffe.
Step 3: recompile caffe with the newly installed libtiff
cd /path/to/caffe
vim Makefile.config
In Makefile.config, modify:
INCLUDE_DIRS := /path/to/libtiff/include $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := /path/to/libtiff/lib $(PYTHON_LIB) /usr/local/lib /usr/lib
This will force caffe to use the newly installed libtiff. Then,
make all
例子3 libpng16so16:对inflatevalidatezlib_129未定义的引用
例子4 /data_1/3rdparty/caffe/include/caffe/util/device_alternate.hpp:34:23: fatal error: cublas_v2.h: 没有那个文件或目录
敲命令
locate cublas_v2.h
会出来 /usr/local/cuda-8.0/include/cublas_v2.h
然后在cmakelist里面添加这两句话:
include_directories(/usr/local/cuda-8.0/include/)
link_directories(/usr/local/cuda/lib64)
include_directories 是包含头文件
link_directories是包含库
例子5 not found libopencv_highgui.so:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
https://www.cnblogs.com/yanghailin/p/11255346.html#6-报错解决
/usr/bin/ld: warning: libjpeg.so.9, needed by //usr/local/lib/libuvc.so, not found (try using -rpath or -rpath-link)
libopencv_highgui.so:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
例子6 一个可执行文件包换到另外一个平台跑, 提示缺库问题
新服务器如何测试:
一般情况下我会拿一个最新的算法发版的压缩包,如:project.tar.gz 。
服务器一般会提前装好驱动(寒武纪或英伟达或者其他)
把压缩包解压之后。
把对应发版服务器(新服务器是英伟达,就从英伟达机器上拷贝, 寒武纪就从寒武纪上拷贝)上的发版目录下的可执行程序project_1拷贝到/bin 目录下。
cd bin
source ../scripts/project_env.sh (加载指定库路径的环境变量)
./project -alsologtostderr 1 即可进行标准测试。
ps : 一般情况下之前适配过的服务器,软件部自己就可以取压缩包进行系统测试。
也就是算法自己要去测试一台新服务器的时候,需要用上述操作进行测试。
可能在project_1 执行时候会缺库啥的,或者报 xxx symbol not found in libxxx.so。
如果直接说缺库, 那就去对应的服务器(寒武纪就是70.217, 英伟达就是70.209)上locate找。 或者用find 去/usr目录下找。 一般情况下 缺的库都会在/usr目录下。
“xxx symbol not found in libxxx.so” 这个说明libxxx.so 与 新服务器的系统不匹配, 那么就先找下新服务器系统/usr下面有没有libxxx.so ,有的话就直接用新服务器自带的。 如果没有的话,就比较麻烦,需要根据实际情况处理, 一般来说,如果没有找到, 那么就需要确认xxx实际到底在那个库中,然后再从对应服务器上找到那个库,拷贝到新服务器上。
如何定位xxx , 用grep -r 去找(路径一般是3rdparty下,然后就是/usr下), 然后strings 这个命令也可以确认找的对不对(具体用法自己查下。)
然后找到的库如何指定, 加入你把找的库放在了3rdlib/new_lib 目录下,那就使用export LD_LIBRARY_PATH=3rdlib/new_lib:$LD_LIBRARY_PATH
3rdlib/new_lib 只是一个示例,最终使用更建议用绝对路径,不容易出错。