AprilRobotics / apriltag

AprilTag is a visual fiducial system popular for robotics research.
https://april.eecs.umich.edu/software/apriltag
Other
1.61k stars 539 forks source link

Compiling fails because of LTO mismatch error when using non-default gcc version #227

Closed AlexReimann closed 2 years ago

AlexReimann commented 2 years ago

Describe the bug When switching the system default gcc version, e. g. upgrading to gcc 9 on Ubuntu 18.04, the compiling fails with following error:

lto1: fatal error: bytecode stream in file ‘apriltag_pywrap.o’ generated with LTO version 8.1 instead of the expected 6.2
compilation terminated.
lto-wrapper: fatal error: x86_64-linux-gnu-gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [apriltag.cpython-36m-x86_64-linux-gnu.so] Error 1
make[1]: *** [CMakeFiles/apriltag_python.dir/all] Error 2
make: *** [all] Error 2

To Reproduce

Operating Sytem Tested on Ubuntu 18.04 using gcc 9.4

Code version Current github HEAD

Additional context The issue is that LTO is activated, which requires that the same LTO versions are used of the linked libraries. The system libraries are build with the system default compiler, which in this case comes with an older LTO version.

LTO is activated because all the python C build flags are simply copied over and used in this line: https://github.com/AprilRobotics/apriltag/blob/bee5efb1cc263ec1459bca46193e3428220d52ba/CMakeLists.txt#L150

This includes the -ftlo flag to activate LTO. Manually copying the flags and removing then the -flto flag resolves the issue for me.

AlexReimann commented 2 years ago

Fixed with #228