Skip to content

Fix multiple sdtlib linkage warning on Windows with MSVS.#22566

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
asmorkalov:as/libjpeg_turbo_linkage_warning
Sep 28, 2022
Merged

Fix multiple sdtlib linkage warning on Windows with MSVS.#22566
asmorkalov merged 1 commit intoopencv:4.xfrom
asmorkalov:as/libjpeg_turbo_linkage_warning

Conversation

@asmorkalov
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov commented Sep 26, 2022

Use global OpenCV settings for MS Visual Studio run-time libraries to prevent collision:

LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [C:\build\precommit_windows64\build\modules\imgcodecs\opencv_imgcodecs.vcxproj]

The regression was introduced in #22372

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

@asmorkalov asmorkalov added this to the 4.7.0 milestone Sep 26, 2022
@asmorkalov asmorkalov requested a review from alalek September 26, 2022 09:28
@asmorkalov
Copy link
Copy Markdown
Contributor Author

/cc @ocpalo

@ocpalo
Copy link
Copy Markdown
Collaborator

ocpalo commented Sep 26, 2022

I borrowed these lines from the upstream. If this pull request fixes the warnings, then we can delete the following lines too.

  option(WITH_CRT_DLL
    "Link all ${CMAKE_PROJECT_NAME} libraries and executables with the C run-time DLL (msvcr*.dll) instead of the static C run-time library (libcmt*.lib.)  The default is to use the C run-time DLL only with the libraries and executables that need it."
    TRUE)
  if(NOT WITH_CRT_DLL)
    # Use the static C library for all build types
    foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
      if(${var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
      endif()
    endforeach()
  endif()

Because this option is not visible to user. I believe for the MSVC only the following line is enough.

  add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)

And I do not have access to any Windows machine. Unfortunately, I can`t test it.

Use global OpenCV settings for MS Visual Studio run-time libraries to prevent colision.
@asmorkalov asmorkalov force-pushed the as/libjpeg_turbo_linkage_warning branch from e2c61b4 to 64649a1 Compare September 27, 2022 11:15
@asmorkalov
Copy link
Copy Markdown
Contributor Author

@alalek The PR is ready for review.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@asmorkalov asmorkalov merged commit 935acc5 into opencv:4.x Sep 28, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants