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

Author Topic: Nuget SFML and static linking  (Read 3815 times)

0 Members and 2 Guests are viewing this topic.

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
Nuget SFML and static linking
« on: May 12, 2018, 02:09:35 pm »
I've been trying to get VC 2015 compiling a test program this entire morning without success.

I get the following errors:
Quote
1>------ Build started: Project: SFMLTEST, Configuration: Release x64 ------
1>  main.cpp
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)
1>D:\SFMLTESTFOLDER\SFMLTEST\x64\Release\SFMLTEST.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I've set:
SFML_STATIC in C/C++->Preprocessor->Preprocessor Definitions
Multi-Threadded in Project Master Settings->Code Generation->Runtime Library

in VC2017 the situation is even worse:
Quote
1>------ Build started: Project: SFMLTEST, Configuration: Release x64 ------
1>main.cpp
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "public: __cdecl sf::CircleShape::CircleShape(float,unsigned __int64)" (??0CircleShape@sf@@QEAA@M_K@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (??1RenderWindow@sf@@UEAA@XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: __cdecl sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0RenderWindow@sf@@QEAA@VVideoMode@1@AEBVString@1@IAEBUContextSettings@1@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: __cdecl sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@QEAA@EEEE@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: void __cdecl sf::Window::display(void)" (?display@Window@sf@@QEAAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: bool __cdecl sf::Window::pollEvent(class sf::Event &)" (?pollEvent@Window@sf@@QEAA_NAEAVEvent@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: bool __cdecl sf::Window::isOpen(void)const " (?isOpen@Window@sf@@QEBA_NXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: void __cdecl sf::Window::close(void)" (?close@Window@sf@@QEAAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "public: void __cdecl sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (?draw@RenderTarget@sf@@QEAAXAEBVDrawable@2@AEBVRenderStates@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: void __cdecl sf::RenderTarget::clear(class sf::Color const &)" (?clear@RenderTarget@sf@@QEAAXAEBVColor@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: void __cdecl sf::Shape::setFillColor(class sf::Color const &)" (?setFillColor@Shape@sf@@QEAAXAEBVColor@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl sf::Shape::~Shape(void)" (??1Shape@sf@@UEAA@XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: __cdecl sf::String::String(char const *,class std::locale const &)" (??0String@sf@@QEAA@PEBDAEBVlocale@std@@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: __cdecl sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@QEAA@III@Z)
1>C:\Users\Radek\source\repos\SFMLTEST\x64\Release\SFMLTEST.exe : fatal error LNK1120: 16 unresolved externals
1>Done building project "SFMLTEST.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


When I set referenced libraries frm Dynamic Library (DLL) to Static I get:
Quote
1>------ Build started: Project: SFMLTEST, Configuration: Release x64 ------
1>  main.cpp
1>sfml-graphics-s.lib(RenderStates.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(CircleShape.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(RenderWindow.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Color.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Shape.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Transform.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(View.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Shader.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Transformable.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(VertexArray.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Image.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(Glsl.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-graphics-s.lib(ImageLoader.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(Window.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(VideoMode.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(Context.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(WindowImpl.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(VideoModeImpl.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(JoystickManager.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(SensorManager.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(WindowImplWin32.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(WglExtensions.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(Joystick.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-system-s.lib(String.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-system-s.lib(Err.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>sfml-system-s.lib(ThreadLocal.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glBlendFunc
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glClear
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glClearColor
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glDisable
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glEnable
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glLoadMatrixf
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glLoadMatrixf
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glMatrixMode
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glMatrixMode
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glPopAttrib
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glPopMatrix
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glPushAttrib
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glPushMatrix
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glViewport
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glColorPointer
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glDrawArrays
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glEnableClientState
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glPopClientAttrib
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glPushClientAttrib
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glTexCoordPointer
1>sfml-graphics-s.lib(RenderTarget.cpp.obj) : error LNK2001: unresolved external symbol glVertexPointer
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glFlush
1>sfml-graphics-s.lib(Shader.cpp.obj) : error LNK2001: unresolved external symbol glFlush
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glGetIntegerv
1>sfml-graphics-s.lib(Shader.cpp.obj) : error LNK2001: unresolved external symbol glGetIntegerv
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2001: unresolved external symbol glGetIntegerv
1>sfml-graphics-s.lib(TextureSaver.cpp.obj) : error LNK2001: unresolved external symbol glGetIntegerv
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glGetTexImage
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glLoadIdentity
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glTexImage2D
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glTexParameteri
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glBindTexture
1>sfml-graphics-s.lib(TextureSaver.cpp.obj) : error LNK2001: unresolved external symbol glBindTexture
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glCopyTexSubImage2D
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glDeleteTextures
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glGenTextures
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol glTexSubImage2D
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2001: unresolved external symbol glGetError
1>sfml-graphics-s.lib(GLExtensions.cpp.obj) : error LNK2001: unresolved external symbol glGetString
1>sfml-graphics-s.lib(ImageLoader.cpp.obj) : error LNK2001: unresolved external symbol __imp_realloc
1>sfml-graphics-s.lib(ImageLoader.cpp.obj) : error LNK2001: unresolved external symbol __imp_fopen_s
1>sfml-graphics-s.lib(ImageLoader.cpp.obj) : error LNK2001: unresolved external symbol __imp_fopen
1>sfml-graphics-s.lib(ImageLoader.cpp.obj) : error LNK2001: unresolved external symbol __imp_fread
1>sfml-graphics-s.lib(ImageLoader.cpp.obj) : error LNK2001: unresolved external symbol __imp_strncmp
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_strstr
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_glEnable
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_glGetError
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_glGetIntegerv
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_glGetString
1>sfml-window-s.lib(GlContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_glIsEnabled
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_wglCreateContext
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_wglDeleteContext
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_wglGetProcAddress
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_wglMakeCurrent
1>sfml-window-s.lib(WglContext.cpp.obj) : error LNK2001: unresolved external symbol __imp_wglShareLists
1>sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_joyGetPosEx
1>sfml-window-s.lib(JoystickImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_joyGetDevCapsW
1>sfml-system-s.lib(SleepImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_timeGetDevCaps
1>sfml-system-s.lib(SleepImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_timeBeginPeriod
1>sfml-system-s.lib(SleepImpl.cpp.obj) : error LNK2001: unresolved external symbol __imp_timeEndPeriod
1>D:\SFMLTESTFOLDER\SFMLTEST\x64\Release\SFMLTEST.exe : fatal error LNK1120: 53 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What am I missing?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Nuget SFML and static linking
« Reply #1 on: May 12, 2018, 02:22:29 pm »
The SFML NuGet package isn't maintained by us, if it needs updating you'll have to ask the maintainer.

The first error happens if you don't set SFML_STATIC. Since you claim you do, check your configuration again and make sure that it's matching the compiler architecture (32 vs 64 bits) and that debug/release mode is correct.

Second one seems like you're not linking the libraries. Again, make sure it's using the correct config. Also has the NuGet package been updated for VS 2017?

The third error means that you've set C/C++ > Code Generation > Runtime Library to /MT or /MTd but the DLLs were compiled with /MD or /MDd thus the mismatch.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
Re: Nuget SFML and static linking
« Reply #2 on: May 12, 2018, 02:32:40 pm »
Thanks for your quick answer.
I've doublechecked the preprocessor flag and it's there, in all configurations.



 :-\

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Nuget SFML and static linking
« Reply #3 on: May 12, 2018, 03:12:05 pm »
And are you linking the static libraries?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
Re: Nuget SFML and static linking
« Reply #4 on: May 12, 2018, 03:14:14 pm »
I’m not. I thought the whole idea of using nuget is to not to worry about setting proper libs in the linker.

Linking dynamic libraries works fine even though the linker settings are empty set to default.

I don't get it, honestly. I've linked against the static libraries in the linker settings with absolute paths, but the linker gives me the same 2 errors.
« Last Edit: May 12, 2018, 04:47:27 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Nuget SFML and static linking
« Reply #5 on: May 12, 2018, 04:49:16 pm »
There's an edit function for a reason, no need to hit reply for every new thought. ;)

Well if NuGet package doesn't support static linking, then it doesn't support it.
I'm not familiar with it for C++, so someone else might help you or you can ask the package maintainer.

What certainly works is the official Visual Studio tutorial.

Also instead of guessing, you can always get the full build command, that way you see exactly what is linked and what isn't. See the FAQ on how to do so.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything