0

I'm trying to compile a code with cmake and get this error (I'm pretty new with cmake):

/usr/bin/ld: cannot find -lMPC

Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.0.2)
project(PX4Vision_AutonomousLanding)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  nav_msgs
  geometry_msgs
  mavros_msgs
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

catkin_package(
  CATKIN_DEPENDS roscpp nav_msgs geometry_msgs mavros_msgs
)

add_executable(offboard_node
  src/offboard_node.cpp
)

target_link_libraries(offboard_node
  MPC
  ${CMAKE_DL_LIBS}
  ${catkin_LIBRARIES} 
)

Inside the folder where my CMakeLists.txt file is I have a subfolder "src" where I have two files: "offboard_node.cpp" and "MPC.so". The first file contains the following line:

handle = dlopen("./MPC.so", RTLD_LAZY);

LucaGare
  • 13
  • 3
  • It you're using dlopen you don't need to link to the library – Alan Birtles May 28 '21 at 16:09
  • 1
    Since you ship MPC library with your project, you need to tell CMake about the **location** of the library. See duplicate question about possible ways. – Tsyvarev May 28 '21 at 16:35
  • @Tsyvarev I looked for other similar questions but all the one I found were using make instead of cmake so they did not have a CMakeLists.txt file, I'm quite new to this kind of thinks so I don't really know hot to tell CMake about the location. Could you please elaborate a bit more on that? – LucaGare May 28 '21 at 16:49
  • @AlanBirtles are you sure about that? – LucaGare May 28 '21 at 16:51
  • @LucaGare: "I have a subfolder "src" where I have two files: "offboard_node.cpp" and "MPC.so"" - So, **absolute path** to your library is `${CMAKE_CURRENT_SOURCE_DIR}/src/MPC.so`. You could use this path with an IMPORTED target, as described in [this answer](https://stackoverflow.com/a/10550334/3440745) (this is preferred way). – Tsyvarev May 28 '21 at 17:26
  • @Tsyvarev Thanks!!! I was looking at that answer but I had trouble with specifying the path to my library. `${CMAKE_CURRENT_SOURCE_DIR}` was the thing I needed and I didn't know about! (Again, I'm pretty new with all this stuff). – LucaGare May 28 '21 at 17:43

0 Answers0