How do I link a static library using cl.exe? (Specifying RuntimeLibrary)

KeyHeart picture KeyHeart · Jan 20, 2015 · Viewed 7.6k times · Source
cl -MT -DSFML_STATIC main.cpp freetype.lib gdi32.lib glew.lib jpeg.lib openal32.lib opengl32.lib sfml-audio-s.lib sfml-graphics-s.lib sfml-network-s.lib sfml-system-s.lib sfml-window-s.lib sndfile.lib winmm.lib

The result is:

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

How do I specify the RuntimeLibrary?

Answer

nicebyte picture nicebyte · Jan 21, 2015

You probably want the multithreaded, dynamic, release version of the runtime library. Use the /MD flag. See here for more information on flags that control which version of runtime library to link against.

The problem is that sfml-graphics-s.lib is linked against the multithreaded, dynamic, release version of the runtime library whereas your command line instructs to link against the multithread, static, release version of that library (you're using the /MT switch). Replace /MT with /MD and the conflict should be resolved.