Reputation: 660
I have a VS10 solution that contains 2 projects that have functions of the identical name. The linker complains (throws warnings) about second definitions (of two functions of the same name) getting ignored:
warning LNK4006: "void __cdecl function_name(short *,class Bbox *,int,int,struct FILE_NAMES *,unsigned char *)" (?function_name@@YAXPAFPAVBbox@@HHPAUFILE_NAMES@@PAE@Z) already defined in XXX.lib(segment.obj); second definition ignored
This causes calls to functions of the second project (the ignored one) to point to the function of the first project (since the definitions are ignored).
My question is: is there any way to avoid/resolve this issue, other than renaming all the functions that have the same name in the two projects? For example, by adding a #if/pragma to my header files, or by manipulating the .obj files. The reality is that the solution only needs one of the two projects in any compilations, so an easy way for conditional compilation is perfectly fine, but my first preference is to have both projects compiled together.
Upvotes: 0
Views: 112
Reputation: 20063
This violates the One Definition Rule that states only one definition of a tempate, type, function or object may exist in the entire program. To resolve this problem either make the signature of both functions unique ether by name or parameter overload, place them in different namespaces or use conditional compiling if you require both libraries at the same time.
Upvotes: 1