C++ running file with included library failes without compiling error (CMake / CLion)

て烟熏妆下的殇ゞ 提交于 2019-12-02 02:54:30

Exit code -1073741515 (0xC0000135) is STATUS_DLL_NOT_FOUND. This would indicate that the dll isn't available to the program at runtime. In windows, the search path for a dll is as follows:

  1. The directory where the executable for the current process is located.
  2. The current directory.
  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
  5. The directories listed in the PATH environment variable.

Verify that liblibrary.dll is located in a place it can be found by the executable.

Once you have done that, you may want to add a macro to help you copy the dll to the executable directory as part of your build. This can be done in cmake like so:

add_custom_command(TARGET uselib POST_BUILD        # Adds a post-build event to uselib
COMMAND ${CMAKE_COMMAND} -E copy_if_different  # which executes "cmake - E copy_if_different..."
    "${PROJECT_SOURCE_DIR}/libs/liblibrary.dll"      # this is in-file
    $<TARGET_FILE_DIR:uselib>)                 # this is out-file path
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!