Errors with SFML on Netbeans C++ project

ぐ巨炮叔叔 提交于 2019-12-11 08:08:28

问题


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'

Line 31 is

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

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

EDIT: 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"


回答1:


You have to tell NetBeans three things:

  • Directory with SFML include files
  • Directory with SFML libraries
  • List of SFML libraries to link

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".

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:

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..."

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

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

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.

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



来源:https://stackoverflow.com/questions/58170881/errors-with-sfml-on-netbeans-c-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!