SFML community forums

Help => General => Topic started by: flux on December 11, 2014, 09:21:42 am

Title: How to compile with msvc on the command line?
Post by: flux on December 11, 2014, 09:21:42 am
Hello,

I'm having trouble linking with SFML on the command line when compiling with MSVC.
It works fine with GCC, but MSVC gives linking errors.

I made a test program just including system as it shouldn't depend on anything else.
"System does not depend on anything and can be used by itself." from https://github.com/SFML/SFML/wiki/FAQ#grl-dependencies

sf_main.cpp
#include <SFML/System.hpp>

int main()
{
    sf::Clock clock;
}
 

command line:
cl -Z7 sf_main.cpp -DSFML_STATIC -Id:\SFML\vc11_64\SFML-2.1\include /link d:\SFML\vc11_64\SFML-2.1\lib\sfml-system-s-d.lib
 

here is the output:
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

sf_main.cpp
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xlocale(337) : warning C4530: C++ exception handler
used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:sf_main.exe
/debug
-libpath:d:\SFML\vc11_64\SFML-2.1\lib
sfml-system-s-d.lib
sf_main.obj
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __cdecl type_info::type_info(class type_info const &)" (??0type
_info@@AEAA@AEBV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __cdecl type_info::operator=(class type_info
const &)" (??4type_info@@AEAAAEAV0@AEBV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
sf_main.exe : fatal error LNK1169: one or more multiply defined symbols found
 

Why does this happen?
Title: AW: How to compile with msvc on the command line?
Post by: eXpl0it3r on December 11, 2014, 09:28:18 am
The SFML library that you're trying to link uses a different runtime library, make sure to use the same when building SFML and when building your application.

For static linking also see this:  https://github.com/SFML/SFML/wiki/FAQ#build-link-static
Title: Re: AW: How to compile with msvc on the command line?
Post by: flux on December 11, 2014, 09:36:18 am
The SFML library that you're trying to link uses a different runtime library, make sure to use the same when building SFML and when building your application.

For static linking also see this:  https://github.com/SFML/SFML/wiki/FAQ#build-link-static
I don't build SFML, I'm just trying to link to it.

The only dependency for system is winmm, wich I added to link to. The output is still the same.
Title: AW: How to compile with msvc on the command line?
Post by: eXpl0it3r on December 11, 2014, 09:41:02 am
I told you that you nees to use the same runtime libraries...

Where did you get the libraries then? You are aware that you can't use the VS 2012 libraries with VS 2013, right?

If you link against the debug SFML library which uses the debug runtine library, you also have to use the debug runtine library. Same goes for the static library.

Additionally if link against the debug library you need to also build your application in debug mode.