microsoft / openssl

A cross-platform cryptographic library
133 stars 57 forks source link

[UWP] mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker' #25

Closed mattleibow closed 8 years ago

mattleibow commented 8 years ago

Just trying build OpenSSL as a static library. That seems to work and produces a static .lib file. I first run ms\do_vsprojects14.bat, and then just build the NT-Universal-10.0-Static-Unicode.vcxproj project from VS.

So, I went ahead and created a dummy DLL project for UWP and added a small usage in dllmain.cpp:

const RAND_METHOD * method = RAND_get_rand_method();

I added the libeay32.lib file and started the build:

...
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe 
    /ERRORREPORT:PROMPT 
    /OUT:"C:\Project\Debug\Dll2\Dll2.dll" /INCREMENTAL /NOLOGO 
    /LIBPATH:"C:\Project\openssl\vsout\NT-Universal-10.0-Static-Unicode\Debug\Win32\bin" 
    libeay32.lib WindowsApp.lib WindowsApp.lib /MANIFEST:NO /DEBUG:FASTLINK 
    /PDB:"C:\Debug\Dll2\Dll2.pdb" 
    /SUBSYSTEM:CONSOLE /TLBID:1 /APPCONTAINER 
    /WINMD:NO /WINMDFILE:"C:\Project\Debug\Dll2\Dll2.winmd" 
    /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Project\Debug\Dll2\Dll2.lib" 
    /MACHINE:X86 /DLL Debug\dllmain.obj
...

I got this error:

1>vccorlib.lib(init.obj) : error LNK2038: mismatch detected for 'vccorlib_lib_should_be_specified_before_msvcrt_lib_to_linker': value '1' doesn't match value '0' in MSVCRTD.lib(app_appinit.obj)
1>vccorlib.lib(init.obj) : error LNK2005: ___crtWinrtInitType already defined in MSVCRTD.lib(app_appinit.obj)
1>C:\Project\Debug\Dll2\Dll2.dll : fatal error LNK1169: one or more multiply defined symbols found

I am not sure where exactly the issue is, but this does not happen with the Store 8.1 and Phone 8.1. Also, as I am just adding the .lib to my dummy DLL, It seems to be a dodgy .lib file? Or, do I need to do something specific. The build does seem to create the openssl.dll file fine, so it is just me and my dll.

khouzam commented 8 years ago

I'm not sure the root cause, but I was able to reproduce the issue and work around by adding this to the linking options, which should set the right order for the libraries.

/NODEFAULTLIB:"vccorlib" /NODEFAULTLIB:"msvcrt" vccorlib.lib msvcrt.lib