0
$\begingroup$

Rosanswers logo

I am trying to use cv_bridge in my project on Windows 10 using Visual Studio 2017. When I try to compile my code, I get the following errors:

Error   LNK2005 "public: __cdecl std::exception::exception(class std::exception const &)" (??0exception@std@@QEAA@AEBV01@@Z) already defined in cv_bridge.lib(cv_bridge.dll) my_project_name    C:\my_project_path\MSVCRTD.lib(throw_bad_alloc.obj) 

Error   LNK2005 "public: virtual char const * __cdecl std::exception::what(void)const " (?what@exception@std@@UEBAPEBDXZ) already defined in cv_bridge.lib(cv_bridge.dll) my_project_name   C:\my_project_path\MSVCRTD.lib(throw_bad_alloc.obj) 

because both cv_bridge.h and opencv2/core.hpp define a class called Exception. I have to link OpenCV in order to link with cv_bridge so I'm not sure how to get around this issue other than commenting the class out in cv_bridge.hand rebuilding cv_bridge from source, but I've used cv_bridge when building catkin packages in Ubuntu and never ran into this problem so I'm hesitant to rebuild it.

I am not creating a ROS package in this case - I am building a DLL to call in Unity+ROS#. Maybe the ROS build scripts are able to handle this issue and Visual Studio cannot?

Is this just some issue with my project settings in VS17? Or will I need to rebuild cv_bridge for this project? Or something else?


Originally posted by sterlingm on ROS Answers with karma: 380 on 2020-08-25

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Actually this is not a conflict between cv_bridge and OpenCV because they use different namespaces.

This was some conflict between cv_bridge and MSVCRT. I'm not sure this is the best solution, but what worked for me was to declare the /FORCE:MULTIPLE option in the Linker command line options, as suggested by this link: https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk1169?view=vs-2019

None of the options for the CRT under C/C++->Code Generation fixed the issue so I went with the /FORCE:MULTIPLE option.


Originally posted by sterlingm with karma: 380 on 2020-08-28

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.