I have a simple project with the following directory structure.
HelloCMake (directory)
|--CMakeLists.txt
|--main.cpp
|
|--HelloDll (directory)
|--CMakeLists.txt
|--hw1.hpp
|--hw1.cpp
The intent is to create a DLL out of hw1.cpp
and call one of its functions from main.cpp
, both functions printing their hello world (main or dll)
respectively. HelloCMake\CMakeLists.txt
has:
cmake_minimum_required(VERSION 3.6)
project (HelloDll)
add_subdirectory (HelloDll)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE})
# the above facilitates running / debugging the program from VS without install
add_executable (hw1 main.cpp)
target_link_libraries (hw1 hw1Dll)
Now HelloDll\CMakeLists.txt
:
add_library (hw1Dll SHARED hw1.cpp hw1.hpp)
set_target_properties (hw1Dll PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
Let's say I modify hw1.cpp
to print from 2 dll hello world
and build, and do Ctrl+F5 to run the program, it prints from 1 dll hello world
, the previous version. I can see that the latest dll was not copied. If I perform another build, it copies the latest dll and I see the right output.
I have tried solutions from other posts to no avail. The current one is from how do I make cmake output into a 'bin' dir?. What am I missing? I am sure it's something embarrassingly simple. Thanks.