在 MacOS 上的 Geany 中让 SFML 与 C++ 一起工作时遇到问题
Having trouble getting SFML to work with C++ in Geany on MacOS
我想用 C++ 进行游戏开发,所以我决定尝试 SFML。但是,即使将所有文件都放在正确的位置后,它也找不到需要的文件。
我按照页面 https://www.sfml-dev.org/tutorials/2.5/start-osx.php 上的所有步骤进行操作,确保将所有框架和 dylib 放在正确的文件夹中,但它仍然不允许我使用 SFML 文件
#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear(sf::Color::Black);
window.display();
}
return 0;
}
程序应该做的是显示一个可以关闭的黑色window,但它给我错误信息
g++ -Wall -o "helloWorld" "helloWorld.cpp" (in directory /Users/Splavacado100/Desktop/Coding/C++)
helloWorld.cpp:2:10 fatal error: 'SFML/Graphics.hpp' file not found
#include <SFML/Graphics.hpp>
SFML(据我所知,标准模板库之外的任何其他库)要求编译器知道 lib 和 include 文件夹的存储位置。在此错误实例中,您使用的 IDE 似乎没有找到正确的文件夹路径。它没有在 MacOS 版本中列出,因为您喜欢的教程假定您使用的是 XCode,这就像 Visual Studio 对应 Mac。
据我所知,如果您在纯文本编辑器中编写程序,并使用 makefile 或命令行提示进行编译,请查看 SFML and Linux article 以更完整地了解如何使用它.与此场景相关的:
In case you installed SFML to a non-standard path, you'll need to tell the compiler where to find the SFML headers (.hpp files):
g++ -c main.cpp -I<sfml-install-path>/include Here
,
is the directory where you copied SFML, for
example /home/me/sfml.
You must then link the compiled file to the SFML libraries in order to
get the final executable. SFML is made of 5 modules (system, window,
graphics, network and audio), and there's one library for each of
them. To link an SFML library, you must add "-lsfml-xxx" to your
command line, for example "-lsfml-graphics" for the graphics module
(the "lib" prefix and the ".so" extension of the library file name
must be omitted).
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
If
you installed SFML to a non-standard path, you'll need to tell the
linker where to find the SFML libraries (.so files):
g++ main.o -o sfml-app -L<sfml-install-path>/lib -lsfml-graphics
-\lsfml-window -lsfml-system
We are now ready to execute the compiled program:
我想用 C++ 进行游戏开发,所以我决定尝试 SFML。但是,即使将所有文件都放在正确的位置后,它也找不到需要的文件。
我按照页面 https://www.sfml-dev.org/tutorials/2.5/start-osx.php 上的所有步骤进行操作,确保将所有框架和 dylib 放在正确的文件夹中,但它仍然不允许我使用 SFML 文件
#include <iostream>
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear(sf::Color::Black);
window.display();
}
return 0;
}
程序应该做的是显示一个可以关闭的黑色window,但它给我错误信息
g++ -Wall -o "helloWorld" "helloWorld.cpp" (in directory /Users/Splavacado100/Desktop/Coding/C++)
helloWorld.cpp:2:10 fatal error: 'SFML/Graphics.hpp' file not found
#include <SFML/Graphics.hpp>
SFML(据我所知,标准模板库之外的任何其他库)要求编译器知道 lib 和 include 文件夹的存储位置。在此错误实例中,您使用的 IDE 似乎没有找到正确的文件夹路径。它没有在 MacOS 版本中列出,因为您喜欢的教程假定您使用的是 XCode,这就像 Visual Studio 对应 Mac。
据我所知,如果您在纯文本编辑器中编写程序,并使用 makefile 或命令行提示进行编译,请查看 SFML and Linux article 以更完整地了解如何使用它.与此场景相关的:
In case you installed SFML to a non-standard path, you'll need to tell the compiler where to find the SFML headers (.hpp files):
g++ -c main.cpp -I<sfml-install-path>/include Here
, is the directory where you copied SFML, for example /home/me/sfml.You must then link the compiled file to the SFML libraries in order to get the final executable. SFML is made of 5 modules (system, window, graphics, network and audio), and there's one library for each of them. To link an SFML library, you must add "-lsfml-xxx" to your command line, for example "-lsfml-graphics" for the graphics module (the "lib" prefix and the ".so" extension of the library file name must be omitted).
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
If you installed SFML to a non-standard path, you'll need to tell the linker where to find the SFML libraries (.so files):
g++ main.o -o sfml-app -L<sfml-install-path>/lib -lsfml-graphics
-\lsfml-window -lsfml-system
We are now ready to execute the compiled program: