Reputation: 1813
I read through nearly every library linking tutorial but none worked for my specific problem.
I have a folder called VSCOM_API_TEST with these files and folders in it:
VSCOM_API_TEST/CMakeLists.txt
VSCOM_API_TEST/include/vs_can_api.h
VSCOM_API_TEST/include/startup.h
VSCOM_API_TEST/lib/libvs_can_api.so
VSCOM_API_TEST/lib/libvs_can_api.a
VSCOM_API_TEST/src/startup.cpp
startup is my executable where I want to include the library.
And I have the problem that my programme can't find the library functions:
CMakeFiles/startup.dir/src/startup.o: In function main:
/home/max/fuerte_workspace/sandbox/VSCOM_API_TEST/src/startup.cpp:6: undefined reference to VSCAN_Open
CMakeLists.txt
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#common commands for building c++ executables and libraries
rosbuild_add_library(${PROJECT_NAME} lib/libvs_can_api.a)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
rosbuild_add_executable(startup src/startup.cpp)
#target_link_libraries(startup ${PROJECT_NAME})
startup.cpp
// ROS includes
#include <ros/ros.h>
#include <vs_can_api.h>
int main(int argc, char** argv)
{
VSCAN_HANDLE handle = VSCAN_Open("192.168.5.10:23", VSCAN_MODE_NORMAL);
VSCAN_API_VERSION *version;
VSCAN_STATUS status;
VSCAN_HWPARAM *hwParams;
// API Version
status = VSCAN_Ioctl(handle, VSCAN_IOCTL_GET_API_VERSION, &version);
//HW Version
status = VSCAN_Ioctl(handle, VSCAN_IOCTL_GET_HWPARAM, &hwParams);
}
So how can I add a precompiled library?
Upvotes: 0
Views: 4431
Reputation: 78320
I'm not familiar with rosbuild at all, but the following points might help:
set(EXECUTABLE/LIBRARY_ ...)
lines.rosbuild_add_library
is a wrapper round CMake's add_library
command and is not intended to be used in conjunction with a compiled library. Instead it would be used to define the sources needed to create a library. This line should be deleted too.LINKER_LANGUAGE
to C
is probably unnecessary, and should probably be CXX
anyway.target_link_libraries
is the command you want to use to link to the compiled library. However, you'll need to provide the full path to the library as the second argument.So (without having tested it) I'd suggest you try the following CMakelists.txt
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
rosbuild_add_executable(startup src/startup.cpp)
target_link_libraries(startup ${CMAKE_CURRENT_LIST_DIR}/lib/libvs_can_api.a)
Upvotes: 1