CMake和Window .Lib文件 [英] CMake and Window .Lib Files

查看:300
本文介绍了CMake和Window .Lib文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力在Stackoverflow上找到这个问题的答案,至少我了解一个答案。我最近购买了CLion,并希望将Visual Studio中的旧项目移植到该项目上。但是我不知道如何将.lib文件链接或添加到我的项目中。我需要链接Xinput和DSound。

I have been struggling to find an answer to this question across Stackoverflow, at least one that I understand. I recently bought CLion and want to port an older project from Visual Studio over to it. But I have no idea how to link or add .lib files to my project. I need to link Xinput and DSound.

在Visual Studio中,我只是添加了标题,然后将它们添加到了文件的顶部

In Visual Studio I just added the headers and then added these to the top of my file

#pragma comment(lib, XInput.lib)

#pragma comment(lib, Dsound.lib)

我只是完全不知道如何使用CMake链接到那些库,

I just have absolutely no idea how to link to those libs using CMake as I am a complete beginner with it.

任何帮助将不胜感激

这是我当前的CMake文件

This is my current CMake file

cmake_minimum_required(VERSION 3.3)
project("Handmade_Hero")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)

INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")

add_executable("Handmade_Hero" ${SOURCE_FILES})

更新

cmake_minimum_required(VERSION 3.3)
project(Handmade_Hero)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)

INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")

add_executable(Handmade_Hero ${SOURCE_FILES})

set( LIBS XInput DSound )
target_link_libraries(Handmade_Hero ${LIBS} )

我的编译器现在抛出以下错误:

My Compiler now throws the following errors:

PATH\ClionProjects\Handmade-Hero\main.cpp:3:20: fatal error: Xinput.h: No such file or directory
 #include <Xinput.h>
                    ^
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles/Handmade_Hero.dir/main.cpp.obj] Error 1
CMakeFiles\Handmade_Hero.dir\build.make:62: recipe for target 'CMakeFiles/Handmade_Hero.dir/main.cpp.obj' failed
mingw32-make.exe[2]: *** [CMakeFiles/Handmade_Hero.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Handmade_Hero.dir/rule] Error 2
mingw32-make.exe: *** [Handmade_Hero] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Handmade_Hero.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Handmade_Hero.dir/rule' failed
Makefile:117: recipe for target 'Handmade_Hero' failed


推荐答案

只需在CMakeLists.txt之后添加这些

Simply add these after your CMakeLists.txt

SET( LIBS XInput DSound )
TARGET_LINK_LIBRARIES(projectname ${LIBS} )

这篇关于CMake和Window .Lib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆