c ++ - CMake forbinder Windows SDK

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg har et projekt i CLion, hvor jeg skal medtage et bibliotek fra Windows 8.1 SDK, så jeg forsøgte at bruge CMake til at forbinde det.

Jeg har ingen .so eller .dll, men .lib (eller direkte .h-filen).

Specifikt er dette bibliotek dsound.h.

Jeg forsøgte at søge efter relaterede spørgsmål, men ingen af ​​de løsninger, jeg fandt, virker for mig: hvordan kan jeg gøre det?


Min nuværende CMakeLists.txt er


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})


hvor WinSDK er variablen indeholdende placeringen af ​​Windows SDK.


Fejlen jeg får er følgende:


[ 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:projectPathsoundclass.cpp:4:0:
C:projectPathsoundclass.h:21:24: fatal error: dsound.h: No such file or directory
In file included from C:projectPathmain.cpp:5:0:
C:projectPathsoundclass.h:21:24: fatal error: dsound.h: No such file or directory
compilation terminated.
compilation terminated.
CMakeFilesProject.diruild.make:61: recipe for target 'CMakeFiles/Project.dir/main.cpp.obj' failed
CMakeFilesProject.diruild.make:85: recipe for target 'CMakeFiles/Project.dir/soundclass.cpp.obj' failed
CMakeFilesMakefile2: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
CMakeFilesMakefile2: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

Bedste reference


${WinSDK} kan ikke indstilles korrekt, da du bruger samme variabel på samme måde for både inkluder og bibliotek.


Andre tips:



  • CMAKE\_CXX\_STANDARD gør intet for MSVC compileren

  • Det er bedre at bruge target\_include\_directories() end include\_directories() for at holde målinformationen renere