0

I am building a project that utilizes a library that is outside of the scope of the project. I am relatively new to CMake and I can't seem to get this library to build. my code is below:

    cmake_minimum_version(VERSION 3.1) 
    
    project(cameraCode VERSION 1.0.0)
    add_library(camControl SHARED IMPORTED
                /opt/MVS/lib/64/MVCamControl
                /opt/MVS/include/MvCamControl.h)
    add_executable(${PROJECT_NAME} cameraCode.cpp)
    
    target_link_libraries(${PROJECT_NAME} 
                PRIVATE
                camControl)

when I make this, it configures okay, but when I build it, I get this error: make[2] *** No rule to make target 'camControl-NOTFOUND', needed by 'cameraCode'. Stop.

2 Answers2

0

add_library would mean that you are building the library.

I don't think add_library is what you want, if this is the prebuilt library as you say.

It looks like you just need link_directories and include_directories for the client to be able to find library and header files.

StPiere
  • 4,113
  • 15
  • 24
  • I just tried that and now I'm getting this:/usr/bin/ld: cannot find -lcamControl – Steven Kraine Aug 28 '20 at 13:27
  • You have to check the documentation for the correct syntax – StPiere Aug 28 '20 at 13:28
  • this is what I have now: find_library(MvCamControl /opt/MVS/lib/64/ /opt/MVS/include/ REQUIRED) add_executable(${PROJECT_NAME} cameraCode.cpp) target_link_libraries( ${PROJECT_NAME} PUBLIC MvCamControl ) MvCamControl is the name of the library and the path to the library itself is below that and the path to the header file is below that. – Steven Kraine Aug 28 '20 at 13:35
0

You were right with the IMPORTED library, but you need to set some properties instead of passing the files as part of add_library:

add_library(camControl SHARED IMPORTED)
set_target_properties(camControl PROPERTIES
    IMPORTED_LOCATION /opt/MVS/lib/64/MVCamControl/libMVCamControl.so
    INTERFACE_INCLUDE_DIRECTORIES /opt/MVS/include/
)
Botje
  • 26,269
  • 3
  • 31
  • 41
  • okay, I tried that and I am getting this error: /usr/bin/ld: cannot find -lMvCameraControl – Steven Kraine Aug 28 '20 at 15:17
  • And is there a `libMvCameraControl.so` in /opt/MVS/lib/64/MVCamControl/? Show the full linker command line with `make VERBOSE=1` – Botje Aug 28 '20 at 15:19
  • This is the error I get now: No rule to make target '/opt/MVS/lib/64/libMVCameraControl.so', needed by 'cameraCode'. Stop. – Steven Kraine Aug 28 '20 at 15:23
  • I am asking for the fifth time now: **what is the name of the .so file under '/opt/MVS/lib/64/'?** – Botje Aug 28 '20 at 15:25
  • it is MvCameraControl.so – Steven Kraine Aug 28 '20 at 15:31
  • Does your IMPORTED_LOCATION end on "/MvCameraControl.so" or "/libMvCameraControl.so" ? Also keep in mind that capitalization matters. – Botje Aug 28 '20 at 15:34
  • @StevenKraine: Under `IMPORTED_LOCATION` property you should write the absolute path of your library file. The error `No rule to make target` for that path means, that you have specified that path **wrong**. Since we don't know the absolute path of the file on **your machine**, we cannot help you in selecting proper value for `IMPORTED_LOCATION` property. – Tsyvarev Aug 28 '20 at 16:28