Closed BedRockJie closed 3 years ago
使用ncnn编译的一个小demo,在官方的sample中修改就可以编译成功,代码没有动过,将文件copy出去后,使用Cmake的方法进行编译,Cmake 脚本如下:
cmake_minimum_required(VERSION 3.2) project(carddetect) set(name carddetect) set(SOURCE main.cpp) add_executable(${name} ${SOURCE}) # 包含ncnn的头文件 include_directories(/home/gaojies/workspace/d1-tina-open/tools/ncnn/build-c906/install/include/ncnn /home/gaojies/workspace/d1-tina-open/tools/ncnn/src) # 包含ncnn的链接文件 link_directories(/home/gaojies/workspace/d1-tina-open/tools/ncnn/build-c906/install/lib) if(OpenCV_FOUND) target_include_directories(${name} PRIVATE ${OpenCV_INCLUDE_DIRS}) target_link_libraries(${name} PRIVATE ncnn ${OpenCV_LIBS}) elseif(NCNN_SIMPLEOCV) target_compile_definitions(${name} PUBLIC USE_NCNN_SIMPLEOCV) target_link_libraries(${name} PRIVATE ncnn) endif()
在编译的过程中出现了 比较多链接不到 函数的问题。
[ 50%] Linking CXX executable carddetect /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L125': main.cpp:(.text+0x940): undefined reference to `ncnn::Net::Net()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0x964): undefined reference to `ncnn::Net::register_custom_layer(char const*, ncnn::Layer* (*)(void*), void (*)(ncnn::Layer*, void*), void*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0x97a): undefined reference to `ncnn::Net::load_param(char const*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.LEHB6': main.cpp:(.text+0x990): undefined reference to `ncnn::Net::load_model(char const*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.LEHB9': main.cpp:(.text+0xa8c): undefined reference to `ncnn::Mat::from_pixels_resize(unsigned char const*, int, int, int, int, int, ncnn::Allocator*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L144': main.cpp:(.text+0xb5c): undefined reference to `ncnn::Option::Option()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.LEHE9': main.cpp:(.text+0xb88): undefined reference to `ncnn::copy_make_border(ncnn::Mat const&, ncnn::Mat&, int, int, int, int, int, float, ncnn::Option const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0xbc2): undefined reference to `ncnn::Mat::substract_mean_normalize(float const*, float const*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0xbd6): undefined reference to `ncnn::Net::create_extractor() const' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0xbf2): undefined reference to `ncnn::Extractor::input(char const*, ncnn::Mat const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0xc24): undefined reference to `ncnn::Extractor::extract(char const*, ncnn::Mat&, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.LEHE12': main.cpp:(.text+0xd8e): undefined reference to `ncnn::Extractor::extract(char const*, ncnn::Mat&, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.LEHE14': main.cpp:(.text+0xef8): undefined reference to `ncnn::Extractor::extract(char const*, ncnn::Mat&, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L146': main.cpp:(.text+0x137e): undefined reference to `ncnn::Extractor::~Extractor()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0x13a0): undefined reference to `ncnn::Net::~Net()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0x1442): undefined reference to `ncnn::Extractor::~Extractor()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0x146c): undefined reference to `ncnn::Net::~Net()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L145': main.cpp:(.text+0x15ca): undefined reference to `cv::rectangle(cv::Mat&, cv::Rect_<int>, cv::Scalar_<unsigned char> const&, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L168': main.cpp:(.text+0x1664): undefined reference to `cv::getTextSize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double, int, int*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.LEHE21': main.cpp:(.text+0x1764): undefined reference to `cv::rectangle(cv::Mat&, cv::Rect_<int>, cv::Scalar_<unsigned char> const&, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L175': main.cpp:(.text+0x17dc): undefined reference to `cv::putText(cv::Mat&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<unsigned char>, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text+0x184e): undefined reference to `cv::imwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L173': main.cpp:(.text+0x1986): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L0 ': main.cpp:(.text._ZN4ncnn3MatC2EimPNS_9AllocatorE[_ZN4ncnn3MatC5EimPNS_9AllocatorE]+0x7c): undefined reference to `ncnn::Mat::create(int, unsigned long, ncnn::Allocator*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text._ZN11YoloV5FocusC2Ev[_ZN11YoloV5FocusC5Ev]+0x12): undefined reference to `ncnn::Layer::Layer()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: main.cpp:(.text._ZNK11YoloV5Focus7forwardERKN4ncnn3MatERS1_RKNS0_6OptionE[_ZNK11YoloV5Focus7forwardERKN4ncnn3MatERS1_RKNS0_6OptionE]+0x82): undefined reference to `ncnn::Mat::create(int, int, int, unsigned long, int, ncnn::Allocator*)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x20): undefined reference to `ncnn::Layer::load_param(ncnn::ParamDict const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x28): undefined reference to `ncnn::Layer::load_model(ncnn::ModelBin const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x30): undefined reference to `ncnn::Layer::create_pipeline(ncnn::Option const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x38): undefined reference to `ncnn::Layer::destroy_pipeline(ncnn::Option const&)' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x40): undefined reference to `ncnn::Layer::forward(std::vector<ncnn::Mat, std::allocator<ncnn::Mat> > const&, std::vector<ncnn::Mat, std::allocator<ncnn::Mat> >&, ncnn::Option const&) const' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x50): undefined reference to `ncnn::Layer::forward_inplace(std::vector<ncnn::Mat, std::allocator<ncnn::Mat> >&, ncnn::Option const&) const' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTV11YoloV5Focus[_ZTV11YoloV5Focus]+0x58): undefined reference to `ncnn::Layer::forward_inplace(ncnn::Mat&, ncnn::Option const&) const' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o: in function `.L0 ': main.cpp:(.text._ZN11YoloV5FocusD2Ev[_ZN11YoloV5FocusD5Ev]+0x20): undefined reference to `ncnn::Layer::~Layer()' /home/gaojies/Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: CMakeFiles/carddetect.dir/main.cpp.o:(.rodata._ZTI11YoloV5Focus[_ZTI11YoloV5Focus]+0x10): undefined reference to `typeinfo for ncnn::Layer' collect2: error: ld returned 1 exit status make[2]: *** [carddetect] Error 1 make[1]: *** [CMakeFiles/carddetect.dir/all] Error 2 make: *** [all] Error 2
然后,准备使用 g++ 手动编译一下 使用如下指令: riscv64-unknown-linux-gnu-g++ -o main -I /home/gaojies/workspace/d1-tina-open/tools/ncnn/build-c906/install/include/ncnn -I /home/gaojies/workspace/d1-tina-open/tools/ncnn/src main.cpp /home/gaojies/workspace/d1-tina-open/tools/ncnn/build-c906/install/lib/libncnn.a 出现了: /Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: /tmp/cctXu0jW.o:(.rodata._ZTI11YoloV5Focus[_ZTI11YoloV5Focus]+0x10): undefined reference to `typeinfo for ncnn::Layer' collect2: error: ld returned 1 exit status
duplicated of https://github.com/Tencent/ncnn/issues/3141
detail | 详细描述 | 詳細な説明
使用ncnn编译的一个小demo,在官方的sample中修改就可以编译成功,代码没有动过,将文件copy出去后,使用Cmake的方法进行编译,Cmake 脚本如下:
在编译的过程中出现了 比较多链接不到 函数的问题。
然后,准备使用 g++ 手动编译一下 使用如下指令: riscv64-unknown-linux-gnu-g++ -o main -I /home/gaojies/workspace/d1-tina-open/tools/ncnn/build-c906/install/include/ncnn -I /home/gaojies/workspace/d1-tina-open/tools/ncnn/src main.cpp /home/gaojies/workspace/d1-tina-open/tools/ncnn/build-c906/install/lib/libncnn.a 出现了: /Tools/riscv64-linux-x86_64-20210512/bin/../lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: /tmp/cctXu0jW.o:(.rodata._ZTI11YoloV5Focus[_ZTI11YoloV5Focus]+0x10): undefined reference to `typeinfo for ncnn::Layer' collect2: error: ld returned 1 exit status