ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

cv_bridge and OpenCV both define Exception class

asked 2020-08-25 17:55:50 -0600

sterlingm gravatar image

updated 2020-08-25 17:56:17 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-08-28 12:59:09 -0600

sterlingm gravatar image

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:

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-08-25 17:55:50 -0600

Seen: 137 times

Last updated: Aug 28 '20