# CPACK third party libraries

**URL:** https://discourse.cmake.org/t/cpack-third-party-libraries/6489
**Category:** Usage
**Created:** [September 14, 2022, 11:04pm UTC](https://discourse.cmake.org/t/cpack-third-party-libraries/6489 "2022-09-14T23:04:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![msj242](https://discourse.cmake.org/user_avatar/discourse.cmake.org/msj242/32/2772_2.png) [@msj242](https://discourse.cmake.org/u/msj242)
#### Post date: [September 14, 2022, 11:04pm UTC](https://discourse.cmake.org/t/cpack-third-party-libraries/6489/1 "2022-09-14T23:04:14Z")

</div>

I have worked out how to make my cmake compile, but now deploying with libraries is confusing me greatly.

As you can see below “target\_link\_libraries(my\_project ${libavcodec\_LIBRARIES})” allows me to use this code, but how do I package that library with “cpack” so that I don’t need a user to install it? I have been looking everywhere to understand this…

Thank you so much! Any tutorial or something? How do I even find the necessary files if I just want to manually add them to the bundle?

```auto
cmake_minimum_required(VERSION 2.8.12)
project(my_project)

# if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_STANDARD 17)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    set(CMAKE_CXX_FLAGS "-I /usr/local/include -L /usr/local/lib -l tensorflow -Wall -Os -g ${CMAKE_CXX_FLAGS}")
    # -I /usr/local/include -L /usr/local/lib -l tensorflow -std=c++17 
    message("CMAKE_COMPILER_IS_GNUCXX is True")
    message("option is: ${CMAKE_CXX_FLAGS}")
endif() #(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# endif (CMAKE_COMPILER_IS_GNUCXX)

find_package(PkgConfig)

pkg_check_modules(libavcodec REQUIRED libavcodec)
pkg_check_modules(libavformat REQUIRED libavformat)
pkg_check_modules(libavdevice REQUIRED libavdevice)
pkg_check_modules(libavutil REQUIRED libavutil)
pkg_check_modules(libswscale REQUIRED libswscale)
pkg_check_modules(sdl REQUIRED sdl)

add_compile_definitions(${libavcodec_CFLAGS_OTHER})
add_compile_definitions(${libavformat_CFLAGS_OTHER})
add_compile_definitions(${libavdevice_CFLAGS_OTHER})
add_compile_definitions(${libavutil_CFLAGS_OTHER})

find_package( OpenCV REQUIRED )
add_compile_definitions(${OpenCV_CFLAGS_OTHER})

add_compile_definitions(${libswscale_CFLAGS_OTHER})

add_executable(my_project my_project.cpp)

target_link_libraries(my_project "-framework Cocoa")
target_link_libraries(my_project "-framework IOKit")
target_link_libraries(my_project ${libavcodec_LIBRARIES})
target_link_libraries(my_project ${libavformat_LIBRARIES})
target_link_libraries(my_project ${libavdevice_LIBRARIES})
target_link_libraries(my_project ${libavutil_LIBRARIES})
target_link_libraries(my_project ${OpenCV_LIBRARIES})
target_link_libraries(my_project ${libswscale_LIBRARIES})
# target_link_libraries(my_project ${sdl_LIBRARIES})

SET(dlib_ROOT "~/Documents/Code/my_project/build/dlib-19.24/")
target_link_libraries(my_project dlib)

install(
    TARGETS my_project
    COMPONENT Application
    )

set(CPACK_COMPONENTS_ALL Application Libraries)
set(CPACK_COMPONENT_APPLICATION_DISPLAY_NAME "Analysis")
set(CPACK_COMPONENT_APPLICATION_LIBRARY_NAME "Video Libaries")

set(CPACK_GENERATOR "TGZ")
if (WIN32)
    list(APPEND CPACK_GENERATOR "NSIS")
elseif (APPLE)
    list(APPEND CPACK_GENERATOR "Bundle")
endif(WIN32)
set(CPACK_SOURCE_GENERATOR "ZIP;TGZ")

include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${my_project_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${my_project_VERSION_MINOR}")
include(CPack)

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 15, 2022, 3:20pm UTC](https://discourse.cmake.org/t/cpack-third-party-libraries/6489/2 "2022-09-15T15:20:47Z")

</div>

You’ll want to look at [`file(GET_RUNTIME_DEPENDENCIES)`](https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies) for that.

---

<div class="post-metadata">

### Author: ![msj242](https://discourse.cmake.org/user_avatar/discourse.cmake.org/msj242/32/2772_2.png) [@msj242](https://discourse.cmake.org/u/msj242)
#### Post date: [September 16, 2022, 2:29am UTC](https://discourse.cmake.org/t/cpack-third-party-libraries/6489/3 "2022-09-16T02:29:11Z")

</div>

Thanks! That was perfect. And quick question how do I link those libraries (for example in a “lib” folder) so that the output executable (unix file) will look for the libraries there?

Currently I get an error: “dyld: Library not found: @rpath/libtensorflow.2.dylib”, where libtensorflow.2.dylib is in the lib folder.

Thanks for any help!

For future people searching:

```auto
file(GET_RUNTIME_DEPENDENCIES
    EXECUTABLES my_project
    RESOLVED_DEPENDENCIES_VAR RESOLVED_DEPS
    UNRESOLVED_DEPENDENCIES_VAR UNRESOLVED_DEPS
  )
  foreach(FILE ${RESOLVED_DEPS})
    #Do whatever you need with these libraries
  endforeach()
  foreach(FILE ${UNRESOLVED_DEPS})
    message(STATUS "Unresolved: ${FILE}")
  endforeach()

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 16, 2022, 12:51pm UTC](https://discourse.cmake.org/t/cpack-third-party-libraries/6489/4 "2022-09-16T12:51:22Z")

</div>

For that, you’ll need to add an RPATH entry (`CMAKE_{INSTALL,BUILD}_RPATH`) to the appropriate location. Probably something like `@executable_path/../lib` or the like for the install and the containing path for the build.

---

<div class="post-metadata">

### Author: ![mhebes](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mhebes](https://discourse.cmake.org/u/mhebes)
#### Post date: [September 19, 2022, 2:04pm UTC](https://discourse.cmake.org/t/cpack-third-party-libraries/6489/5 "2022-09-19T14:04:03Z")

</div>

For what it’s worth, I (and many programs I’ve seen) just dump the DLLs in the same bin folder as my exe.

Even when the libraries have their dlls spread across a bunch of directories, I put them directly in `bin/` so my exe can see them.

Also in regards to actually finding your DLLs for installation:

Some Find modules make this process easy because they provide a `LIB_BIN_DIR` or similar that you can pass right to `file(GET_RUNTIME_DEPENDENCIES` or `install(RUNTIME_DEPENDENCY_SET` but a lot of times I have to manually add the search directory (usually ends up being something like `LIB_INCLUDE_DIR/../bin`)
