Skip to content

Define _USE_MATH_DEFINES for each target that links control_toolbox on WIN32#616

Merged
christophfroehlich merged 1 commit into
ros-controls:masterfrom
traversaro:patch-1
May 29, 2026
Merged

Define _USE_MATH_DEFINES for each target that links control_toolbox on WIN32#616
christophfroehlich merged 1 commit into
ros-controls:masterfrom
traversaro:patch-1

Conversation

@traversaro
Copy link
Copy Markdown
Contributor

Fixes downstream compilation problems on Windows.

M_PI is used in public headers in

-1.0 / sampling_frequency * (2.0 * M_PI * damping_frequency) /
, so we need to ensure that _USE_MATH_DEFINES is always defined also for downstream compilation units that include control_toolbox/low_pass_filter.hpp. This can be done by setting as PUBLIC target_compile_definitions _USE_MATH_DEFINES.

This fixes errors like:

 │ │ %PREFIX%\Library\include\control_toolbox\control_toolbox\low_pass_filter.hpp(117,42): error C2065: 'M_PI': undeclared identifier [%SRC_DIR%\build\gz_custom_hardware_plugins.vcxproj]
 │ │   (compiling source file '../ros-jazzy-gz-ros2-control-demos/src/work/src/gz_custom_system.cpp')
 │ │       %PREFIX%\Library\include\control_toolbox\control_toolbox\low_pass_filter.hpp(117,42):
 │ │       the template instantiation context (the oldest one first) is
 │ │           %SRC_DIR%\ros-jazzy-gz-ros2-control-demos\src\work\src\gz_custom_system.cpp(266,34):
 │ │           see reference to class template instantiation 'control_toolbox::LowPassFilter<double>' being compiled
 │ │           %PREFIX%\Library\include\control_toolbox\control_toolbox\low_pass_filter.hpp(114,8):
 │ │           while compiling class template member function 'void control_toolbox::LowPassFilter<double>::set_params(double,double,double)'
 │ │               %PREFIX%\Library\include\control_toolbox\control_toolbox\low_pass_filter.hpp(85,15):
 │ │               see the first reference to 'control_toolbox::LowPassFilter<double>::set_params' in 'control_toolbox::LowPassFilter<double>::LowPassFilter'
 │ │               C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\include\memory(3630,5):
 │ │               see the first reference to 'control_toolbox::LowPassFilter<double>::LowPassFilter' in 'std::make_unique'
 │ │   
 │ │ %SRC_DIR%\build>if errorlevel 1 exit 1

see RoboStack/ros-jazzy#212 (comment) .

Is this user-facing behavior change?

No.

Did you use Generative AI?

Surprisingly no.

Additional Information

None.

TODOs

To send us a pull request, please:

  • Fork the repository.
  • Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
  • Ensure local tests pass. (colcon test and pre-commit run (requires you to install pre-commit by pip3 install pre-commit)
  • Commit to your fork using clear commit messages.
  • Send a pull request, answering any default questions in the pull request interface.
  • Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.61%. Comparing base (588fd7c) to head (934aa70).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #616      +/-   ##
==========================================
- Coverage   83.90%   83.61%   -0.30%     
==========================================
  Files          30       31       +1     
  Lines        2100     2203     +103     
  Branches      112      128      +16     
==========================================
+ Hits         1762     1842      +80     
- Misses        268      277       +9     
- Partials       70       84      +14     
Flag Coverage Δ
unittests 83.61% <ø> (-0.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

LGTM

@traversaro
Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-humble Triggers PR backport to ROS 2 humble. backport-jazzy Triggers PR backport to ROS 2 jazzy. backport-kilted Triggers PR backport to ROS 2 kilted.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants