I created a cmake file for libgps (cmake File). This worked fine, and the libgps.a/libgps.so(tryed both) will be placed in /usr/local/lib. When I try to use this library I get the cmake message, that the library was not found. What can I check to find out why it does not work?
Here the cmake code for libgps:
cmake_minimum_required(VERSION 2.6)
set(PROJECT_NAME position_logger)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../RPiToolchainCmake/toolchain-rpi.cmake) # must be before project()
project(${PROJECT_NAME})
add_library(gps STATIC "")
#add_library(gps SHARED "")
target_link_libraries(gps m)
target_include_directories(gps PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_sources(gps PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/gps.h
${CMAKE_CURRENT_SOURCE_DIR}/src/nmea.h
${CMAKE_CURRENT_SOURCE_DIR}/src/serial.h)
target_sources(gps PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/gps.c
${CMAKE_CURRENT_SOURCE_DIR}/src/nmea.c
${CMAKE_CURRENT_SOURCE_DIR}/src/serial.c)
add_executable(${PROJECT_NAME} examples/position_logger.c)
target_link_libraries(${PROJECT_NAME} gps)
install(TARGETS gps DESTINATION /usr/local/lib)
#install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
toolchain-rpi.cmake contains the paths to the cross compiler
# Define our host system
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# Define the cross compiler locations
SET(CMAKE_C_COMPILER ${CMAKE_CURRENT_LIST_DIR}/../RaspCompiler/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${CMAKE_CURRENT_LIST_DIR}/../RaspCompiler/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
# Define the sysroot path for the RaspberryPi distribution in our tools folder
#SET(CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR}/../../RaspCompiler/arm- bcm2708/arm-rpi-4.9.3-linux-gnueabihf/sysroot/)
# Use our definitions for compiler tools
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories only
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
This is the cmake for my test program:
cmake_minimum_required(VERSION 2.6)
set(PROJECT_NAME GPS_Program)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../RPiToolchainCmake/toolchain-rpi.cmake) # must be before project()
project(${PROJECT_NAME})
# libgps -- Begin
set(GPS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libgps/src)
set(LIBGPS_PATH /usr/local/lib)
find_library(GPS_LIBRARY
NAMES libgps
PATHS ${LIBGPS_PATH}
NO_DEFAULT_PATH)
if (NOT ${GPS_LIBRARY})
message(FATAL_ERROR "LIBGPS not found in: ${LIBGPS_PATH} . Install libgps(Software/libgps)")
else()
message("LIBGPS_LIBRARY FOUND: " ${LIBGPS_PATH})
endif()
# libgps -- End
include_directories (include ${GPS_INCLUDE_DIR})
FILE(GLOB SRC_FILES src/main.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})
#install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
target_link_libraries(${PROJECT_NAME} ${GPS_LIBRARY})
The problem is, that libgps will not be found. I get every time the message, that libgps was not found:
CMake Error at CMakeLists.txt:17 (message):
LIBGPS not found in: /usr/local/lib . Install libgps(Software/libgps)
I checked that the program and the library are compiled with the same compiler. I added also
#ifdef __cplusplus
extern "C"{
#endif
to the gps.h file