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!
Related
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
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!
I am trying to follow an SDL tutorial and compile a c++ file that uses SDL. I am on windows 10, and was originally using MinGW.
Past a certain point I realized my MinGW installation was having issues unrelated to SDL, so I switched to MinGW-w64 instead, which cleared up the non-SDL issue, but now when I try to compile anything with SDL it can't find lSDL2 or lSDL2main. It does, however, skip over various files saying that they are incompatible.
I suspect it might be a 32 bit/64 bit incompatibility, but I'm not sure how this is happening, as even when I explicitly make sure to use the 32 bit g++ compiler, the issue persists. For reference, the command I put into the command prompt is
x86_64-w64-mingw32-g++ 04_key_presses.cpp
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
and the error messages are
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib\libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.dll.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib\libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.dll.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
Your compiler is x86_64-w64-mingw32-g++. That's the 64-bit compiler.
The 32-bit compiler is i686-w64-mingw32-g++.exe. The 64-bit linkage
that you are attempting with:
x86_64-w64-mingw32-g++ 04_key_presses.cpp \
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w \
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
skips your incompatible 32-bit SDL2 libraries.
The 64-bit compiler can build either 64- or 32-bit targets, building
64-bit by default. To target 32-bit, pass -m32 for both compilation
and linkage. As you doing both with one command you need only pass it once:
x86_64-w64-mingw32-g++ 04_key_presses.cpp -m32 \
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w \
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
I have a very similar issue to the one presented in how to dynamically link to local copy of libc.so.6, libstdc++.so.6 on system with old version of gcc and I followed the answer provided there. To summarize, the issue is that I have code written using C++11 and the cluster sysadmin won't upgrade the gcc compiler to a version which supports C++11. I did a manual install of gcc4.9 in my home directory (using --prefix=$HOME). I compile my code with the following flags:
-I/home/stroberg/include -L/home/stroberg/lib -lc -lstdc++ -llapack -lblas -O3 -std=C++11
I also set
export LD_LIBRARY_PATH=/home/stroberg/lib:$LD_LIBRARY_PATH
The compilation goes fine until it gets to the linking stage, where I get the following errors:
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /home/stroberg/lib/libgcc_s.so when searching for -lgcc_s
Any ideas what could be causing the problem? I'm also using the armadillo package (also a local version) is that makes any difference.
Thanks.
I got it working, so I figured I should post what I did. Compiling with
-I$(HOME)/include -L$(HOME)/lib -lblas -llapack -lgsl -lglsblas -O3 -std=c++11
seemed to do the trick. Wish I knew exactly what fixed the problem, but I hope this helps.
When linking a project I am working on, the linker gives the following errors:
/usr/bin/ld: ../Includes and Libs/lib/libsfml21rca.a(SoundFile.o): undefined reference to symbol 'sf_read_short##libsndfile.so.1.0'
/usr/bin/ld: note: 'sf_read_short##libsndfile.so.1.0' is defined in DSO /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so so try adding it to the linker command line
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so: could not read symbols: Invalid operation
The thing is, libsndfile.so is already linked before libsfml21rca.a, so I have no idea where the problem is.
I'm using Code::Blocks 10.05
Thanks for help in advance
EDIT:
Here is the linking command:
g++ -L"Includes and Libs/lib" -L"Includes and Libs/lib/raknet3_731" -L"Includes and Libs/lib/d3d_new/x86" -L"Includes and Libs/lib/ogg" -L"Includes and Libs/lib/sdl" -LBullet/lib -o (filename) ...(a whole lot of object files) -lGLEW -lglfw -lGL -lGLU -lpthread -lopenal -ljpeg -lfreetype -lsndfile -lXrandr -lsfml-system -lsfml-window -lsfml-audio ../Bullet/lib/LinearMath.lib ../Bullet/lib/BulletCollision.lib ../Bullet/lib/BulletDynamics.lib "../Includes and Libs/lib/raknet3_731/RakNetLibStaticDebug.lib" "../Includes and Libs/lib/libsfml21rca.a" ../../../../../../home/msabol/Desktop/SFML/sfml2st/sfmlVideo/sfmlVideo/bin/Release/libsfmlVideo.a ../../../../../../home/msabol/Desktop/SFML/sfmlVideo/bin/Release/libsfmlVideo.a
The linker only runs one pass over the library files. So if you have something in Library A that needs something in Library B, you need to have g++ objects... -llibA -llibB, if you use g++ objects... -llibB -llibA it will fail in the manner you show.
So, in your case, put the -lsndfile after "../Includes and Libs/lib/libsfml21rca.a".
(And whose idea was it to put spaces in a the "Includes and Libs" directory - not the best idea I've seen...)