Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows Compatibility Fixes for vision_opencv Build #538

Open
wants to merge 2 commits into
base: humble
Choose a base branch
from

Conversation

SENAI-GilmarCorreia
Copy link

@SENAI-GilmarCorreia SENAI-GilmarCorreia commented Oct 31, 2024

Summary

This PR adds compatibility improvements to enable successful building of vision_opencv on Windows by introducing additional compiler options.

Changes Made

  1. Added Compiler Definitions for Windows Compatibility:

    • Added -DHAVE_SNPRINTF to add_compile_options to ensure that the snprintf function is available during compilation. This is a common requirement when building cross-platform code on Windows.
  2. Boost Python Library Static Linking on Windows:

    • For MSVC (Microsoft Visual C++), target_compile_definitions was updated with -DBOOST_PYTHON_STATIC_LIB. This option helps to statically link the Boost Python library, which is necessary for compatibility on Windows.

Rationale

These changes are specifically intended as a workaround to address issues encountered when building vision_opencv on Windows. By adding the snprintf definition and setting Boost Python for static linking, this PR aims to resolve common build issues related to cross-platform support.

Additional Notes

  • This PR only affects Windows builds and should not impact Linux-based systems.
  • These adjustments were tested on Windows using MSVC, and the build completed successfully after these changes.

Resolves: #401

Copy link
Member

@ijnek ijnek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR! Sorry it took me a while to get back - please check the feedback.

@@ -90,3 +92,7 @@ install(TARGETS ${PROJECT_NAME}
ament_package(
CONFIG_EXTRAS "cmake/cv_bridge-extras.cmake.in"
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to line 41 in src/CMakeLists.txt.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my tests I can only move after line 64. That works?

@@ -12,6 +12,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra)
endif()

add_compile_options(-DHAVE_SNPRINTF)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is to treat the following warning:

warning C4996: '_vsnprintf': This function or variable may be unsafe. Consider using _vsnprintf_s instead.

Could you please replace the vnsprintf calls with vsnprintf_s instead of adding this compile option?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error that I trying to solve was that:

C:/boost/boost/assert/source_location.hpp(95,9): error C2039: '_snprintf': is not a member of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module_opencv3.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\string(24): message: see declaration of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module_opencv3.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:/boost/boost/assert/source_location.hpp(95,9): error C2039: '_snprintf': is not a member of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\string(24): message: see declaration of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:/boost/boost/assert/source_location.hpp(102,13): error C2039: '_snprintf': is not a member of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module_opencv3.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\string(24): message: see declaration of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module_opencv3.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:/boost/boost/assert/source_location.hpp(102,13): error C2039: '_snprintf': is not a member of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\string(24): message: see declaration of 'std' (compiling source file <ANONYMIZED_PATH>/src/vision_opencv/cv_bridge/src/module.cpp) [<ANONYMIZED_PATH>/build/cv_bridge/src/cv_bridge_boost.vcxproj]

I can only solve this using -DHAVE_SNPRINTF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants