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

Author Topic: SFML's example can't be build anymore with static std libs and VS10+11  (Read 10696 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11006
    • View Profile
    • development blog
    • Email
So I was creating a small batch file to compile all the different variants of SFML 2 with Visual Studio 11 and everything worked fine until I checked the 'build examples' box.
The examples build fine for the static and dynamic libraries which use the dynamic runtime libraries build fine, but as soon as you try to build the examples with the static runtime library you get many unresolved symbols and other errors, here the full list for the OpenGL example:
Linking CXX executable opengl-d.exe
sfml-graphics-s-d.lib(ftbase.obj) : warning LNK4217: locally defined symbol "_strrchr" imported in function _raccess_make_file_name
sfml-graphics-s-d.lib(type1.obj) : warning LNK4049: locally defined symbol "_memmove" imported
sfml-graphics-s-d.lib(truetype.obj) : warning LNK4049: locally defined symbol"_memmove" imported
sfml-graphics-s-d.lib(ftlzw.obj) : warning LNK4049: locally defined symbol "_memmove" imported
sfml-graphics-s-d.lib(ftbase.obj) : warning LNK4217: locally defined symbol "_memmove" imported in function _FT_GlyphLoader_CheckPoints
sfml-graphics-s-d.lib(sfnt.obj) : warning LNK4049: locally defined symbol "_memmove" imported
sfml-graphics-s-d.lib(pshinter.obj) : warning LNK4049: locally defined symbol"_memmove" imported
sfml-graphics-s-d.lib(type1cid.obj) : warning LNK4049: locally defined symbol"_memmove" imported
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_fwrite" imported in function _empty_output_buffer
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_free" imported in function _empty_mem_output_buffer
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4049: locally defined symbol"_free" imported
sfml-graphics-s-d.lib(jmemnobs.obj) : warning LNK4049: locally defined symbol"_free" imported
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_malloc" imported in function _empty_mem_output_buffer
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4049: locally defined symbol"_malloc" imported
sfml-graphics-s-d.lib(jmemnobs.obj) : warning LNK4049: locally defined symbol"_malloc" imported
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_ferror" imported in function _term_destination
sfml-graphics-s-d.lib(jdatadst.obj) : warning LNK4217: locally defined symbol"_fflush" imported in function _term_destination
sfml-graphics-s-d.lib(jerror.obj) : warning LNK4217: locally defined symbol "_exit" imported in function _error_exit
sfml-graphics-s-d.lib(jerror.obj) : warning LNK4217: locally defined symbol "___iob_func" imported in function _output_message
sfml-graphics-s-d.lib(jerror.obj) : warning LNK4217: locally defined symbol "_sprintf" imported in function _format_message
sfml-graphics-s-d.lib(bdf.obj) : warning LNK4049: locally defined symbol "_sprintf" imported
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_realloc" imported in function _ft_realloc
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fclose" imported in function _ft_ansi_stream_close
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fread" imported in function _ft_ansi_stream_io
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fseek" imported in function _ft_ansi_stream_io
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_ftell" imported in function _FT_Stream_Open
sfml-graphics-s-d.lib(ftsystem.obj) : warning LNK4217: locally defined symbol"_fopen" imported in function _FT_Stream_Open
sfml-graphics-s-d.lib(sfnt.obj) : warning LNK4217: locally defined symbol "_memchr" imported in function _tt_face_find_bdf_prop
sfml-graphics-s-d.lib(cff.obj) : warning LNK4049: locally defined symbol "_strncmp" imported
sfml-graphics-s-d.lib(type1.obj) : warning LNK4049: locally defined symbol "_strncmp" imported
sfml-graphics-s-d.lib(sfnt.obj) : warning LNK4217: locally defined symbol "_strncmp" imported in function _tt_face_find_bdf_prop
sfml-graphics-s-d.lib(psaux.obj) : warning LNK4217: locally defined symbol "_strncmp" imported in function _afm_parser_parse
sfml-graphics-s-d.lib(type42.obj) : warning LNK4049: locally defined symbol "_strncmp" imported
sfml-graphics-s-d.lib(type1cid.obj) : warning LNK4049: locally defined symbol"_strncmp" imported
sfml-graphics-s-d.lib(type42.obj) : warning LNK4217: locally defined symbol "_atol" imported in function _t42_get_name_index
sfml-graphics-s-d.lib(type1cid.obj) : warning LNK4049: locally defined symbol"_atol" imported
sfml-graphics-s-d.lib(ftbase.obj) : error LNK2019: unresolved external symbol "__imp__longjmp" referenced in function "_ft_validator_error".
sfml-graphics-s-d.lib(smooth.obj) : error LNK2001: unresolved external symbol "__imp__longjmp".
sfml-graphics-s-d.lib(ftbase.obj) : error LNK2019: unresolved external symbol "__imp__strncpy" referenced in function "_raccess_make_file_name".
sfml-graphics-s-d.lib(type1.obj) : error LNK2001: unresolved external symbol "__imp__qsort".
sfml-graphics-s-d.lib(ftbase.obj) : error LNK2019: unresolved external symbol "__imp__qsort" referenced in function "_FT_Raccess_Get_DataOffsets".
sfml-graphics-s-d.lib(bdf.obj) : error LNK2001: unresolved external symbol "__imp__qsort".
sfml-graphics-s-d.lib(psmodule.obj) : error LNK2001: Nicht aufgelöstes externesSymbol "__imp__qsort".
sfml-graphics-s-d.lib(psaux.obj) : error LNK2001: unresolved external symbol "__imp__qsort".
sfml-graphics-s-d.lib(jerror.obj) : error LNK2019: unresolved external symbol "__imp__fprintf" referenced in function "_output_message".
sfml-graphics-s-d.lib(truetype.obj) : error LNK2019: unresolved external symbol "__imp__strstr" referenced in function "_tt_check_trickyness_family".
sfml-graphics-s-d.lib(jmemmgr.obj) : error LNK2019: unresolved external symbol "__imp__sscanf" referenced in function "_jinit_memory_mgr".
sfml-graphics-s-d.lib(jmemmgr.obj) : error LNK2019: unresolved external symbol "__imp__getenv" referenced in function "_jinit_memory_mgr".
opengl-d.exe : fatal error LNK1120: 7 unresolved external symbols.
LINK Pass 1 failed. with 2

The errors look quite similar for the other examples that don't build which are: opengl, pong, shader and win32.
I then even tried the VS10 compiler of which I know that it build fine in the past, so it's not a VS11 issue.
For me it seems like the external libraries (OpenAL, etc) have problems with the statically/build-in runtime library.

Any ideas?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #1 on: October 26, 2012, 03:57:14 pm »
Yeah I know, it happens since I recompiled the dependencies of sfml-graphics to fix the "... conflicts with default library ..." linker warning. I have no idea, and no time to test :(

Quote
Visual Studio 11
Visual Studio (20)12. It is Visual C++ which is in version 11. Visual Studio (the IDE) versions are years, Visual C++ (the compiler) versions are just incremented. This is very confusing because both are almost equal.
Laurent Gomila - SFML developer

Oberon

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • My Github profile
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #2 on: October 27, 2012, 12:19:46 pm »
Maybe you fixed the "... conflicts with default library ..." warning by recompiling the external libraries using the non-static default libraries (DLL-Runtime, /MTd, MDd). But you would have to supply two versions of them, one for the static and one for the DLL runtime.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #3 on: October 27, 2012, 06:45:17 pm »
I recompiled them with no version of the standard libraries. They are static libraries, so they don't need to link to specific libs.
Laurent Gomila - SFML developer

Kai

  • Guest
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #4 on: October 31, 2012, 02:21:36 am »
I recompiled them with no version of the standard libraries. They are static libraries, so they don't need to link to specific libs.

As far as I know, there is no way to compile a program without linking to a C run-time library, even if you're compiling a static library. If you don't specify a CRT flag then MSVC will use /MT by default. (http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.80).aspx)

I think Oberon is correct about /MTd and /MDd being the problem.

Kai

  • Guest
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #5 on: October 31, 2012, 02:54:47 am »
I verified that /MTd and /MDd are the problem. These are the steps I used:
  • Compile FreeType 2.4.10 from source with the /MT flag (use Debug Multithreaded configuration in their .sln)
  • Check out the latest SFML source from GitHub
  • Replace SFML/extlibs/libs-msvc/x86/freetype.lib with the /MT one
  • Compile SFML with CMake option SFML_USE_STATIC_STD_LIBS
  • Link SFML statically to my game (using SFML_STATIC)
Now my game compiles without errors. There are still warnings, but I think those are from libjpeg and libglew.
« Last Edit: October 31, 2012, 02:57:24 am by Kai »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11006
    • View Profile
    • development blog
    • Email
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #6 on: October 31, 2012, 03:21:23 am »
I verified that /MTd and /MDd are the problem. These are the steps I used:
  • Compile FreeType 2.4.10 from source with the /MT flag (use Debug Multithreaded configuration in their .sln)
  • Check out the latest SFML source from GitHub
  • Replace SFML/extlibs/libs-msvc/x86/freetype.lib with the /MT one
  • Compile SFML with CMake option SFML_USE_STATIC_STD_LIBS
  • Link SFML statically to my game (using SFML_STATIC)
Now my game compiles without errors. There are still warnings, but I think those are from libjpeg and libglew.
Well that doesn't confirm anything, it just shows that it works with /MT builds and your specific setup. ;D

As far as my testing goes (dumpbin /all LIBRARY | find /i "msvcr") I have only found a result on the libsndfile-1.dll but nothing in the static libraries, so...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #7 on: October 31, 2012, 08:15:51 am »
Quote
As far as I know, there is no way to compile a program without linking to a C run-time library, even if you're compiling a static library. If you don't specify a CRT flag then MSVC will use /MT by default
When you compile a static library, there's no link step. All you can do is to force the linker to "write" the name of the C runtime to link when the final binary will be compiled. And you can of course make the linker not write anything into the static library, with the /Zl option.

You can check that by opening any .lib with a text editor: there's no C runtime name written in it.

Quote
I verified that /MTd and /MDd are the problem.
Of course it works, this thread is all about that :P
Before I was explicitely using the Multithreaded DLL runtime and all worked fine -- except this annoying warning. With the modification I made to fix it, this problem appeared. But the cause of the problem is less obvious than what you think. I'll revert to the old behaviour if I have no choice, but I'd really like to understand what's going on.
Laurent Gomila - SFML developer

Oberon

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • My Github profile
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #8 on: October 31, 2012, 09:47:37 am »
Omitting the default library name (/Zl) is not enough. Like you cannot link the object files of an SFML application compiled with SFML_STATIC defined to the sfml-s-* libraries, you cannot link an .lib file compiled with /MD to an application compiled with /MT (although the opposite works; see below): Look at  the crtdefs.h header: There you will find the following lines:

#ifndef _CRTIMP
#ifdef  _DLL
#define _CRTIMP __declspec(dllimport)
#else   /* ndef _DLL */
#define _CRTIMP
#endif  /* _DLL */
#endif  /* _CRTIMP */

This is basically the same, what SFML does with its SFML_API #define, and thats the problem: either you dllimport your functions, or you do not. Still, if you omit the dllimport, it should work both with and without the DLL, albeit a bit slower, according to http://blogs.msdn.com/b/russellk/archive/2005/03/20/399465.aspx. So compiling the libraries with /MT might work for all configurations. I don't think, however, that a loss of speed when calling default library functions like malloc is desireable, so I would still opt for an additional freetype-s.lib.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #9 on: October 31, 2012, 10:47:50 am »
You're right, I totally forgot about this problem. Thanks for investigating :)

I don't know yet which solution I'm going to choose, but at least now the problem is fully understood.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML's example can't be build anymore with static std libs and VS10+11
« Reply #10 on: November 01, 2012, 12:11:54 pm »
It's fixed.
Laurent Gomila - SFML developer

 

anything