ddemidov / ev3dev-lang-cpp

C++ language bindings for http://ev3dev.org
MIT License
73 stars 38 forks source link

Multiple definitions of symbols when linking #66

Open alexdewar opened 3 years ago

alexdewar commented 3 years ago

I've found if I #include ev3dev stuff in separate compilation units then I get errors like this:

/usr/bin/ld: BoB/modules/robots/ev3/BoB/third_party/ev3dev-lang-cpp/libev3dev.a(ev3dev.cpp.o):(.rodata+0x370): multiple definition of `ev3dev::gyro_sensor::mode_gyro_ang'; BoB/modules/robots/ev3/libbob_robots__ev3.a(mindstorms_imu.cc.o):(.rodata._ZN6ev3dev11gyro_sensor13mode_gyro_angE[_ZN6ev3dev11gyro_sensor13mode_gyro_angE]+0x0): first defined here
/usr/bin/ld: BoB/modules/robots/ev3/BoB/third_party/ev3dev-lang-cpp/libev3dev.a(ev3dev.cpp.o):(.rodata+0x380): multiple definition of `ev3dev::gyro_sensor::mode_gyro_rate'; BoB/modules/robots/ev3/libbob_robots__ev3.a(mindstorms_imu.cc.o):(.rodata._ZN6ev3dev11gyro_sensor14mode_gyro_rateE[_ZN6ev3dev11gyro_sensor14mode_gyro_rateE]+0x0): first defined here
/usr/bin/ld: BoB/modules/robots/ev3/BoB/third_party/ev3dev-lang-cpp/libev3dev.a(ev3dev.cpp.o):(.rodata+0x3a0): multiple definition of `ev3dev::gyro_sensor::mode_gyro_g_a'; BoB/modules/robots/ev3/libbob_robots__ev3.a(mindstorms_imu.cc.o):(.rodata._ZN6ev3dev11gyro_sensor13mode_gyro_g_aE[_ZN6ev3dev11gyro_sensor13mode_gyro_g_aE]+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mindstorms_imu.dir/build.make:103: mindstorms_imu] Error 1
make[1]: *** [CMakeFiles/Makefile2:209: CMakeFiles/mindstorms_imu.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

This can be worked around by passing --allow-multiple-definition to the linker, but this is a hack. I suspect the real problem lies in some symbols not properly being marked inline (or their definitions being put separately into a .cpp file).

I'm using gcc v11 on Arch Linux.

ddemidov commented 3 years ago

Would b8a4c90 solve this for you?