0

Continuation of this question, where there's already some advice on how to solve the issue, but still I cannot manage.

My current CMakeLists.txt is the following:

cmake_minimum_required(VERSION 3.12)
project( project_360_visual )
find_package(OpenCV REQUIRED)
set(SOURCE_FILES 
    ${CMAKE_SOURCE_DIR}/src/project_360_visual.cpp
    ${CMAKE_SOURCE_DIR}/src/projection.cpp)
set(INCLUDE_FILES
    ${CMAKE_SOURCE_DIR}/include/project_360_visual.h
    ${CMAKE_SOURCE_DIR}/include/projection.h)

#Creating executable targets
add_executable(project_360_visual ${SOURCE_FILES} ${INCLUDE_FILES})
set_target_properties(project_360_visual PROPERTIES RUNTIME_OUTPUT_DIRECTORY 
    ${CMAKE_SOURCE_DIR}/bin )

#Creating library targets
add_library(opencv_tracking430 SHARED IMPORTED GLOBAL)
set_target_properties(opencv_tracking430 PROPERTIES
    IMPORTED_LOCATION "c:/opencv/build/bin/Release/opencv_tracking430.dll"
    IMPORTED_IMPLIB "c:/opencv/build/lib/Release/opencv_tracking430.lib"
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
)

target_include_directories(project_360_visual PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(project_360_visual PUBLIC ${OpenCV_LIBS} opencv_tracking430)

Again, building is fine, but when I run the executable the .dll is not seen. I'm not sure I've used correctly the LIBRARY_OUTPUT_DIRECTORY property.

I think the idea of target opencv_tracking430 is to import the library and then move it in LIBRARY_OUTPUT_FOLDER, the same needs to be done for the executable.

The executable is correctly moved, but not the .dll.

Any suggestions?

user8469759
  • 2,522
  • 6
  • 26
  • 50
  • Does this answer your question? Perhaps, this is a more relevant link, considering your DLLs are third party libraries: [How to copy DLL files into the same folder as the executable using CMake?](https://stackoverflow.com/questions/10671916/how-to-copy-dll-files-into-the-same-folder-as-the-executable-using-cmake) – Kevin Apr 13 '20 at 18:54
  • Is that the only solution then? Doesn't sound really "elegant". If I copy the file anyway does the import of the shared library (`.dll` + `.lib`) still make sense? – user8469759 Apr 13 '20 at 18:56
  • Also, why doesn't my command work? Is it because the library is already built? – user8469759 Apr 13 '20 at 18:58
  • And it doesn't work, my output is generated in `project-name/bin/Release` (the actual executable) while the library is only copied in `project-name/bin`. I'm trying to figure if there a variable storing the actual path of the executable. – user8469759 Apr 13 '20 at 19:19
  • The linked response is one of `cmake`'s most viewed questions on the site (56k views), so I'd consider the answers provided to be the best solutions available. And yes, you still need to tell CMake the location of the import library (`.lib`) so that your library is linked properly. Also, because you are using Visual Studio (a multi-configuration IDE), you must use [generator expressions](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html) to resolve the full path to the executable (i.e. `project-name/bin/Release`). The answers in the linked question address this. – Kevin Apr 13 '20 at 19:58

0 Answers0