Search code examples
c++visual-studiostatic-librariesluajit.lib

LuaJIT lib built with /MD but does not cause runtime library mismatch with /MDd program?


I downloaded luajit source from

http://luajit.org/git/luajit-2.0.git

and built it with its msvcbuild.bat

https://github.com/luvit/luajit-2.0/blob/master/src/msvcbuild.bat

Judging from the batch file, it uses /MD to build the lua51.lib. When I linked the library to my application, I found visual studio 2013 does not issue runtime library mismatch when I used /MDd settings for my application.

I also have built other source into libraries using visual studio, and I have to build two versions of lib to avoid the mismatch error.

My question is, is it possible to build a library that could be used both by program compiled with /MD and /MDd settings?

If the answer is yes, is it safe to do so?

If the answer is no, why there is no error when linking the lua51.lib to /MDd application?

Thanks.

Edit

Error message

Error 20 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in Logger.obj

Solution

  • Question 1:

    is it possible to build a library that could be used both by program compiled with /MD and /MDd settings?

    Answer: Yes.

    Question 2:

    Is it safe to do so?

    Short answer: Not always.

    Longer answer:

    When the flag /MD is used, the compiler defines the proprocessor macros _MT, _DLL. When /MDd is used, the compiler defines the proprocessor macros _MT, _DLL, _DEBUG.

    It is possible that one or more classes will have different member variables depending on whether _DEBUG is defined. When that is the case, it is most likely not safe to mix codes compiled with the different flags. If you are absolutely certain that none of the objects being passed between the two sets of code have that issue, it's probably safe to mix the two sets of code/libraries.