【发布时间】:2022-01-31 03:36:34
【问题描述】:
这是我第一次使用 CMake,所以请耐心等待。我的知识非常有限。 我正在按照教程重新创建我在下面链接的太空入侵者。
我使用 git-bash 设置我的存储库,现在我正在使用 CMake (cmake-gui) for Windows 设置我的构建。
回购教程链接:https://dooglz.github.io/set09121/repo_setup.html
构建教程链接:https://dooglz.github.io/set09121/build_setup.html
这是我关注的 CMake 指南:https://github.com/edinburgh-napier/aux_guides/blob/master/cmake_guide.pdf
据我了解,对于“源代码在哪里”,我使用 CMakeLists.txt 和 main.cpp 创建了一个名为“Space Invader”的文件夹。对于“在哪里构建二进制文件”,我创建了一个名为“build”的空文件夹。
当我按下配置时,我得到这个error message.
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
CMake Error at CMakeLists.txt:15 (add_subdirectory):
add_subdirectory given source "lib/sfml" which is not an existing
directory.
这是给定的 CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
# Require modern C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(Games_Engineering)
#### Setup Directories ####
#Main output directory
SET(OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
# Ouput all DLLs from all libs into main build folder
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
#### Add External Dependencies ####
add_subdirectory("lib/sfml")
set(SFML_INCS "lib/sfml/include")
link_directories("${CMAKE_BINARY_DIR}/lib/sfml/lib")
#### Practical 1 ####
file(GLOB_RECURSE SOURCES practical_1/*.cpp practical_1/*.h)
add_executable(PRACTICAL_1 ${SOURCES})
target_include_directories(PRACTICAL_1 PRIVATE ${SFML_INCS})
target_link_libraries(PRACTICAL_1 sfml-graphics)
main.cpp
int main(){
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed){
window.close();
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
我还尝试使用 git-bash 创建 CMake。该教程说要使用以下命令:
mkdir projectname_build
cd projectname_build
cmake -G "Visual Studio 14 2015 Win64" ../projectname/
或者在我的情况下是最后一行(我猜这是正确的)
cmake -G "Visual Studio 16 2019" ../projectname/
但是当我尝试使用 git-bash 时,我得到了这个错误:
bash: cmake: command not found
我可以使用 git-bash 或 CMake for Windows 制作 CMake,因此我愿意接受使用这些路线的任何解决方案。我也不想将代码更改为在尝试完成此项目时将来会遇到问题的地方,这就是为什么我链接教程以展示我已经完成的工作。
我一直在寻找解决方案,但我很迷茫。请查看网站链接,请耐心等待我。如果其中任何内容令人困惑或措辞错误,我深表歉意。我只是一个试图扩展我的技能的学生。
【问题讨论】:
-
您是否按照最后的步骤将 sfml 添加为 git 子模块?你忘记运行
git submodule update --init --recursive了吗? dooglz.github.io/set09121/repo_setup.html#get-sfml -
@AlexReinking 是的,我遵循了最后的步骤
git submodule updategit submodule init,但它没有提到递归。
标签: c++ cmake git-bash subdirectory cmake-gui