如何避免函数的多重定义(Linux、GCC/G++、Code::Blocks)

Mis*_*ery 3 c++ header codeblocks

我在代码块中有一个项目,它使用许多不同的文件 - 通常由其他程序员编写。目前,我有两个不同的子项目,其中包含以相同方式命名的函数。假设:F(int x)。所以 F(int x) 在两个不同位置的两个源文件中定义,它们有两个不同的标题。我还为这些标头创建了两个不同的命名空间:

namespace NS1
{
 extern "C"{
  #include "header1definingF.h"
 }
}
namespace NS2
{
 extern "C"{
  #include "header2definingF.h"
 }
}
Run Code Online (Sandbox Code Playgroud)

但是编译器仍然抱怨它有多个 F(int x) 定义。我如何在 Code::Blocks 中解决这个问题(在 Visual Studio 中它工作得很好)。

编辑:为了更清楚这些头文件包括 C 代码。没想到会这么乱 有数千个源文件使用其他项目,包括数千个函数……那该怎么办。我完全不知道如何使它工作。

doc*_*ove 6

我想知道为什么它适用于 Visual Studio,而不适用于代码块。这表明您确实有一个包含守卫。请问帮助?

Project->Build options...->Linker settings (tab)
-Wl,--allow-multiple-definition
Run Code Online (Sandbox Code Playgroud)