Mingw cannot find any sfml libraries - c++

I was trying to set up Sfml for my c ++ project by watching tutorials and documentation on how to do this.
I am using Mingw to compile and produce an executable, see how it goes.
#include <SFML/Graphics.hpp>
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;
}
Mingw command line input
g++ mycppfile -o myexefile -IDependencies/include -LDependencies/lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32 -lwinmm -lgdi32
But this error always appears.
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-graphics
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-window
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-system
I've researched many times trying to solve this problem, reviewed the names of the libraries, put all the Sfml dependencies in my project folder and the compiler folder, and also put the Sfml Dlls in the system32 folder and my project folder, but the problem has not yet been solved.
What can I do now?

Related

"Undefined symbols for architecture arm64" building basic SFML project on M1 mac with g++-12

i've been having some trouble trying to compile a very basic SFML project on an M1 mac. the exact error i've been getting is as follows:
Undefined symbols for architecture arm64: "__ZN2sf6StringC1EPKcRKSt6locale", referenced from: _main in cczblZnn.o ld: symbol(s) not found for architecture arm64 collect2: error: ld returned 1 exit status
when running
g++-12 -std=c++20 src/main.cpp -I/Users/rooster/SFML/include -o Ghost -L/Users/rooster/SFML/build/lib -lsfml-audio -lsfml-network -lsfml-graphics -lsfml-window -lsfml-system
so far, nothing i've tried has worked; i've already compiled the libs myself from the source using cmake, i've rearranged the order of the libraries in the build command, among other seemingly inconsequential tweaks in VSCode.
here's what i'm using:
VSCode
g++-12
library files compiled by me with cmake (using unix makefiles)
c++20
SFML 2.5.1_2
and here's my main.cpp:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(sf::Vector2u(200, 200)), "SFML");
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;
}
i'm relatively confident that i'm making some simple mistake. any help is greatly appreciated, and thank you for your time!!
fixed by scrubbing all references to SFML from my computer, installing it again with brew, and then using clang++ instead of compiling with g++ :)

SDL mingw static lib linking errors

I'm trying to compile a simple SDL program using Mingw w64. Here is my code:
test.c
#include "SDL2/SDL.h"
#include <stdio.h>
int main( int argc, char* args[] )
{
SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("SDL2 Window", 100, 100, 640, 480, 0);
if(window==NULL)
{
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
and here is the command I'm using to compile the program:
g++ -o text.exe test.c -I./include -L./lib -lmingw32 -lSDL2main -lSDL2
but when I compile the program, I get hundreds of linking errors that look like this:
./lib/libSDL2.a(SDL_wasapi_win32.o): In function `WASAPI_PlatformInit':
/Users/valve/release/SDL/SDL2-2.0.22-source/foo-x64/../src/audio/wasapi/SDL_wasapi_win32.c:255: undefined reference to `__imp_CoCreateInstance'
I downloaded the library from the second link down in the windows development libraries section on the official SDL website, and took the libraries from the following directory:
SDL2-2.0.22\x86_64-w64-mingw32\lib
The contents of ./lib are:
libSDL2main.a
libSDL.a
What is the problem and how can I fix it?
You have two options, depending on your intent:
If you want to link SDL2 dynamically (this should be your default course of action), you need to add libSDL2.dll.a to your library directory. Then libSDL2.a will be ignored and can be removed. It should just work, no other changes are needed.
If you want to statically link SDL2, you need more linker flags. The exact flags are listed in sdl2.pc in the Libs.private section.
As of SDL 2.0.22, those are: -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid.
Those should be added to the right of -lmingw32 -lSDL2main -lSDL2.
You also might want to add -static to statically link everything, including the standard library. (What's the point of statically linking SDL2, when your program still needs the DLLs of the standard library to work?) It also makes the linker prefer libSDL2.a to libSDL2.dll.a if both are available, meaning you don't need to worry what's in your library directory.

Having trouble getting SFML to work with C++ in Geany on MacOS

I want to get into game development with C++, so I decided to try SFML. However, even after putting all the files in the right places, it won't find the files need.
I followed all the steps on the page https://www.sfml-dev.org/tutorials/2.5/start-osx.php, making sure to put all the frameworks and dylibs in the right folders, but it still won't allow me to use the SFML files
#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;
}
What the program should do is display a black window that can close, but it gives me the error message
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 (and to my knowledge any additional library outside the Standard Template Library) requires the compiler to know where the lib and include folders are stored. In this error instance, it looks like the IDE you're using isn't finding the right path to the folders. It's not listed in the MacOS version, because the tutorial you liked to assumes you're using XCode, which is like Visual Studio for Mac.
From what I can gather, if you're writing your program in a plain text editor, and compiling using makefiles or command line prompts, look at the SFML and Linux article for more complete idea of how to use it. The relevant to this scenario:
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:

Cant run SFML library in netbeans on ubuntu

Hi i want to add SFML for a graphical project in c++ but i get this error when i try to run som basic code:
free(): invalid pointer: 0x00000000009ace48 ***
And in netbeans properties under c++ compiler i have added the SFML/include folder in the include directories
And under linker and additionally library directory i have the sfml/lib folder
And last under linker and in the library i have added sfml-graphics-s-d, sfml-audio-s-d, sfml-network-s-d, sfml-window-s-d and sfml-system-s-d in that order.
This is the code i want to run:
#include <cstdlib>
#include <SFML/Graphics.hpp>
/*
*
*/
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;
}
The SFML window is opening and directly closes and then i get:
RUN FINISHED; Aborted; core dumped; real time: 240ms; user: 20ms; system: 30ms
and the error i told in the start
Do any one know if its me that have added the library wrong or what it can be. thanks for help
Edit:
for now i have solved it by using a makefile and writing it in a text editor but i wonder if i can use same method in netbeans?
This is how my makefile looks and it works but i would like to be able to do it all in netbeans:
all:
g++ -std=c++11 *.cpp -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
clean:
rm -rf *.o sfml-app
I think you have added wrong libraries, you should use "-d" libraries in case of dynamic linking. "-s-d" libraries are being used for static linking. In case you want to use static linking you need to define SFML_STATIC macro for preprocessor in your project. And you should add additional libraries, such as opengl32.lib, and others.

I can't compile example code, SFML

I saw similiar problem, but it didn't solved me my problem.
I can't compile this example code http://www.sfml-dev.org/tutorials/2.3/start-linux.php . I am following this instructions but I still have error:
In one before last step I wrote : g++ sfml.o -o sfml-app -L /home/Documents/SFML/SFML-2.1/lib -lsfml-graphics -lsfml-window -lsfml-system
and I got this:
sfml.o: In function main':
sfml.cpp:(.text+0x12d): undefined reference to sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)' collect2: ld returned 1 exit status
Can somebody help me with that?
It seems like you have't linked the sfml libraries to your program. Further down that page (just after the code snippet), the page further describes:
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
Although you have included the linking in your command line, my best guess is that the linker cannot find the libraries still, which is why sf::RenderWindow is undefined (it's declared, so the compiler knows what it is and thus compiles successfully, but cannot link properly because the linker can't find a reference for it)
I checked the path and folder with libraries and libs are there:
http://i.imgur.com/bTk7QCZ.png
But I still can't linkt it correctly.. I have installed SFML in my standard path (usr/lib)
http://i.imgur.com/Mzp9tMY.png
and after compile it shows the same error.
Error:
sfml.o: In function main':
sfml.cpp:(.text+0x12d): undefined reference tosf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
collect2: ld returned 1 exit status
My code it's the same as example code:
#include <SFML/Graphics.hpp>
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;
}