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

error C2491 "definition of dllimport function not allowed" on downstream package on Windows when compiled with BUILD_SHARED_LIBS set to OFF #1

Closed
traversaro opened this issue Jun 13, 2022 · 10 comments

Comments

@traversaro
Copy link
Member

traversaro commented Jun 13, 2022

I tried to migrate of a simple ROS2 package from RoboStack's Galactic (where it was working) to Humble (where the Windows build is not working).

The PR is robotology/yarp-devices-ros2#31 and the code is https://github.com/robotology-playground/yarp-ros2/blob/4ae984d11428491ea0b7c61162707cf49836897a/ros2_interfaces_ws/src/map2d_nws_ros2_msgs/CMakeLists.txt, on Humble macOS and Linux are working but windows is failing with:

2022-06-13T07:23:12.5560863Z   Building Custom Rule D:/a/yarp-ros2/yarp-ros2/ros2_interfaces_ws/src/map2d_nws_ros2_msgs/CMakeLists.txt
2022-06-13T07:23:12.6743586Z   get_map_by_name__type_support.cpp
2022-06-13T07:23:13.0765930Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(34,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::cdr_serialize': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0795019Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(45,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::cdr_deserialize': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0799494Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(57,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::get_serialized_size': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0804346Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(79,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::max_serialized_size_GetMapByName_Request': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0891238Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(190,134): warning C4273: 'rosidl_typesupport_fastrtps_cpp__get_message_type_support_handle__map2d_nws_ros2_msgs__srv__GetMapByName_Request': inconsistent dll linkage [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0893518Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs/srv/detail/get_map_by_name__rosidl_typesupport_fastrtps_cpp.hpp(74,3): message : see previous definition of 'rosidl_typesupport_fastrtps_cpp__get_message_type_support_handle__map2d_nws_ros2_msgs__srv__GetMapByName_Request' [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0895571Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(258,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::cdr_serialize': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0898227Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(271,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::cdr_deserialize': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0902110Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(284,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::get_serialized_size': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0904937Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(307,1): error C2491: 'map2d_nws_ros2_msgs::srv::typesupport_fastrtps_cpp::max_serialized_size_GetMapByName_Response': definition of dllimport function not allowed [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0915119Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(421,135): warning C4273: 'rosidl_typesupport_fastrtps_cpp__get_message_type_support_handle__map2d_nws_ros2_msgs__srv__GetMapByName_Response': inconsistent dll linkage [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0917017Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs/srv/detail/get_map_by_name__rosidl_typesupport_fastrtps_cpp.hpp(151,3): message : see previous definition of 'rosidl_typesupport_fastrtps_cpp__get_message_type_support_handle__map2d_nws_ros2_msgs__srv__GetMapByName_Response' [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0929394Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs\srv\detail\dds_fastrtps\get_map_by_name__type_support.cpp(482,126): warning C4273: 'rosidl_typesupport_fastrtps_cpp__get_service_type_support_handle__map2d_nws_ros2_msgs__srv__GetMapByName': inconsistent dll linkage [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
2022-06-13T07:23:13.0932847Z D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\rosidl_typesupport_fastrtps_cpp\map2d_nws_ros2_msgs/srv/detail/get_map_by_name__rosidl_typesupport_fastrtps_cpp.hpp(171,3): message : see previous definition of 'rosidl_typesupport_fastrtps_cpp__get_service_type_support_handle__map2d_nws_ros2_msgs__srv__GetMapByName' [D:\a\yarp-ros2\yarp-ros2\build\ros2_interfaces_ws\src\map2d_nws_ros2_msgs\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.vcxproj]
@wolfv
Copy link
Member

wolfv commented Jun 13, 2022

Hmm, strange. I didn't see this kind of issue when building any of the native message packages... Could there be some boilerplate CMake missing?

@traversaro
Copy link
Member Author

Could this workaround be the problem? https://github.com/robotology-playground/yarp-ros2/blob/4ae984d11428491ea0b7c61162707cf49836897a/ros2_interfaces_ws/src/map2d_nws_ros2_msgs/CMakeLists.txt#L51-L54

I think this is unrelated, the problem happens even if you comment out that part.

To investigate the problem, I compared ros-galactic vs ros-humble, comparing the exact invocation of the compilation of the failing compilation unit:

Working:
  "command": "C:\\PROGRA~2\\MIB055~1\\2019\\ENTERP~1\\VC\\Tools\\MSVC\\1429~1.301\\bin\\Hostx64\\x64\\cl.exe  /nologo /TP -DFASTCDR_DYN_LINK -DFASTRTPS_DYN_LINK -DROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL_map2d_nws_ros2_msgs -DROS_PACKAGE_NAME=\\\"map2d_nws_ros2_msgs\\\" -IC:\\src\\yarp-ros2\\buildgalactic\\ros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\rosidl_generator_cpp -IC:\\src\\yarp-ros2\\buildgalactic\\ros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\rosidl_typesupport_fastrtps_cpp -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarpgalactic\\Library\\include -external:W0    /DWIN32 /D_WINDOWS /GR /EHsc /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /O2 /Ob2 /DNDEBUG /W4 /w34101 /w34555 /w34189 /w35038 /w34715 -std:c++14 /Foros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\CMakeFiles\\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.dir\\c93e36ceeabcb03fe94ad1ea268bccde\\srv\\detail\\dds_fastrtps\\get_map_by_name__type_support.cpp.obj /FdTARGET_COMPILE_PDB /FS -c C:\\src\\yarp-ros2\\buildgalactic\\ros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\rosidl_typesupport_fastrtps_cpp\\map2d_nws_ros2_msgs\\srv\\detail\\dds_fastrtps\\get_map_by_name__type_support.cpp",
Not Working:
  "command": "C:\\PROGRA~2\\MIB055~1\\2019\\ENTERP~1\\VC\\Tools\\MSVC\\1429~1.301\\bin\\Hostx64\\x64\\cl.exe  /nologo /TP -DFASTCDR_DYN_LINK -DROS_PACKAGE_NAME=\\\"map2d_nws_ros2_msgs\\\" -D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING -IC:\\src\\yarp-ros2\\buildhumble\\ros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\rosidl_typesupport_fastrtps_cpp -IC:\\src\\yarp-ros2\\buildhumble\\ros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\rosidl_generator_cpp -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\rmw -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\rcutils -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\rosidl_runtime_c -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\rosidl_typesupport_interface -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\rosidl_runtime_cpp -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\rosidl_typesupport_fastrtps_cpp -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\nav_msgs -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\builtin_interfaces -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\geometry_msgs -external:IC:\\Users\\STraversaro\\AppData\\Local\\mambaforge\\envs\\yarphumble\\Library\\include\\std_msgs -external:W0    /DWIN32 /D_WINDOWS /GR /EHsc /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /O2 /Ob2 /DNDEBUG /W4 -std:c++14 /Foros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\CMakeFiles\\map2d_nws_ros2_msgs__rosidl_typesupport_fastrtps_cpp.dir\\c93e36ceeabcb03fe94ad1ea268bccde\\srv\\detail\\dds_fastrtps\\get_map_by_name__type_support.cpp.obj /FdTARGET_COMPILE_PDB /FS -c C:\\src\\yarp-ros2\\buildhumble\\ros2_interfaces_ws\\src\\map2d_nws_ros2_msgs\\rosidl_typesupport_fastrtps_cpp\\map2d_nws_ros2_msgs\\srv\\detail\\dds_fastrtps\\get_map_by_name__type_support.cpp",

The main difference is that in the galactic version -DROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL_map2d_nws_ros2_msgs is defined, while it is not defined in Humble.

@traversaro
Copy link
Member Author

Manually changing the related code to the Galactic version makes the library work, so I think that indeed it is a regression due to ros2/rosidl_typesupport_fastrtps#87 .

@traversaro
Copy link
Member Author

Ok, I understood the problem, and it will probably take a bit of time for describing it and opening appropriate issue in the related repositories. However, the good news is that it occurs only if you compile a repo with BUILD_SHARED_LIBS set to OFF, if you set BUILD_SHARED_LIBS set to ON everything works fine.

@traversaro traversaro changed the title error C2491 "definition of dllimport function not allowed" on downstream package on Windows error C2491 "definition of dllimport function not allowed" on downstream package on Windows when compiled with BUILD_SHARED_LIBS set to OFF Jun 28, 2022
@Tobias-Fischer
Copy link
Contributor

Ah.. shouldn't we always build shared libs in our case?

@traversaro
Copy link
Member Author

Ah.. shouldn't we always build shared libs in our case?

Yes, the problem is that the downstream repo (i.e. https://github.com/robotology-playground/yarp-ros2) was hardcoding BUILD_SHARED_LIBS to OFF, not a problem of our packages. Indeed, I think the issue is not related to robostack packaging at all, but I would leave it open until I open an appropraite issue upstream.

@Tobias-Fischer
Copy link
Contributor

I think we can close this now that an upstream issue was created: ros2/rosidl_typesupport_fastrtps#90

@traversaro
Copy link
Member Author

Sure, thanks for closing. I forgot close it myself after opening the issue upstream.

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

3 participants