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

Confusion regarding visibility_control for static libraries for Windows #2747

Open
prnthp opened this issue Feb 14, 2025 · 0 comments
Open

Comments

@prnthp
Copy link

prnthp commented Feb 14, 2025

Looking at visibility_control.hpp (and all of these throughout the ROS2 codebase), it seems like it was never designed for static linkage on Windows. Say I don't have RCLCPP_BUILDING_LIBRARY in my preprocessor flags, RCLCPP_PUBLIC_TYPE will use __declspec(dllimport), which is probably not what you want during statically linking. Other libraries tend to just leave those defines blank --even the second example in the linked website in the header does that (https://gcc.gnu.org/wiki/Visibility).

Am I missing something fundamental here? C++ isn't my strong suite, but I'm trying to get static libraries instead of shared libraries/.dlls.

Thank you!

#ifndef RCLCPP__VISIBILITY_CONTROL_HPP_
#define RCLCPP__VISIBILITY_CONTROL_HPP_

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
//     https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
  #ifdef __GNUC__
    #define RCLCPP_EXPORT __attribute__ ((dllexport))
    #define RCLCPP_IMPORT __attribute__ ((dllimport))
  #else
    #define RCLCPP_EXPORT __declspec(dllexport)
    #define RCLCPP_IMPORT __declspec(dllimport)
  #endif
  #ifdef RCLCPP_BUILDING_LIBRARY
    #define RCLCPP_PUBLIC RCLCPP_EXPORT
  #else
    #define RCLCPP_PUBLIC RCLCPP_IMPORT
  #endif
  #define RCLCPP_PUBLIC_TYPE RCLCPP_PUBLIC
  #define RCLCPP_LOCAL
#else
  #define RCLCPP_EXPORT __attribute__ ((visibility("default")))
  #define RCLCPP_IMPORT
  #if __GNUC__ >= 4
    #define RCLCPP_PUBLIC __attribute__ ((visibility("default")))
    #define RCLCPP_LOCAL  __attribute__ ((visibility("hidden")))
  #else
    #define RCLCPP_PUBLIC
    #define RCLCPP_LOCAL
  #endif
  #define RCLCPP_PUBLIC_TYPE
#endif

#endif  // RCLCPP__VISIBILITY_CONTROL_HPP_
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

No branches or pull requests

1 participant