I am working with gcc(cygwin), gnu make, windows 7 and cmake.
my cmake testprojekt has the following structure
rootdir |-- App | |-- app.cpp | +-- CMakeLists.txt |-- Lib | |-- lib.cpp | |-- CMakeLists.txt |-- MakeFileProject + CMakeLists.txt rootdir/App/app.cpp:
#include<string> void printThemMessageToScreen(std::string input);//prototype int main(int argc,char **argv){ printThemMessageToScreen("this will be displayed by our lib"); return 0; } rootdir/Lib/lib.cpp:
#include<iostream> #include<string> void printThemMessageToScreen(std::string input){ std::cout<<input; } rootdir/CMakeLists.txt:
cmake_minimum_required(VERSION 2.6) project(TestProject) add_subdirectory(App) add_subdirectory(Lib) rootdir/Lib/CMakeLists.txt:
add_library(Lib SHARED lib.cpp) rootdir/App/CMakeLists.txt:
# Make sure the compiler can find include files from our Lib library. include_directories (${LIB_SOURCE_DIR}/Lib) # Make sure the linker can find the Lib library once it is built. link_directories (${LIB_BINARY_DIR}/Lib) # Add executable called "TestProjectExecutable" that is built from the source files add_executable (TestProjectExecutable app.cpp) # Link the executable to the lib library. target_link_libraries (TestProjectExecutable Lib) Now, when i run cmake and make, everything will get generated & built with no errors, but when i try to execute the binary, it will fail because the library which was generated could not be found.
BUT: when i copy the lib dll into the same directory like the app exe, it will get executed!
also: if i configure the library to be static, it will also execute.
how to tell the runtime linker where to look for my dll?
UPDATE:
Solution according to the Method proposed by User Vorren:
I opened up the registry editor, and navigated to the following Key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths , here i created a new key with the name of my Applikation:
in this case : TestProjectExecutable.exe
after that, the (default) value was set to the full path of TestProjectExecutable.exe including the filename and extension. Then i created another String Value called "Path" and set the value to the folder where the dll was located:
