问题描述
我有一个项目在代码块,使用许多不同的文件 - 经常由其他程序员写。目前我有一个情况,我有两个不同的子项目包含以相同的方式命名的函数。让我们说:F(int x)。因此F(int x)在两个不同位置的两个源文件中定义,它们有两个不同的头。我还为这些头创建了两个不同的命名空间:
I have a project in code blocks that uses many different files - quite often written by other programmers. At the moment I have a situation in which I have two different sub-projects containing function named in the same manner. Let's say: F(int x). So F(int x) is defined in two source files in two different locations and they have two different headers. Also I have created two different namespaces for those headers:
namespace NS1
{
extern "C"{
#include "header1definingF.h"
}
}
namespace NS2
{
extern "C"{
#include "header2definingF.h"
}
}
但是编译器仍然抱怨它有多个定义F(int x)。我如何解决这个在Code :: Blocks(在Visual Studio它的工作正常)。
But still compiler complains that it has multiple definition of F(int x). How can I workaround this in Code::Blocks (In Visual Studio it works just fine).
编辑:为了更清楚,这些头包括C代码。我没有想到会是这么凌乱。有像成千上万的源文件使用其他项目,包括成千上万的功能...所以做什么。我完全不知道如何使它工作。
To be more clear those headers include C code. I haven't thought it will be so messy. There are like thousands of source files using other projects including thousands of functions again... so what to do. I have absolutely no idea how to make it work.
推荐答案
我想知道为什么它在Visual stduio,但不是代码块。这表明你有一个包括守卫。
此帮助?
I wonder why it works on Visual stduio, but not code blocks. This suggests you do have an include guard.Does this help?
Project->Build options...->Linker settings (tab)
-Wl,--allow-multiple-definition
这篇关于如何避免多重定义函数(Linux,GCC / G ++,Code :: Blocks)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!