我有一个源代码结构如下
foo.h (c库中的标头)
#pragma once
struct foo {...};bar.h
#pragma once
extern "C" {
#include "foo.h"
}
class Bar {
foo val;
...
};bar.cpp
// some Bar methods implementationuser.cpp
#include "bar.h"
...
extern "C" {
#include "foo.h"
}
...
/* some additional foo usage */我希望发生的是,如果foo.h包含了多次,#语用一次就会使它只包含第一次。但是,在bar.h中,它根本不包括,只包含在user.cpp中。所以user.cpp.i的预处理输出看起来有点像这样:
extern "C" {/* nothing is here, literally empty braces */}
class Bar {
foo val;
...
};
extern "C" {/*actual header content*/}
...
/*the rest of user.cpp content*/我希望foo.h在最初包含时粘贴,但是所发生的情况是,struct在bar.h中未定义,但在user.cpp中定义。
我现在可以通过重新排序来解决这个问题,但是为什么会发生这种情况呢?
更新:
重新安排包括什么都不做。因为bar.cpp仍然没有得到预处理器添加的包含。
发布于 2022-09-06 01:32:02
所以。我的设置是: Windows + Wsl。源代码位于windows主机上,并在wsl上编译。因此,我在编写时考虑到了linux,但没有注意到我最终拥有了c_functionality.h和C_FUNCTIONALITY.h (第二个应该是包装器)。
据我所知,对于大多数linux‘As来说,这都不是一个问题,因为大多数广泛使用的linux FS都支持这种情况。但!源代码在ntfs上。
GCC不会告诉你,你有多个标题,名字相互矛盾。但克莱尔会的。
https://stackoverflow.com/questions/73614994
复制相似问题