SFML community forums

Help => General => Topic started by: Dante on July 18, 2020, 12:08:50 pm

Title: Compiling simple SFML Project with MSVC CL Compiler in Command Prompt
Post by: Dante on July 18, 2020, 12:08:50 pm
Greetings fellow developers,

i am having trouble with compiling a simple SFML Project using the command line version of Microsoft's VisualC++ Compiler. The compilation process happens inside "x64 Native Tools Command Prompt for VS 2019", which is basically a batch file provided by the visual studio 2019 installation that sets up the command line environment for me to use the cl compiler.

The problem is the following Debug Assertion Failure when running the .exe file. My folder structure is also in the following link.

https://imgur.com/a/RBcYE1M (https://imgur.com/a/RBcYE1M)

This is the code I am compiling...
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

I use the following command to compile the program...
cl /I SFML-2.5.1\include main.cpp SFML-2.5.1\lib\sfml-graphics-d.lib SFML-2.5.1\lib\sfml-system-d.lib SFML-2.5.1\lib\sfml-window-d.lib
 

The first argument says where to look for include files. After that is the file to compile (main.cpp). The rest of the arguments are for linking the sfml dlls.

I use the SFML Version "Visual C++ 15 (2017) - 64-bit".
Title: Re: Compiling simple SFML Project with MSVC CL Compiler in Command Prompt
Post by: MarbleXeno on July 18, 2020, 01:57:06 pm
Did you copy and pasted all the dlls from sfml/bin to your .exe folder?
It's says about invalid argument, maybe something with compiler arguments?
Title: Re: Compiling simple SFML Project with MSVC CL Compiler in Command Prompt
Post by: Dante on July 18, 2020, 02:15:22 pm
Did you copy and pasted all the dlls from sfml/bin to your .exe folder?
If you look at the first image on the imgur link you can see that I have sfml-graphics-d-2.dll, sfml-system-d-2.dll and sfml-window-d-2.dll in the same directory as the main.exe file.

It's says about invalid argument, maybe something with compiler arguments?
The error appears when running the main.exe file and it appears in sfml-graphics code. I think the "invalid argument" is referring to c++ code inside the dll. But maybe the reason why that error appears is because i dont have a certain compiler flag or the sfml version and the compiler version are a mismatch.
Title: Re: Compiling simple SFML Project with MSVC CL Compiler in Command Prompt
Post by: Dante on July 19, 2020, 01:04:10 pm
The problem is somewhere in the compiler-/linker-options. An equivalent Visual Studio 2019 solution builds and runs the project no problem. So I just copied the compiler and linker options out of the property windows. Now it looks like this...

@ECHO OFF
cl /JMC /permissive- /GS /W3 /Zc:wchar_t /I"C:\Programming\Projekte\DSAVis\SFML-2.5.1\include"^
 /ZI /Gm- /Od /sdl /Fd"vc142.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE"^
 /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /MDd /FC /EHsc /nologo^
 /diagnostics:column^
 main.cpp^
 /OUT:".\main.exe" /MANIFEST /NXCOMPAT^
 /PDB:".\main.pdb" /DYNAMICBASE^
 "SFML-2.5.1\lib\sfml-graphics-d.lib" "SFML-2.5.1\lib\sfml-system-d.lib" "SFML-2.5.1\lib\sfml-window-d.lib" "kernel32.lib" "user32.lib"^
 "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib"^
 "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X64 /INCREMENTAL^
 /PGD:".\main.pgd" /SUBSYSTEM:CONSOLE^
 /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:".\main.exe.intermediate.manifest"^
 /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
 

I dont really know why it works tho.