Compiling SFML for Visual Studio 2012 using CMake

2019-03-05 01:48发布

问题:

Before I start the question, I just want to make clear that I want SFML with static linkage to runetime because I want to statically link the mvsc.dlls so noone has to install them or to relly on them.

I sucessfully made this work for the source from website, but it has the very same problem.

To the problem. I downloaded SFML from github as zip, unpacked it. I then started cmake-gui via Visual Studio Command prompt and I filled the paths correctly, and configurated it so that BUILD_SHARED_LIBS is unchecked and SFML_USE_STATIC_STD_LIBS is checked. After that I generated the code.

Here the problem begins. When I try to compile any of the projects generated(ALL_BUILD, ZERO_CHECK, SFML) it generates all libs but when it moves past that(dont know how it works inside) Visual Studio pops error: "Unable to Start Program 'H:/SFML/SFML-Static/Release/ALL_BUILD'." which is nonexistant(both folders Release and Debug are empty). I think that because of this I dont get the include folder(it is not generated and there is no flag in CMake project for it).

Is there a way to fix this? Or am I supposed to copy the include folder from the github source?

Additionally, I dont know if I am supposed to run projects inside src/SFML, but when I try to(either INSTALL or sfml-system for instance) compile them(they are both Visual projects) it pops error that "file ' ' is missing"

Some insight would be nice, because I spent 2 hours with this already.

回答1:

It sounds like you're confused about the proper usage of the project(s) generated by CMake.

Here the problem begins. When I try to compile any of the projects generated(ALL_BUILD, ZERO_CHECK, SFML) it generates all libs but when it moves past that(dont know how it works inside) Visual Studio pops error: "Unable to Start Program 'H:/SFML/SFML-Static/Release/ALL_BUILD'." which is nonexistant(both folders Release and Debug are empty).

Typically, the way you compile your project is to simply hit the green arrow up at the top bar. This compiles your program, generating an executable. Then, it runs that exectuable.

When you hit the green arrow in VS in the SFML project, it still compiles it. It sounds like this step is succeeding, since you say the libraries are generated. Next, it tries to run the generated executable. However, SFML does not generate an executable, because it is a library. It's just a collection of classes and functions for you to use; there's no code to run. Thus, when VS tries to run the generated executable, it errors, because one wasn't generated in the first place.

The way to "fix" this is, instead of hitting the run button, simply right click on the SFML project and hit "build". This will compile, but not attempt to run, the project.

I think that because of this I dont get the include folder(it is not generated and there is no flag in CMake project for it). Is there a way to fix this? Or am I supposed to copy the include folder from the github source?

Visual Studio should not need to generate the include folder. It would be the exact same as the one in the github source. However, you shouldn't copy this folder to your own project either. The proper way to add include directories to go to Tools / Options / Projects and Settings / VC++ Directories / Include files and add the SFML includes directory to this property. Your project will then know where to look for includes, and things like #include "SFML/System.hpp" will work.

Before I start the question, I just want to make clear that I want SFML with static linkage to runetime because I want to statically link the mvsc.dlls so noone has to install them or to relly on them.

You probably don't need to compile SFML yourself to do this. I believe you can switch to using static libraries in your own project by going to configuration properties / c/c++ / code generation / [Runtime Library] and changing that option; then, you don't have to rely on compiling a version of SFML with the static C++ libraries every time a new version comes out.