COVESA/dlt-daemon

unit test error : linker command failed with exit code 1

Closed this issue · 2 comments

Hello,

If turn off the BUILD_SHARED_LIBS option and enable the WITH_DLT_UNIT_TESTS option, some test codes will experience build errors.

Command:

cmake -DWITH_DLT_UNIT_TESTS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../
make 

error:

[ 93%] Linking CXX executable gtest_dlt_daemon_event_handler
/usr/bin/ld: ../src/daemon/libdlt_daemon.a(dlt-daemon.c.o): in function `main':
/root/1/dlt-daemon/src/daemon/dlt-daemon.c:1122: multiple definition of `main'; CMakeFiles/gtest_dlt_daemon_event_handler.dir/gtest_dlt_daemon_event_handler.cpp.o:/root/1/dlt-daemon/tests/gtest_dlt_daemon_event_handler.cpp:698: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tests/CMakeFiles/gtest_dlt_daemon_event_handler.dir/build.make:101: tests/gtest_dlt_daemon_event_handler] Error 1
make[1]: *** [CMakeFiles/Makefile2:1402: tests/CMakeFiles/gtest_dlt_daemon_event_handler.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 94%] Linking CXX executable gtest_dlt_daemon_gateway
/usr/bin/ld: ../src/daemon/libdlt_daemon.a(dlt-daemon.c.o): in function `main':
/root/1/dlt-daemon/src/daemon/dlt-daemon.c:1122: multiple definition of `main'; CMakeFiles/gtest_dlt_daemon_gateway.dir/gtest_dlt_daemon_gateway.cpp.o:/root/1/dlt-daemon/tests/gtest_dlt_daemon_gateway.cpp:739: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tests/CMakeFiles/gtest_dlt_daemon_gateway.dir/build.make:101: tests/gtest_dlt_daemon_gateway] Error 1
make[1]: *** [CMakeFiles/Makefile2:1350: tests/CMakeFiles/gtest_dlt_daemon_gateway.dir/all] Error 2
[ 95%] Linking CXX executable gtest_dlt_logd_converter
[ 95%] Built target gtest_dlt_logd_converter
[ 96%] Linking CXX executable dlt_env_ll_unit_test
[ 96%] Built target dlt_env_ll_unit_test
[ 97%] Linking CXX executable gtest_dlt_daemon_common
[ 97%] Built target gtest_dlt_daemon_common
[ 98%] Linking CXX executable gtest_dlt_daemon_offline_log
/usr/bin/ld: ../src/daemon/libdlt_daemon.a(dlt-daemon.c.o): in function `main':
/root/1/dlt-daemon/src/daemon/dlt-daemon.c:1122: multiple definition of `main'; CMakeFiles/gtest_dlt_daemon_offline_log.dir/gtest_dlt_daemon_offline_log.cpp.o:/root/1/dlt-daemon/tests/gtest_dlt_daemon_offline_log.cpp:2256: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tests/CMakeFiles/gtest_dlt_daemon_offline_log.dir/build.make:101: tests/gtest_dlt_daemon_offline_log] Error 1
make[1]: *** [CMakeFiles/Makefile2:1376: tests/CMakeFiles/gtest_dlt_daemon_offline_log.dir/all] Error 2

Thanks.

Hello @vsecv
thanks for this report.
I checked in my local and seem it a real issue with static compilation.
Will you propose a fix for this?
I would love to review then.
Thank you

Hello @vsecv,

When you disable BUILD_SHARED_LIBS, the component will build static libraries

The error shows that some gtest of dlt file have two main functions(including main of dlt-daemon and itself).

I recommend that you should not set BUILD_SHARED_LIBS to FALSE when enabling gtest of dlt to avoid getting error

@minminlittleshrimp you can close this issue now