Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Compile Project on Windows Via Cmd  (Read 6465 times)

0 Members and 1 Guest are viewing this topic.

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Compile Project on Windows Via Cmd
« on: April 30, 2014, 08:25:07 pm »
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;
}
 
« Last Edit: April 30, 2014, 09:01:15 pm by mchughq »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Compile Project on Windows Via Cmd
« Reply #1 on: April 30, 2014, 08:32:04 pm »
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.

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #2 on: April 30, 2014, 09:03:28 pm »
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?
« Last Edit: April 30, 2014, 09:07:27 pm by mchughq »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Compile Project on Windows Via Cmd
« Reply #3 on: April 30, 2014, 09:09:28 pm »
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/

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #4 on: April 30, 2014, 11:18:57 pm »
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?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Compile Project on Windows Via Cmd
« Reply #5 on: April 30, 2014, 11:23:19 pm »
.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.

metsuro

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #6 on: May 01, 2014, 12:37:43 am »
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"

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #7 on: May 01, 2014, 02:02:49 pm »
@metsuro Where did you get all the -lsfml libraries from?

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #8 on: May 01, 2014, 04:19:24 pm »
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?

metsuro

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #9 on: May 01, 2014, 04:21:32 pm »
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
« Last Edit: May 01, 2014, 04:27:19 pm by metsuro »

mchughq

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #10 on: May 01, 2014, 04:42:00 pm »
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
 

metsuro

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Compile Project on Windows Via Cmd
« Reply #11 on: May 01, 2014, 07:02:03 pm »
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?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Compile Project on Windows Via Cmd
« Reply #12 on: May 01, 2014, 08:00:10 pm »
The link order might matter with some compilers.  Try putting the system module first, then window, then audio/graphics.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10916
    • View Profile
    • development blog
    • Email
Re: Compile Project on Windows Via Cmd
« Reply #13 on: May 02, 2014, 10:03:05 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/