1
我在CLion中有一個項目,我需要從Windows 8.1 SDK中包含一個庫,所以我試圖用CMake來鏈接它。
我沒有任何.so或.dll,但.lib(或直接.h文件)。
具體來說,這個庫是dsound.h。
我試圖尋找相關的問題,但我找到的解決方案都不適合我:我該怎麼做?CMake鏈接Windows SDK
我目前的CMakeLists.txt是
cmake_minimum_required(VERSION 3.7)
project(Project)
set(CMAKE_CXX_STANDARD 11)
include_directories(${WinSDK})
set(SOURCE_FILES main.cpp file1.h file1.cpp)
add_executable(Project ${SOURCE_FILES})
target_link_libraries(Project ${WinSDK})
其中WinSDK是包含Windows SDK的位置的變量。
我得到的錯誤是:
[ 33%] Building CXX object CMakeFiles/Project.dir/main.cpp.obj
[ 66%] Building CXX object CMakeFiles/Project.dir/soundclass.cpp.obj
In file included from C:\projectPath\soundclass.cpp:4:0:
C:\projectPath\soundclass.h:21:24: fatal error: dsound.h: No such file or directory
In file included from C:\projectPath\main.cpp:5:0:
C:\projectPath\soundclass.h:21:24: fatal error: dsound.h: No such file or directory
compilation terminated.
compilation terminated.
CMakeFiles\Project.dir\build.make:61: recipe for target 'CMakeFiles/Project.dir/main.cpp.obj' failed
CMakeFiles\Project.dir\build.make:85: recipe for target 'CMakeFiles/Project.dir/soundclass.cpp.obj' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Project.dir/all' failed
mingw32-make.exe[3]: *** [CMakeFiles/Project.dir/main.cpp.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
mingw32-make.exe[3]: *** [CMakeFiles/Project.dir/soundclass.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Project.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Project.dir/rule' failed
Makefile:117: recipe for target 'Project' failed
mingw32-make.exe[1]: *** [CMakeFiles/Project.dir/rule] Error 2
mingw32-make.exe: *** [Project] Error 2
你在哪裏初始化'WinSDK'變量?在一個較高的範圍內的某處?頭文件是否正好位於您存儲在「WinSDK」變量中的位置? – Akira
'WinSDK'變量在CLion的Path Variables中定義;現在我改變它取決於包括和庫,如@utopia建議,它的工作。 – thesmith
我的意圖與我的問題是要確保您設置標題和庫的確切位置或不。看起來這是你問題的根源。 – Akira