简体   繁体   English

具有相同名称功能的具有不同项目的Visual Studio解决方案

[英]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. 我有一个VS10解决方案,其中包含2个具有相同名称功能的项目。 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. 例如,通过将#if / pragma添加到我的头文件中,或通过操作.obj文件。 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. 要解决此问题,请按名称或通过参数重载使两个函数的签名唯一,将它们放置在不同的名称空间中,或者如果您同时需要两个库,请使用条件编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在多项目Visual Studio解决方案中以不同配置编译项目 - Compiling projects in different configurations in a multi-projects Visual Studio Solution 同一解决方案中不同项目之间的引用(Visual Studio 2012) - Reference between different projects in the same solution (Visual Studio 2012) Visual Studio解决方案:静态或共享项目? - Visual Studio Solution: static or shared projects? 在Visual Studio解决方案中链接两个项目 - Linking two projects in a Visual studio solution 使用cmake和visual studio在一个解决方案中的几个项目 - Several projects in one solution with cmake and visual studio 具有多个项目的visual studio解决方案无法编译 - visual studio solution with multiple projects doesnt compile 如何在Visual Studio 2010中使用来自不同C ++项目的函数? - How to use functions from different C++ projects in Visual Studio 2010? Visual Studio:解决方案中的某些项目不会生成.exe文件 - Visual Studio: some projects in solution don't generate .exe files c ++ visual studio 2008问题,在一个解决方案中有两个项目 - c++ visual studio 2008 issue with two projects in one solution 在Visual Studio解决方案中为所有项目设置目录结构吗? - Set directory structure for all projects in a Visual Studio solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM