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

Author Topic: How to compile with msvc on the command line?  (Read 2299 times)

0 Members and 1 Guest are viewing this topic.

flux

  • Newbie
  • *
  • Posts: 2
    • View Profile
How to compile with msvc on the command line?
« 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?
« Last Edit: December 11, 2014, 09:30:57 am by flux »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: How to compile with msvc on the command line?
« Reply #1 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

flux

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: AW: How to compile with msvc on the command line?
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: How to compile with msvc on the command line?
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything