-
I've got a simple file "main.cpp" seen below. I also have all the sfml 2.1 libraries under "C:\SFML-2.1\". My question is: What are the commands to compile, link, and run this project? I'm very comfortable using gcc to compile projects from the command line, but have never done so with any external libraries (such as sfml) before. Any help would be greatly appreciated. Thanks.
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
-
I believe you use -I to indicate include directories, -L to indicate library directories, -D to define macros, and -l for each individual library. I have no idea how to control static vs dynamic linking from the command line.
You should go read the gcc docs/man page or a tutorial. These are all very basic features for any command line compiler so it should be easy to find the information you need.
-
I read over the tutorials section for sfml 2.1 and most of the stuff seems to be for IDE's, with the exception of the linux tutorials. Where might I find relevant content for command line based compiling and linking for Windows?
-
I meant tutorials for gcc itself. Just google them.
Here's one I found just now which seems to cover the stuff you need for this task: http://latedev.wordpress.com/2011/07/09/the-gcc-command-line-part-2/
-
Ok, I did more research and read over the link but I believed the author assumed that I had ".a" files for my library which I don't. Does anybody else have experience with makefile or command line compiling on windows for sfml?
-
.a is the standard extension for static libraries on Linux. Presumably gcc for Windows can handle static Windows libraries, so I wouldn't worry about the different extensions.
-
Ok, I did more research and read over the link but I believed the author assumed that I had ".a" files for my library which I don't. Does anybody else have experience with makefile or command line compiling on windows for sfml?
I'm using MinGW and to build an exe we just do something "g++ -o test-game main.cpp character.cpp -DSFML_STATIC -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-audio-s -static-libstdc++ -std=c++11"
-
@metsuro Where did you get all the -lsfml libraries from?
-
Ok, I believe I'm making progress on this problem. I'm now entering the command "g++ -Ic:\SFML-2.1\include -o main.o main.cpp -DSFML_STATIC -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-audio-s -static-libstdc++" and I get the following errors:
c:/mingw2/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot fi
nd -lsfml-graphics-s
c:/mingw2/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot fi
nd -lsfml-window-s
c:/mingw2/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot fi
nd -lsfml-system-s
c:/mingw2/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot fi
nd -lsfml-audio-s
What am I doing wrong? How do I get the sfml-...-s libraries?
-
well for me I just dropped the library and includes into MinGW's includes and library folders. But I think you can flag libraries to there installed directory by using their path name. so for the library names do -L then the path to the library you want to use instead of -llibrary
-
I dropped all the .lib files into "C:\MinGW\lib" and everything under "C:\SFML-2.1\include" into "C:\MinGW\include\c++\3.4.5". I believe this is even more progress but I'm getting a new set of errors:
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0xd1): undefined
reference to `sf::String::String(char const*, std::locale const&)'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0xf5): undefined
reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int
)'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x12e): undefine
d reference to `sf::Window::Window(sf::VideoMode, sf::String const&, unsigned in
t, sf::ContextSettings const&)'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x15c): undefine
d reference to `sf::Window::close()'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x170): undefine
d reference to `sf::Window::pollEvent(sf::Event&)'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x180): undefine
d reference to `sf::Window::isOpen() const'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x195): undefine
d reference to `sf::Window::~Window()'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x1c1): undefine
d reference to `sf::Window::~Window()'
C:\Users\QUINNM~1\AppData\Local\Temp\ccKJDzvN.o:main.cpp:(.text+0x1e9): undefine
d reference to `sf::Window::~Window()'
collect2: ld returned 1 exit status
-
the lib files would have gone to mingw/lib and the includes are in a folder in mingw/include. I think the fact you put them into the c++ includes is what caused the problem? Maybe?
-
The link order might matter with some compilers. Try putting the system module first, then window, then audio/graphics.
-
The link order might matter with some compilers. Try putting the system module first, then window, then audio/graphics.
Ixrec stop telling the wrong things! You already said that above and it's wrong, the correct order is graphics, window, system.... >:(
I think the fact you put them into the c++ includes is what caused the problem? Maybe?
That's not really an issue, even though it's not advised to do so.
Since you still refuse to build SFML from source with your compiler or make sure the compiler matches the pre-built binaries, I can't help you further. This is not something "optional" but it's required. The compiler version HAVE TO match.