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

Author Topic: Statically linking mismatched runtime for LLVM Clang Windows  (Read 1364 times)

0 Members and 1 Guest are viewing this topic.

Kappa

  • Newbie
  • *
  • Posts: 4
  • yes
    • View Profile
So far, I am able to dynamically link SFML and run the executable just fine. However, statically linking the SFML errors saying:

Quote
sfml-graphics-s.lib(RenderWindow.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in Main.o

My clang version and information are:
Quote
clang version 15.0.7
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: ...
which made me not accomplish any solutions from quick google search about my problem as their build system or environment is different from mine.

I downloaded the SFML version for Visual Studio 64 bit, and then setted up the required search directories and linkers such as sfml-graphics-s.lib.
My command line is:
clang++.exe -DSFML_STATIC -fms-extensions -O2 -Wnon-virtual-dtor -Wall -std=c++14 -I"Deps\SFML\include" -c "Main.cpp" -o "Main.o"

clang++.exe -L"Deps\SFML\lib" -o "Main.exe" "Main.o" -m64 -lfreetype.lib -lopengl32.lib -lwinmm.lib -lgdi32.lib -luser32.lib -lsfml-window.lib -lsfml-graphics-s.lib -lsfml-system.lib
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Statically linking mismatched runtime for LLVM Clang Windows
« Reply #1 on: June 22, 2023, 11:09:11 pm »
The runtime library is linked statically for your own code, but linked dynamically in SFML. Not sure if clang links the runtime statically by default on Windows.

The simplest solution is to build SFML with the same configuration. You can easily achieve this by using for example this CMake SFML Template: https://github.com/SFML/cmake-sfml-project
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kappa

  • Newbie
  • *
  • Posts: 4
  • yes
    • View Profile
Re: Statically linking mismatched runtime for LLVM Clang Windows
« Reply #2 on: June 24, 2023, 02:20:34 am »
Thank you! After a long dedicated research about it, I have discover the solution.

I had to link msvcrt.lib, then define the _DLL macro. Now it successfully compiles my SFML project statically.