I have a CLion/CMake project that needs an external DLL, A.dll
, which I have placed in the project lib/
directory. After building the executable, when I run the APP.exe
, it cannot find/use the lib/A.dll
. How do I fix this?
Asked
Active
Viewed 1,325 times
3

gknauth
- 2,310
- 2
- 29
- 44
-
Did you move the executable file after build succeed? – Shihe Zhang May 23 '17 at 01:52
3 Answers
2
I think you didn't add .dll file to cmake file this is Quick CMake Tutorial or CLion and CMake: only building a library without an executable?

Pang
- 9,564
- 146
- 81
- 122

NinjaDeveloper
- 1,620
- 3
- 19
- 51
-
I am aware of the tutorial and did add the .dll but apparently I didn't not use the right command. I used a command that apparently is good at the compilation linking step, but not at the runtime step, e.g., when you press Run in CLion. – gknauth May 09 '16 at 15:02
-
1I'm not trytng to build a library without an executable. I'm trying to run an executable that uses an external .dll I want this project to find when I press Run in CLion. – gknauth May 09 '16 at 15:04
0
I usually just add D:/path/to/lib/A.dll to the Path, either globally by editing the user or system environment variables, or by creating a small batch file which sets up the Path along with CMAKE_PREFIX_PATH et al then possibly spawns something like cmake-gui.exe or devenv.exe.

Daniel Schepler
- 3,043
- 14
- 20
0
If you are asking import exist lib in cmake,this link can be help.
you may need this code in your CMakeList.txt
# Create an IMPORTED library
add_library(A IMPORTED)
# Set IMPORTED_LOCATION *property* for this target
set_target_properties(SimpleAmqpClient PROPERTIES
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/A.dll)
# Then use library *target* for linking with
target_link_libraries(APP PUBLIC A)

Shihe Zhang
- 2,641
- 5
- 36
- 57