0

By using otool I can find and add all the library files to a "lib" folder for my project. I am having trouble making my unix file (c++) reference the folder.

Even though the file "libtensorflow.2.dylib" is in a folder "lib" beside the "myproject" app. I have tried also putting the libraries in the same folder as well, children, side by side folders.... Any ideas? Or even ways to debug?

dyld: Library not loaded: @rpath/libtensorflow.2.dylib
     referenced from: /Users/anan/Downloads/myproject 2/myproject
     Reason: image not found

Here is a look at my cmake

cmake_minimum_required(VERSION 2.8.12) project(myproject)

set(CMAKE_MACOSX_RPATH OFF)

# if (CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_STANDARD 17) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    set(CMAKE_CXX_FLAGS "-L /lib -I /lib -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)

add_compile_definitions(${libavcodec_CFLAGS_OTHER})

add_executable(myproject myproject.cpp)

target_link_libraries(mypro "-framework Cocoa") 
target_link_libraries(myproject "-framework IOKit") 
target_link_libraries(myproject ${libavcodec_LIBRARIES})


include(GNUInstallDirs) install(
    TARGETS myproject
    RUNTIME DESTINATION ./bin
    LIBRARY DESTINATION ./lib
    ARCHIVE DESTINATION ./lib
    COMPONENT Application
    ) 
set(CMAKE_MACOSX_BUNDLE 1)
set(CMAKE_INSTALL_RPATH "@executable_path/lib")

set(CPACK_COMPONENTS_ALL Application)
set(CPACK_COMPONENT_APPLICATION_DISPLAY_NAME "Analysis")



set(CPACK_GENERATOR "TGZ")

include(InstallRequiredSystemLibraries) 
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${myproject_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${myproject_VERSION_MINOR}")
include(CPack)
msj121
  • 2,812
  • 3
  • 28
  • 55
  • Setting [CMAKE_INSTALL_RPATH](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_RPATH.html) variable affects only on the targets created **afterwards**, it doesn't affects on already created targets. (This variable is used for initialize property [INSTALL_RPATH](https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html) of the target when the target is created.) – Tsyvarev Sep 16 '22 at 07:58
  • 1
    Also, setting `-L` and `-l` flags in `CMAKE_CXX_FLAGS` variable is simply wrong: https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake/43136695#43136695 – Tsyvarev Sep 16 '22 at 07:59
  • @Tsyvarev Currently I am just trying different things out to see if I can link folders for libraries after creation. As you can see I am trying anything at the moment. – msj121 Sep 16 '22 at 18:21
  • @Tsyvarev So how do I set the "r_path" for a library that was installed on my computer that I would like to use in my executable, but is looking in rpath and not the local "lib" folder? – msj121 Sep 16 '22 at 18:24
  • Setting `CMAKE_INSTALL_RPATH` variable is correct approach for your task. But this variable should be set **before** `add_executable` call. Otherwise (like in your current code) this setting has no effect on the executable. – Tsyvarev Sep 16 '22 at 18:37

0 Answers0