Skip to content

Conversation

KeaneWong
Copy link

@KeaneWong KeaneWong commented Feb 20, 2025

Description

Currently, the way that CMake creates the library files always generates .dylib files on Mac. Compilation will work fine, but attempting to import in any Python app will cause the import to fail, as the interpreter expects .so files for library files.
For some reason, using the flag
--cmake-args " -DCMAKE_SHARED_LIBRARY_SUFFIX=.so"
does not fix the issue. Additionally, setting the variable before the project() line in the CMakeLists also remains inneffective. So, the workaround is to add
set(CMAKE_SHARED_LIBRARY_SUFFIX .so)
right after the project() line.

@Mergifyio backports 2.1.x

Fixes #206

Contributor Checklist

  • Commit messages follow the project guidelines.
  • Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally
  • Changes are API compatible.
  • Applicable backports have been included in the description.

Reviewer Checklist

  • The PR has a milestone assigned.
  • The title and description correctly express the PR's purpose.
  • Check contributor checklist is correct.
  • Check CI results: changes do not issue any warning.
  • Check CI results: failing tests are unrelated with the changes.

@Danipiza Danipiza force-pushed the fix/mac-dylib-generation branch from 52c299e to a336102 Compare July 30, 2025 09:47
@Danipiza Danipiza changed the title Set CMAKE_SHARED_LIBRARY_SUFFIX to always create .so files. [#23543] Set CMAKE_SHARED_LIBRARY_SUFFIX to always create .so files. Jul 30, 2025
Comment on lines +29 to +41
if(NOT WIN32)
if(SHARED_LIBRARY_SUFFIX)
set(CMAKE_SHARED_LIBRARY_SUFFIX ".${SHARED_LIBRARY_SUFFIX}")
else()

# Default values for shared library suffix
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif()
endif()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

We decided to always change the value. No need of a user's cmake option.

Suggested change
if(NOT WIN32)
if(SHARED_LIBRARY_SUFFIX)
set(CMAKE_SHARED_LIBRARY_SUFFIX ".${SHARED_LIBRARY_SUFFIX}")
else()
# Default values for shared library suffix
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif()
endif()
endif()
if(NOT WIN32)
# Default values for shared library suffix in MacOS
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif()
endif()

@@ -41,6 +41,20 @@ find_package(fastdds 3 REQUIRED)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(NOT WIN32)
Copy link
Member

Choose a reason for hiding this comment

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

This CMakeLists are generated by fastddsgen. We need a PR to fastddsgen adding the code.

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.

FastDDS Python generates .dylib files instead of .so files on MacOS
3 participants