简体   繁体   中英

Visual Studio solution with different projects with functions of the identical name

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM