I know similar questions exist, I've seen them, and had no luck with them in my hours of troubleshooting before I decided I must ask.
I am new to C++, learning it via a class. My assignment requires me to use a third party library: SFML. My current coding setup is using Netbeans with the C++ plugin, Windows 10. Previously I used the Cygwin compiler. SFML claims it requires it is used with the exact version of one of the compilers it was compiled with, so I chose MinGW 7.3.0, which I have since installed and continued my attempts with.
In "Project" -> Properties -> Build -> C++ Compiler, I added the includes directory of SFML:
"C:/Users/Drayux/Documents/Coding/NetBeans/Third Party Libraries/SFML-2.5.1/include"
In here, in -> Preprocessor Definitions I also added:
SFML_STATIC
As suggested by the tutorial here.
In "Project" -> Properties -> Build -> Linker, I added the both the lib and bin directories of SFML:
"C:/Users/Drayux/Documents/Coding/NetBeans/Third Party Libraries/SFML-2.5.1/bin"
"C:/Users/Drayux/Documents/Coding/NetBeans/Third Party Libraries/SFML-2.5.1/lib"
Finally, I made sure to manually add each of the libraries individually under the Libraries portion of the Linker section. Also as suggested by the above tutorial.
After doing all this, I can write a standard program that compiles and runs. However, as soon as I begin to include the headers of the SFML library, sometimes the code builds, but does not run, other times it simply does not build all together.
Take this example code:
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
using namespace sf;
int main() {
cout << "Test output line" << endl;
RenderWindow window(VideoMode(200, 200), "Hello there!");
//CircleShape shape(100.f);
return 0;
}
When I attempt to build it under the configuration described above, build is successful, but the run is not. Here are both the consoles.
Build:
cd 'C:\Users\Drayux\Documents\Coding\NetBeans\Lab7C'
C:\Program Files\MinGW\MSYS\bin\make.exe -f Makefile CONF=Debug
"/C/Program Files/MinGW/MSYS/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
"/C/Program Files/MinGW/MSYS/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/lab7c.exe
make.exe[2]: Entering directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
make.exe[2]: `dist/Debug/MinGW-Windows/lab7c.exe' is up to date.
make.exe[2]: Leaving directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
make.exe[1]: Leaving directory `/c/Users/Drayux/Documents/Coding/NetBeans/Lab7C'
BUILD SUCCESSFUL (total time: 3s)
Run:
C:/Users/Drayux/Documents/Coding/NetBeans/Lab7C/dist/Debug/MinGW-Windows/lab7c.exe: error while loading shared libraries: sfml_window-d-2.dll: cannot open shared object file: No such file or directory
RUN FAILED (exit value 127, total time: 74ms)
I have tried the solution adding LD_LIBRARY_PATH to the environment section under Run in the project properties as well, with no luck.
Seeing no other solutions considering my situation, I am left feeling stuck. Any help is greatly appreciated.
Thanks, Liam
After many hours and even more obscenities, I was able to successfully run a basic SFML program and render a basic test window.
I know there is still much for me to learn, but the fix to my solution was the location of my shared libraries (the .dll files.)
I had assumed that referencing them in the linker configuration would have done the job, but it seems that the .a libraries were looking for them in the local directory of the compiled program. As of now I am still unaware how to change this.
As such the solution was manually moving the .dll files in the file system to the directory of the compiled program, in my case:
C:\Users\Drayux\Documents\Coding\NetBeans\SFML Test\dist\Debug\MinGW-Windows
Hope this helps anyone with my issue in the future!