So I'm trying to run an example SFML program on my Windows laptop. If relevant, the source code is on this page.
So first I make the .o file using this command -
g++ -c a.cpp -ISFML/SFML/include
Where a.cpp is the main file, and my SFML package is located in SFML/SFML.
Then I compile using this command -
g++ a.o -o a -LSFML/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
When I first ran the program I got the errors about not being able to find certain dlls, sfml-graphics-2 etc. So I found them and put them next to the exe. But now when I run, I get this weird error:
The procedure entry point
_ZNSt7__cxx1112basic_stringSt11char_traitsIcESalcEE7reserveEj could not be located in the dynamic link library.
What is going on here?
As the SFML download page states, You could be using the wrong version of the compiler, other library versions of SFML that you have not removed from your working directory that could mismatch between code and linker. Worst case, if your compiler is not listed there, you have to compile SFML yourself:
Get CMake. Get the source code for 2.4.2 by going to the bottom of the SFML download page. Follow this guide on SFML's GitHub repo. Alternatively, you could use the guide on SFML's page but it is for an older version. It might answer some questions that the first guide misses.
Ones CMake have generated the makefiles, you're on your way to build SFML.
Good luck!
I've had this problem for so long so I just wanted to help someone out who had the same problem. I have a windows 10 FYI and MinGW-w64 8.1.0 (if it doesnt work try a 32 bit mingw instead)
for a debug mode (debug is when your still working on the game and would like command prompt to open whenever you run it)
(make sure your in the right directory first by doing "cd")
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -g -m64 -Wall &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics -lsfml-window -lsfml-system
The code above when placed in command will compile everything for you if its all in the same directory so make sure you keep an eye out for that
and now for release mode (if you dont want command prompt to show up)
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -O3 -m64 &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics lsfml-window -lsfml-system -mwindows
Noticed all I added was the -mwindows and the -O3 aswell as removing -g and -Wall which are not necessary since we wont be using command prompt
Make sure to go to SFML/bin and take all the .dlls and put it into the same directory has your .exe sorry xd
Hope this helped.
Related
I found this example over the internet, on how to use librsvg, it compiles on mingw, and it runs, but it does not run outside mingw context. (For example going to explorer and double clicking the file).
The error is:
the code execution cannot proceed because librsvg-2-2.dll was not found. reinstalling the program may fix this problem.
the code execution cannot proceed because libcairo-2.dll was not found. reinstalling the program may fix this problem.
Now, I want to run this code outside mingw, but it doesn't find the cairo and librsvg dlls, (I have no .dlls only .dll.a files), running it inside mingw works perfectly.
These are my compilation flags. (I changed the name from main.c to main.cpp)
How can I make this code run, in this case?
g++ -c main.cpp -o main.o -I/mingw64/include/librsvg-2.0 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include/cairo -I/mingw64/include/gdk-pixbuf-2.0
g++ main.o -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread /mingw64/lib/libcairo.dll.a /mingw64/lib/librsvg-2.dll.a -o main.exe
First I tried just downloading what you get after searching mingw64 windows. That didn't work. While searching for a solution I came across this, where the answer includes what seems to be a legit version of mingw64.
This being probably the third or fourth mingw64 I've downloaded, I was happy to see a g++64.exe which I assumed would take care of everything. It doesn't, after compiling with g++64 -o hello.exe -c hello.cpp and running hello I get an error saying This version of [...]\hello.exe is not compatible[...].
What am I doing wrong? I've tried -m64. Is there some additional setting I need to change? Should I post what I get for g++64 -v?
Your command is wrong, you're not creating a .exe file, but an object file that you need to link to produce an executable. Do it like this:
g++64 -o hello.exe hello.cpp
The -c argument tells the compiler to just compile but not link your code. You can do the above in 2 steps, compile and link:
g++64 -c -o hello.o hello.cpp
g++64 -o hello.exe hello.o
I have been trying to compile a simple C++ program with the googletest libraries. I have gotten this to work using g++, however the project will soon become large and I want to be able to automate the compilation using make. I installed GNU make for windows which I have tested on another program and it works. However when I try and use make to compile my googletest project I get the following error:
ld.exe: cannot find -lgtest
Here is the contents of my makefile:
all: test.exe
test.exe: main.cpp
g++ -o test.exe .\main.cpp .\sample1.h .\sample1.cc .\sample1_unittest.cc -ID:\...\gtest\include -LD:\D...\gtest\lib\ -lgtest_main -lgtest -Wall
clean:
rm test.o test.exe
The weird thing is that if I run the same code from the command line, as follows, it works perfectly an I end up with my test.exe.
g++ -o test.exe .\main.cpp .\sample1.h .\sample1.cc .\sample1_unittest.cc -ID:\...\gtest\include -LD:\D...\gtest\lib\ -lgtest_main -lgtest -Wall
Does anyone know what this could be caused by and how to fix it?
Ok, I managed to find the problem! I'm still not sure why this is the case but apparently in make you have to specify paths like so:
-LD:\...\gtest\lib
And not like this (note the extra ):
-LD:\...\gtest\lib\
The error message makes sense since it must have been trying to search for the library in a path that looks something like this:
-LD:\...\gtest\lib\\
Which would obviously not work. I guess what threw me off was that the code worked when executed from the command line. It took me a while to see the inconstancy in my path specification and figure out that make doesn't want the extra '\'. Hopefully this will prevent someone else for wasting as much time as I did.
I know that it is possible to make .dylib files with g++ compiler on the MacOSX platform. I want to make a .framework grouping headers and library. Is it possible to use g++ compiler for that? If not is there any command line interface tool for that purpose? (I want to avoid using xCode if possible)
I know you said you wanted to avoid using Xcode, but here is a nice link https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html Follow the instructions ONLY for creating the framework, you'll get a .framework file. With the .framework file that you can place anywhere in your computer, you can compile outside of Xcode like so.
if in your current directory:
cwd=$(pwd)
g++ -Wall somefiles.c -o run "-I $(pwd)/some/path/name.framework -F $(pwd)/some/path/ -framework name"
otherwise
g++ -Wall somefiles.c -o run "-I /full/path/name/name.framework -F /full/path/name/ -framework name"
I'm trying to run the standard example from the SFML Library in Linux. I have download the Rep. from Github, build and install it with CMake. I have build 2 Libraries for static/shared debug, and 2 Libraries for static/shared Release.
The problem now, I don't know much about compiling in the Terminal. I use the commands I found on the SFML Website:
g++ -c test.cpp
g++ test.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
that works. I can run my SFML Application by ./sfml-app and double-click. But other people who (who have not installed SFML) using Linux cant. And I think it's because the compiler does not use the static libraries. Of course - how he could? It's not written in the command. But I also don't know how to write it.
The name of the static-release libraries is for example
libsfml-graphics-s.a
libsfml-window-s.a
libsfml-system-s.a
what must I write in g++, that he is using this libs when he link the stuff?
To link your program against the static versions of the libraries, you would do the following:
g++ test.o -o sfml-app libsfml-graphics-s.a libsfml-window-s.a libsfml-system-s.a
(Assuming, of course, that these files are in your local directory.)