0

I have two files in a project local lib/ directory. The files are oysters.lib and oysters.dll.

My CMake looks like this:

add_executable(MyProject ${SOURCES})
target_link_libraries(MyProject ${PROJECT_SOURCE_DIR}/lib/oysters.lib)

When I try to run the exe

enter image description here (Ignore the dll in the image, I changed the name to make it simpler. Assume its missing oysters.dll)

BAR
  • 15,909
  • 27
  • 97
  • 185
  • 1
    A similar question was asked today. – 273K Aug 31 '22 at 02:45
  • Put the dll in the same folder as the executable. You could script that with CMake using a post build step or possibly [https://cmake.org/cmake/help/latest/module/BundleUtilities.html](https://cmake.org/cmake/help/latest/module/BundleUtilities.html) Related: [https://stackoverflow.com/questions/14089284/copy-all-dlls-that-an-executable-links-to-to-the-executable-directory](https://stackoverflow.com/questions/14089284/copy-all-dlls-that-an-executable-links-to-to-the-executable-directory) – drescherjm Aug 31 '22 at 02:49
  • 1
    @drescherjm - I have just contributed an answer to the question you linked that works well in CMake 3.21+ using the new `$`. @BAR, that answer should address the issue you're having here. – Alex Reinking Aug 31 '22 at 03:45
  • @AlexReinking thanks. I am sure that will be helpful when I get to modernize some of my 12+ year old CMake scripts.. – drescherjm Aug 31 '22 at 04:02
  • Depending on whether you use the debugger or you want to deploy your own project with the binaries, setting the path for the debugger could work (`set_target_properties(MyProject PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=${ONIXS_DLL_DIR};$ENV{PATH}")`). For deploying the `RUNTIME_DEPENDENCIES` parameter for [`install(TARGETS)`](https://cmake.org/cmake/help/latest/command/install.html#targets) could be useful. – fabian Aug 31 '22 at 18:03
  • @fabian I want to do both, use the debugger and build for prod. I'm a little confused on what I should do, can you post an answer? – BAR Aug 31 '22 at 19:04

0 Answers0