Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to cross-compile with some"undefined reference" errors #11878

Closed
lazylazypig opened this issue Jul 3, 2018 · 3 comments
Closed

Failed to cross-compile with some"undefined reference" errors #11878

lazylazypig opened this issue Jul 3, 2018 · 3 comments
Labels
category: build/install question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org

Comments

@lazylazypig
Copy link

System information (version)
  • OpenCV => 3.4.1
  • Operating System / Platform => Manjaro 17.1.10 (host)
  • Compiler => arm-linux-gnueabi-g++ (ver 4.9.4)
Detailed description

I have failed to cross-compile opencv3.4.1 with several '### undefined reference' errors related to std::exception_ptr

Steps to reproduce

My configuration is as follow:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D ENABLE_CXX11=ON -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D BUILD_TESTS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_opencv_world=ON -D WITH_TBB=ON -D BUILD_TBB=ON -D WITH_JPEG=ON -D BUILD_JPEG=ON -D WITH_PNG=ON -D BUILD_PNG=ON -D WITH_TIFF=ON -D BUILD_TIFF=ON -D WITH_FFMPEG=ON -D BUILD_opencv_apps=OFF -D CMAKE_TOOLCHAIN_FILE=mypath/toolchain.cmake ..

And, My toolchain.cmake file look like these:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER /opt/arm-hisiv600-linux/bin/arm-hisiv600-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /opt/arm-hisiv600-linux/bin/arm-hisiv600-linux-gnueabi-g++)

set(CMAKE_FIND_ROOT_PATH /opt/arm-hisiv600-linux/arm-hisiv600-linux-gnueabi)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

add_definitions(-DENABLE_NEON=ON)
add_definitions(-DENABLE_VFPV3=ON)

set(CMAKE_C_FLAGS "-mcpu=cortex-a17.cortex-a7 -mfpu=neon-vfpv4 -mfp16-format=ieee -mfloat-abi=softfp -mno-unaligned-access -fno-aggressive-loop-optimizations")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_C_FLAGS}")

After several minutes, I got some errors as follow:
[ 88%] Built target opencv_ts
[ 89%] Building CXX object modules/world/CMakeFiles/opencv_perf_dnn.dir//dnn/perf/opencl/perf_convolution.cpp.o
[ 89%] Building CXX object modules/world/CMakeFiles/opencv_perf_dnn.dir/
/dnn/perf/perf_caffe.cpp.o
[ 89%] Building CXX object modules/world/CMakeFiles/opencv_perf_dnn.dir//dnn/perf/perf_convolution.cpp.o
[ 89%] Building CXX object modules/world/CMakeFiles/opencv_perf_dnn.dir/
/dnn/perf/perf_main.cpp.o
[ 89%] Building CXX object modules/world/CMakeFiles/opencv_perf_dnn.dir/__/dnn/perf/perf_net.cpp.o
[ 89%] Linking CXX executable ../../bin/opencv_perf_dnn
../../lib/libopencv_world.so.4.0.0: undefined reference to std::rethrow_exception(std::__exception_ptr::exception_ptr)' ../../lib/libopencv_world.so.4.0.0: undefined reference to std::__exception_ptr::exception_ptr::exception_ptr()'
../../lib/libopencv_world.so.4.0.0: undefined reference to std::current_exception()' ../../lib/libopencv_world.so.4.0.0: undefined reference to std::__exception_ptr::exception_ptr::exception_ptr(std::__exception_ptr::exception_ptr const&)'
../../lib/libopencv_world.so.4.0.0: undefined reference to std::__exception_ptr::exception_ptr::swap(std::__exception_ptr::exception_ptr&)' ../../lib/libopencv_world.so.4.0.0: undefined reference to std::__exception_ptr::exception_ptr::~exception_ptr()'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/world/CMakeFiles/opencv_perf_dnn.dir/build.make:147:bin/opencv_perf_dnn] Error 1
make[1]: *** [CMakeFiles/Makefile2:1795:modules/world/CMakeFiles/opencv_perf_dnn.dir/all] Error 2
make: *** [Makefile:163:all] Error 2

I have set "-D ENABLE_CXX11=ON", and add "-std=c++11" to CMAKE_CXX_FLAGS (in the toolchain.cmake file), but still failed. Could anyone help me? Thanks :)

@alalek
Copy link
Member

alalek commented Jul 3, 2018

This is build configuration problem. std::exception_ptr is properly declared by compiler in headers, but final binary can't link - try adding something like -lstdc++ into linker flags.
If there is no such library with std::exception_ptr symbols, then used compiler setup is buggy - we can't help really here.
There is workaround in OpenCV to disable using std::exception_ptr via compiler definition:

  • -D CV__EXCEPTION_PTR=0 (via CMAKE_CXX_FLAGS)

@lazylazypig
Copy link
Author

@alalek thanks for the quick reply. but following your advice, i failed again:(
i don't think it's a bug of used compiler, because i have tried to build a very simple example about std::exception_ptr with the same toolchain.cmake file:

#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>

void handle_eptr(std::exception_ptr eptr)
{
    try {
        if (eptr) {
            std::rethrow_exception(eptr);
        }
    } catch(const std::exception& e) {
        std::cout << "Caught exception \"" << e.what() << "\"\n";
    }
}
 
int main()
{
    std::exception_ptr eptr;
    try {
        std::string().at(1); // this generates an std::out_of_range
    } catch(...) {
        eptr = std::current_exception(); // capture
    }
    handle_eptr(eptr);
}

no errors occurred during build, and the built program run correctly on the target machine.
on the other hand, i found that the flags ENABLE_TBB and ENABLE_NEON can't be turned on at the same time (just as my original configuration). if I turned off either of them, the compiling of opencv was successful. I'm very confused.
thanks:)

@alalek
Copy link
Member

alalek commented Jul 4, 2018

Unfortunately we can't help on problems which we are not able to reproduce on our side (we don't have environment setup for this configuration).
But we can take a look on the clear reason of the problem and suggest some fix/workaround.

BTW, There two CMake lines seems wrong:

add_definitions(-DENABLE_NEON=ON)
add_definitions(-DENABLE_VFPV3=ON)

They should be CMake options (via set()), not for compiler.

Also take a look on OpenCV's cross-compiling GCC-based ARM toolchains here: https://github.com/opencv/opencv/tree/3.4/platforms/linux
We using them successfully on our CI: http://pullrequest.opencv.org/buildbot/waterfall?tag=arm

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Aug 5, 2018
OpenCV3 allows to disable the usage of std::exception_ptr:
opencv/opencv#11878 (comment)

Fixes
http://autobuild.buildroot.net/results/5ca/5ca221792c72c0a19f8b0e8303c0603d28f3c48e/

Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build/install question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org
Projects
None yet
Development

No branches or pull requests

2 participants