So I've recently transitioned to compiling through the cmd but when I tried to setup SFML, I ran into a problem.
I used this tutorial: http://verra.xyz/howto/sfml.html following it step by step. After I did everything, I got the following error messages after compiling:
E:\Cpp\Random>g++ sfmlTest.cpp -o hello -lsfml-graphics -lsfml-window -lsfml-system
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-graphics
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-window
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-system
collect2.exe: error: ld returned 1 exit status
I'd be really thankful if someone was to help me. Cheers!
Related
I am trying to install sfml and run it with mingW. This is the first time I use it so I was following a tutorial (https://www.youtube.com/watch?v=Ljhpsdz8Ouo). I followed it step by step until the end, where he compiles a test script to check if it works, his does, mine doesn't.
I can't figure out why, but it seems to be a problem with the paths because the output says it can't find some files.
g++ -Isrc/include -c main.cpp
g++ main.o -o main -Lsrc/lib -lsfml-graphics -lsfml-window -lsfml-system
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-graphics.a when searching for -lsfml-graphicsC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib\libsfml-graphics.a when searching for -lsfml-graphicsC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-graphics.a when searching for -lsfml-graphicsC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-graphics: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-graphics.a when searching for -lsfml-graphicsC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-window.a when searching for -lsfml-window
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib\libsfml-window.a when searching for -lsfml-window
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-window.a when searching for -lsfml-window
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-window: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-window.a when searching for -lsfml-window
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-system.a when searching for -lsfml-system
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib\libsfml-system.a when searching for -lsfml-system
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-system.a when searching for -lsfml-system
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-system: No such file or directory
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible src/lib/libsfml-system.a when searching for -lsfml-system
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:7: link] Error 1
These are my files:
My Makefile:
all: compile link
compile:
g++ -Isrc/include -c main.cpp
link:
g++ main.o -o main -L src/lib -lsfml-graphics -lsfml-window -lsfml-system
And the script I'm trying to run is the test script from the documentation. Note that this is my first time using Makefile, but the main.o file is created properly.
I hope someone can help me, it's probalby an installation mistake. Thanks for your time.
In my experience this can be caused by using the improper compilers, on the SFML website it states:
If you download these compilers and add them to your path variable (being careful to remove what might already be there to avoid a conflict) I am willing to bet you will be on your way.
I might also suggest using CMake as it makes the whole 'makefile' process a bit easier. It is an extra step, but in the future it will serve you well as your project expands. I have written a tutorial on this subject here if you would like to see how that might look in practice. Good luck and hope this helps!
I am trying to compile a simple Hello World program in C++ on jGrasp but I am getting the following error
----jGRASP exec: g++ -g -o jGHello.exe jGHello.cpp -lglu32 -lfreeglut -lopengl32
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lfreeglut
collect2.exe: error: ld returned 1 exit status
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
I suppose that jGrasp is unable to compile the program due to -lfreeglut being missing. But I am unable to find any mention of it on the internet.
Compiler cant find -lfreeglut, its could be cause two reasons:
It doesnt exits (look if its already install)
Its not on libs path, then u ve to install it on libs path, or tell C++ compiler where is this lib, u can do it like -L /pathToLib
Ej: g++ -g -o jGHello.exe jGHello.cpp -lglu32 -lfreeglut -lopengl32 -L /pathToLib
I've been learning to use visual studio code recently to code in C++ since Visual Studio 2019 were having alot of problems with the Windows SDK.Recently i've succefully link and run an SFML/C++ file on VS Code using MinGw and CMake Gui.Here's the 'Makefile' file that i used to link:
Makefile(no extension):
all:
g++ main.cpp -o main.exe -DSFML_STATIC -I F:\SFMLPrj\StarFirestc\Prefixes\include -L F:\SFMLPrj\StarFirestc\Prefixes\lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype
for the .cpp file(main.cpp) i've tried copy the sample code on https://www.sfml-dev.org/ to test the linking process and everything works fine.
But then when i try to include another header(of a class called 'Game')into to main.cpp and link the following errors occurs in MinGW:
F:\SFMLPrj\StarFirestc>mingw32-make all
g++ main.cpp -o main.exe -DSFML_STATIC -I F:\SFMLPrj\StarFirestc\Prefixes\include -L F:\SFMLPrj\StarFirestc\Prefixes\lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x16): undefined reference to `Game::Game()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x21): undefined reference to `Game::Run()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x31): undefined reference to `Game::~Game()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x42): undefined reference to `Game::~Game()'
collect2.exe: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
I have searched for 4 hour and still have no idea how to link 2 or more file using MinGW.Can anyone help me ?
I already installed libboost, and I made sure the certain library already located in /usr/lib/x86_64-linux-gnu/. I already called #include <boost/filesystem.hpp> in my .cpp file. But, whenever I run this,
g++ -Wall -g -o result.out main.cpp -L/usr/lib/x86_64-linux-gnu -lboost_system
The system gave me
/usr/bin/x86_64-linux-gnu-ld: cannot find -lboost_system
collect2: error: ld returned 1 exit status
Realizing it mentioned ld, I checked my /etc/ld.so.conf.d, and I found a configuration file linked to /usr/lib/x86_64-linux-gnu/. I ran sudo ldconfig, then ran the g++ command again, same result.
I don't know what I'm going to do next, so can anyone help me? I'll provide another information related to this if anyone ask. Thanks in advance.
I am trying to build a project using Boost's Asio , but I am getting linking error:
g++ -o homework main.o -L/usr/lib64/qt-3.3/lib -L/usr/X11R6/lib64 -L/home/student/boost_1_46_1/libs -lboost_system -lqt-mt -lXext -lX11 -lm
/usr/bin/ld: cannot find -lboost_system
collect2: ld returned 1 exit status
make: *** [homework] Error 1
How can I resolve the problem?
I think it's a typo. You said -l boost_system in command line, while it should be -lboost_system.
Update:
Nope! I get my answer back. Just found that it's OK to pass -l <libname>. In fact it's equal to -l<libname>. As others said, double-check paths.