简体   繁体   中英

including installed libraries in cmakelists

I don't always program in C, but when I do it's typically for microcontrollers, so please bear with me on this one.

I'm trying to run a simple test of a C program before I try and compile it in Matlab for a Simulink block. I'm using Clion as my IDE. If I compile on the command line with gcc -o listener exlcm_example_t.o listener.o 'pkg-config lcm --libs' my program compiles fine. Now, if I try to compile in my IDE I get that the system can't find the symbol for x86 etc.

I've found some similar solutions for people including other libraries, but they don't seem to work in my case. In particular, I'm trying to include the Lightweight Communications and Marshaling system LCM in order to do some interprocess communication.

I've tried a couple solutions from here on SE, and they generally follow what is outlined here . In the IDEs editor, if I do #include <lcm/lcm.h> , I can do Go To -> Declaration and it will take me to the h files, so it's finding it somehow, just not where I need it.

From what I've read, if make doesn't have a module for the library, I'll need to use my own *.cmake file. I happen to have found one here . My directory looks like this:

MyProject: - cmake -- modules --- *.cmake - cmakelists.txt - main.cpp

The help is much appreciated.

Self resolved by structuring my directory as above in the original post with FindLCM.cmake, and using this cmakelists.txt file:

    cmake_minimum_required(VERSION 3.2)
    project(lcm_mp)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    set(SOURCE_FILES main.cpp)
    add_executable(lcm_mp ${SOURCE_FILES})
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
    find_package(LCM REQUIRED lcm)
    include_directories(${LCM_INCLUDE_DIRS})
    set(LIBS ${LIBS} ${LCM_LIBRARIES})
    target_link_libraries(lcm_mp ${LIBS})

Any comments on improving on this file are much appreciated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM