sick_scan_base icon indicating copy to clipboard operation
sick_scan_base copied to clipboard

Redefinition problems when trying to use 'sick_scan_base' for other libs.

Open ceezous opened this issue 3 years ago • 4 comments

Description:

I was trying to encapsulate sick_scan_base for my own lib which uses SickTim561. I modified 'CMakeLists.txt' for compilation and installing and everything works fine. However, when i tried '#include <sick_scan/sick_generic_laser.h>', some redefinition errors happen.

Error messages:

1>libboost_system-vc141-mt-x32-1_68.lib(error_code.obj) : error LNK2005: "public: virtual class boost::system::error_condition __thiscall boost::system::detail::system_error_category::default_error_condition(int)const " (?default_error_condition@system_error_category@detail@system@boost@@UBE?AVerror_condition@34@H@Z) already defined in sick_scan.lib(rossimu.obj)

1>libboost_system-vc141-mt-x32-1_68.lib(error_code.obj) : error LNK2005: "public: virtual class std::basic_string<char,struct std::char_traits,class std::allocator > __thiscall boost::system::detail::generic_error_category::message(int)const " (?message@generic_error_category@detail@system@boost@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in sick_scan.lib(rossimu.obj)

1>libboost_system-vc141-mt-x32-1_68.lib(error_code.obj) : error LNK2005: "public: virtual class std::basic_string<char,struct std::char_traits,class std::allocator > __thiscall boost::system::detail::system_error_category::message(int)const " (?message@system_error_category@detail@system@boost@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in sick_scan.lib(rossimu.obj)

1>D:\visionnav-libraries\ForkingPerceptionModule2D\out\build32\bin\RelWithDebInfo\LaserDriver.dll : fatal error LNK1169: one or more multiply defined symbols found

Trials:

I tried everything I could come up, including adding "#ifndef #define #endif", but none helped. And I looked up the source code and found some functions may be the source of problems. The functions are like: void ros::init(int &, char * *, class std::basic_string<char, struct std::char_traits, class std::allocator > const &, unsigned int) { Time::init(); } But I still can't figure out how to solve this problem.

ceezous avatar Dec 23 '21 07:12 ceezous

Thanks for reporting. Since all messages are linker errors, I guess that both sick_scan.lib and other libs/executables are linked against boost libraries. This way symbols defined in the boost library may be defined in other libs, too. If possible, try to link boost libraries only once in your executable (i.e. do not link libraries against boost except the main executable).

Alternatively, you can link with option /FORCE, which forces a link to complete even with unresolved symbols or symbols defined more than once.

Another alternative is to switch to sick_scan_xd, see https://github.com/SICKAG/sick_scan_xd for details. This driver has no boost dependencies and supports both Linux and Windows with or without ROS.

rostest avatar Dec 23 '21 09:12 rostest

Visual Studio 2019 is recommended for the Windows build. If you're using Visual Studio 2017 (which "libboost_system-vc141" suggests), try upgrading to Visual Studio 2019.

rostest avatar Dec 23 '21 10:12 rostest

Visual Studio 2019 is recommended for the Windows build. If you're using Visual Studio 2017 (which "libboost_system-vc141" suggests), try upgrading to Visual Studio 2019.

Thank you for your replay. I am using VS 2019 and this "libboost_system-vc141" is a prebuilt lib which is installed from PCL(PCL itself has a boost-1.68 library build by VS 2017.) In fact, when building sick_scan_base, I linked boost-1.68-vc141, and boost-1.78-vc142 for my own lib.

Anyway, I'll try using boost-1.78 built by VS2019 and see if the problem will be solved.

ceezous avatar Dec 24 '21 01:12 ceezous

It works. I applied both libs(personal lib and sick_scan_base) with boost 1.68, and the exact problem seems to be solved.

ceezous avatar Dec 25 '21 06:12 ceezous