0

So I have a library and some associated headers and a little driver.

proj
    include
        blob.dylib
        header1.h
        header2.h
    src
        driver.cpp

I would like to rebundle this into a modern cmake target for find_package as well as make it accessible when included in some users tree. I was planning on following a guide to enable the library install and etc, but I haven't got that far because I am running into an error.

Currently my cmake file looks like this

cmake_minimum_required(VERSION 3.5)

project(EVAPI VERSION 1.1.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14)

add_executable(libBlobAPI
    src/driver.cpp
)

find_library(BLOB blob)

target_link_libraries(libBlobAPI
    BLOB
)

target_include_directories(libBlobAPI
    PUBLIC
        $<INSTALL_INTERFACE:include>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
) 

but this fails with error:

ld: library not found for -linclude/libBlobAPI.dylib

The question is... What is the canonical way to repackage a library with modern CMake?

cmg
  • 29
  • 3
  • 6
  • You talk about using `find_package` for find your library, but your code uses `find_library` instead... and does that in wrong manner: the first argument to the `find_library` is a *name of the variable* (not a target, so it cannot be used in `target_link_libraries`), and the second is the name of the *library file* (not an executable target). For use `find_package` for finding the library, you need to write either "Find" script or "Config" script. You may find more info about "Config" scripts in [documentation](https://cmake.org/cmake/help/v3.9/manual/cmake-packages.7.html#id14). – Tsyvarev Jun 13 '18 at 19:56
  • @Tsyvarev ... Ah that was a mistake, corrected. I actually already know where blob.dylib is located. So I'm probably not supposed to be attempting to find it anyway, but I don't know how to specify it. – cmg Jun 13 '18 at 20:31
  • If you want to use library via IMPORTED target, you need to create that target, and then assign path of your library to *IMPORTED_LOCATION* property of that target. – Tsyvarev Jun 13 '18 at 20:38
  • @Tsyvarev : Are there other ways to link to the shared library without it being an existing target. At this time, the library only exists as the .dylib and an associated headers. I have no access to code or build system that created the library. – cmg Jun 13 '18 at 22:48
  • "Are there other ways to link to the shared library without it being an existing target?" - Yes, see there: https://stackoverflow.com/questions/8774593/cmake-link-to-external-library. – Tsyvarev Jun 14 '18 at 08:32

0 Answers0