Linker Tools Warning LNK4255

Error Message

library contain multiple objects of the same name; linking object as if no debug info

LNK4255 can occur when merging two static libraries and where each library has an .obj file that has the same name as an .obj file in the other library and where both .obj files were built with /Zi. In this case, the linker will not include debug symbols to the library for one of the .obj files.

Example

The following sample creates an .obj file that will be used to create a static library.

// LNK4255.cpp
// compile with: /c /Zi /FoLNK4255_obj1.obj /FdLNK4255.pdb
// post-build command: lib LNK4255_obj1.obj /out:LNK4255_lib1.lib
void func1() {}

The following sample creates another .obj file that will be used to create a static library.

After the LNK4255_lib2.lib static library is created, you would then run lib.exe again, to merge the two static libraries into one static library. For example, lib LNK4255_lib1.lib LNK4255_lib2.lib /out:LNK4255_lib.lib.

// LNK4255_b.cpp
// compile with: /c /FoLNK4255_obj1.obj /Zi /FdLNK4255_b.pdb
// post-build command: (lib LNK4255_obj1.obj /out:LNK4255_lib2.lib & lib LNK4255_lib1.lib  LNK4255_lib2.lib /out:LNK4255_lib.lib)
void func2() {}

The following sample generates LNK4255.

// LNK4255_c.cpp
// compile with: LNK4255_lib.lib /Zi /FdLNK4255_c.pdb
// processor: x86
void func1();
void func2();
int main() {
   func1();
   func2();
}