ROS2 Windows can't add dependency, fatal error LNK1107: invalid or corrupt file
I am trying to use the ctre phoenix c++ library. This worked fine when using catkin in Ubuntu, but I recently made the switch to ROS2 and am developing in windows, and now I get this error:
hello.cpp
hello.obj : error LNK2019: unresolved external symbol "int __cdecl ctre::phoenix::platform::can::SetCANInterface(char const *)" (?SetCANInterface@can@platform@phoenix@ctre@@YAHPEBD@Z) referenced in function main [F:\dev\colcon_ws\build\lunabotics2021\hello.vcxproj]
F:\dev\colcon_ws\src\lunabotics2021\lib\x86-64\libCTRE_Phoenix.a : fatal error LNK1107: invalid or corrupt file: cannot read at 0x56FF0 [F:\dev\colcon_ws\build\lunabotics2021\hello.vcxproj]
listen.cpp
listen.vcxproj -> F:\dev\colcon_ws\build\lunabotics2021\Release\listen.exe
Failed <<< lunabotics2021 [21.2s, exited with code 1]
---
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(lunabotics2021)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
#set(phoenix_DIR "F:/dev/colcon_ws/src/lunabotics2021/include/ctre")
#////////////////////////////////////////////////////////////////
# STEP 1: ADD DEPENDENCIES///////////////////////////////////////
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
#find_package(phoenix REQUIRED)
# STEP 2: ADD EXECUTABLE AND AMENT DEPENDENCIES/////////////////
add_executable(hello src/hello.cpp)
ament_target_dependencies(hello rclcpp std_msgs)
add_executable(listen src/listen.cpp)
ament_target_dependencies(listen rclcpp std_msgs)
target_include_directories(hello PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE::include>)
target_include_directories(listen PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE::include>)
# STEP 3: ADD INSTALL///////////////////////////////////////////
install(TARGETS hello DESTINATION lib/${PROJECT_NAME})
install(TARGETS listen DESTINATION lib/${PROJECT_NAME})
#////////////////////////////////////////////////////////////////
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
target_link_libraries(hello F:/dev/colcon_ws/src/lunabotics2021/lib/x86-64/libCTRE_Phoenix.a)
target_link_libraries(hello F:/dev/colcon_ws/src/lunabotics2021/lib/x86-64/libCTRE_PhoenixCanutils.a)
target_link_libraries(hello F:/dev/colcon_ws/src/lunabotics2021/lib/x86-64/libCTRE_PhoenixCCI.a)
target_link_libraries(hello F:/dev/colcon_ws/src/lunabotics2021/lib/x86-64/libCTRE_PhoenixPlatformLinuxSocketCan.a)
ament_package()
Any ideas what is wrong, or is there a better way to be doing this?
@JoelB, it looks like you acquired the libraries from this repository. Those are Linux specific libraries and not binary compatible with Windows system. I'd recommend to contact the repository owner on GitHub and see if they have the Windows equivalent ones for your development.