Reputation: 1
I need to link a static library against a given object file. I neither have the source code of that file nor any influence on it.
When using Visual Studio 2010 I can create a library and link it against the given file.
On a different machine I only have VS 2015. When I build and link my C-Code to the given lib I get the following error:
LIBCMT.lib(vfprintf.obj) : error LNK2005: __vfprintf_l already defined in c_fun.obj
LIBCMT.lib(printf.obj) : error LNK2005: _printf already defined in c_fun.obj
For testing purpose I use the following simplified code:
#include <stdio.h>
void c_fun(double C_IN, double *C_OUT)
{
*C_OUT = C_IN * 2.0;
printf("Hallo C!\n");
}
When I commend the printf line out, then I can successfully link the lib created with VS2015 but I need the printf statements for visualization purpose.
To compile my lib I use the same parameters on the command line. Is there a compiler or linker option to generate a VS 2010 compatible library?
When I use dumpbin /all for both libs, I get the following outputs:
Lib created with VS2010:
2 public symbols
BC _F_FUN
310 _c_fun
Lib created with VS2015: 7 public symbols
1DE _F_FUN
432 ?_OptionsStorage@?1??__local_stdio_printf_options@@9@9
432 ___local_stdio_printf_options
432 __real@4000000000000000
432 __vfprintf_l
432 _c_fun
432 _printf
I would expect to get the same symbols with both versions.
The compiler options i use are both times "/MT /W3 /EHsc /c"
Upvotes: 0
Views: 1238
Reputation: 39621
The Visual Studio 2015 compilers aren't compatible with object files created with earlier versions of the compiler. There was a major reorganization of the C runtime library that broke the C object level backwards compatibility that Visual Studio used to have. You'll need to use the older compiler to compile and create the static library and then link it with the object file created by the older compiler. You can do this in Visual Studio 2015 by installing Visual Studio 2010 and in your Visual Studio 2015 project properties selecting "Visual Studio 2010 (v100)" under Configuration Properties -> General -> Platform Toolset.
Upvotes: 2