Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@thiru31
Copy link
Contributor

@thiru31 thiru31 commented Jun 29, 2024

Added a definition for M_PI in the code to resolve a compilation error encountered when building OpenCV on the MSYS2 environment. The M_PI constant was not defined, causing the compilation to fail.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@Kumataro
Copy link
Contributor

Hello, my sample CMakeList.txt has not been tested, so if there are some build error, I'm sorry.


M_PI is not a part of C++(and C) Standard. See https://stackoverflow.com/questions/51344013/m-pi-imprecision

(I know this is only armchair theory, not reality.)
For example, if someone uses compiler that has -DM_PI=42, this fix will not works well.

Instead of definiton M_PI in user source code, we can use M_PI, with "_USE_MATH_DEFINES` definition.

https://github.com/opencv/opencv/blob/4.x/3rdparty/carotene/CMakeLists.txt

      endif()
  endif()

+ if(MINGW) # TODO: What condition is better ?
+    target_compile_definitions(carotene_objs PRIVATE "-D_USE_MATH_DEFINES=1")
+ endif()

  # we add dummy file to fix XCode build
  add_library(carotene STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} "$<TARGET_OBJECTS:carotene_objs>" 
  "${CAROTENE_SOURCE_DIR}/dummy.cpp")

Or Add #define _USE_MATH_DEFINES before #include <cmath> in phase.cpp

Added a definition for M_PI in the code to resolve a compilation error encountered when building OpenCV on the MSYS2 environment. The M_PI constant was not defined, causing the compilation to fail.
@thiru31
Copy link
Contributor Author

thiru31 commented Jun 30, 2024

@Kumataro I have updated the PR to use _USE_MATH_DEFINES as suggested, by adding the following to CMakeLists.txt:

if(MINGW)
    target_compile_definitions(carotene_objs PRIVATE "-D_USE_MATH_DEFINES=1")
endif()

I have compiled and tested this change on my local ARM machine, and it resolves the compilation issue successfully.

Please review the changes and let me know if any further adjustments are needed. Thank you!

@Kumataro
Copy link
Contributor

I think the new patch is preferable as it limits the impact to the MINGW environment only.
Thank you very much !

@asmorkalov asmorkalov added category: build/install platform: win32 platform: arm ARM boards related issues: RPi, NVIDIA TK/TX, etc labels Jul 1, 2024
@asmorkalov asmorkalov self-requested a review July 1, 2024 07:32
@asmorkalov asmorkalov merged commit 930af15 into opencv:4.x Jul 1, 2024
@asmorkalov asmorkalov mentioned this pull request Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: build/install platform: arm ARM boards related issues: RPi, NVIDIA TK/TX, etc platform: win32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants