我正在使用
gcc(cygwin),gnu make,windows 7和cmake.
我的cmake testprojekt具有以下结构
rootdir |-- App | |-- app.cpp | +-- CMakeLists.txt |-- Lib | |-- lib.cpp | |-- CMakeLists.txt |-- MakeFileProject + CMakeLists.txt
ROOTDIR /应用/ 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.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 /应用/的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)
现在,当我运行cmake和make时,一切都将生成并且构建没有错误,但是当我尝试执行二进制文件时,它将失败,因为找不到生成的库.
但是:当我将lib dll复制到像app exe这样的目录时,它会被执行!
另外:如果我将库配置为静态,它也将执行.
如何告诉运行时链接器在哪里查找我的DLL?
更新:
我打开了注册表编辑器,导航到以下密钥:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
,在这里我创建了一个名为applikation的新密钥:
在这种情况下:TestProjectExecutable.exe
之后,(默认)值设置为TestProjectExecutable.exe的完整路径,包括文件名和扩展名.然后我创建了另一个名为“Path”的字符串值,并将值设置为dll所在的文件夹: