Netbeans C++ 项目上的 SFML 错误 [英] Errors with SFML on Netbeans C++ project

查看:60
本文介绍了Netbeans C++ 项目上的 SFML 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Netbeans(在 Windows 上)开发 C++.我正在努力让 SMFL 发挥作用.

I'm working on a c++ with Netbeans (on Windows). I'm trying to get SMFL to work.

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) 
{
    RenderWindow window(VideoMode(600, 800), "TITLE");
    cout << "Hello World!";

    return 0;
}

当我启动应用程序时,我收到以下错误.

When I launch the application I get the following errors.

main.cpp:31: undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'
main.cpp:31: undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'
main.cpp:31: undefined reference to `__imp__ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
main.cpp:31: undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
main.cpp:31: undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'

第 31 行是

RenderWindow window(VideoMode(600, 800), "TITLE");

我在 C++ 编译器中添加了 SFML/include 目录,在链接器中添加了 SFML/lib,你能帮我吗?

I added SFML/include dir to c++ compiler and SFML/lib to linker, can you help me?

在重试添加 lib 和包含折叠后,现在我得到:加载共享库时出错:?:无法打开共享对象文件:没有这样的文件或目录"

after retrying to adding lib and include foldes, now I get: "error while loading shared libraries: ?: cannot open shared object file: No such file or directory"

推荐答案

你必须告诉 NetBeans 三件事:

You have to tell NetBeans three things:

  • 包含 SFML 包含文件的目录
  • 包含 SFML 库的目录
  • 要链接的 SFML 库列表

看起来您已经知道如何做 #1,但我会重复所有内容以防万一.所有这些设置都应该使用项目属性来完成 - 右键单击​​您的项目名称,然后打开属性设置窗口.您需要在两个窗格中添加内容 - C++ Compiler"和Linker".

It looks like you already know how to do #1, but I'll repeat everything just in case. All this setup should be done using the project properties - right-click on your project name, then open the properties setup window. You'll need to make additions in two panes - "C++ Compiler" and "Linker".

C++ 编译器"窗格是您首先需要的.找到包含目录"这一行,然后单击带有三个点的方块(目录选择器)——然后添加 SFML包含"目录.在我的情况下,此窗格如下:

The "C++ Compiler" pane is what you need first. Find the line "Include Directories" and click on the square with three points (directory chooser) - then add the SFML "include" directory. This pane in my case is below:

链接器"窗格是下一个.找到附加库目录"并添加 SFMLlib"目录 - 也使用目录选择器.然后找到Libraries"行并添加至少三个库——sfml-graphics"、sfml-window"和sfml-system".为此,您需要使用稍微复杂的选择器,您需要的按钮是添加库..." - 请参阅此处的第三张图片.库的顺序很重要.在我的情况下,此窗格如下:

The "Linker" pane is the next one. Find the "Additional Library Directories" and add the SFML "lib" directory - using also the directory chooser. Then find the "Libraries" line and add at least three libraries - "sfml-graphics", "sfml-window" and "sfml-system". For that you need to use slightly more complex chooser, the button you need is "Add Library..." - please see the third picture here. Order of libraries is important. This pane in my case is below:

这是库选择器 - 使用按钮添加库..."

This is libraries chooser - use the button "Add Library..."

同样在您的示例中,您需要为 SFML 类型使用前缀sf::":

Also in your example you need to use prefix "sf::" for SFML types:

sf::RenderWindow window(sf::VideoMode(600, 800), "TITLE");

添加.看起来(从评论中)编译和链接问题已经解决,但是应用程序仍然找不到 SFML 动态库.此问题在 NetBeans 之外 - 您只需要确保已将带有动态库的 SFML 目录添加到 Windows 系统路径中.

ADDITION. It looks like (from comments) that compilation and linking problems have been resolved, however the application still couldn't find SFML dynamic libraries. This problem is outside of NetBeans - you just need to make sure, that the SFML directory with dynamic libraries has been added to the Windows system path.

这个目录名可能很长,所以添加到路径时很容易打错.有一个简单的方法来验证 - 一个 Windows 工具 where.exe.有些 Windows 系统没有这个工具——所以你可以通过 path 命令输出当前路径,然后将路径中与 SFML 相关的部分作为参数复制粘贴到 Unix ls 命令(在 MinGW MSYS 环境中).通常ls 会显示SFML 动态库的列表(带有dll 扩展名).

This directory name can be long, so it's easy to mistype it when adding to the path. There is a simple way to verify that - a Windows tool where.exe. Some Windows systems don't have this tool - so you can output the current path by the path command, and then copy-paste the SFML-related part of the path as an argument to the Unix ls command (it's in the MinGW MSYS environment). Normally the ls will show you the list of SFML dynamic libraries (with dll extension).

这篇关于Netbeans C++ 项目上的 SFML 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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