内联外部导致的重复符号
FMParallaxChild.h
typedef struct {
// ...
} FMParallaxSetting;
inline extern FMParallaxSetting FMParallaxSettingMake(CGPoint ratio, CGPoint startPos, CGPoint offset, CGPoint relVel, int zOrder);
inline extern FMParallaxSetting FMParallaxSettingMake(CGPoint ratio, CGPoint startPos, CGPoint offset, CGPoint relVel, int zOrder) {
// ...
}
FMParallax.h
#import "FMParallaxChild.h"
....
MyController.h
#import "FMParallax.h"
....
AppDelegate.m
#import "MyController.h"
....
从这个简化的设置中,我收到重复的符号链接器错误:
ld: duplicate symbol _FMParallaxSettingMake in MyController.o and AppDelegate.o
我找不到任何导入循环,我只导入 FMParallaxChild.h
在一个地方,那么我做错了什么?
FMParallaxChild.h
typedef struct {
// ...
} FMParallaxSetting;
inline extern FMParallaxSetting FMParallaxSettingMake(CGPoint ratio, CGPoint startPos, CGPoint offset, CGPoint relVel, int zOrder);
inline extern FMParallaxSetting FMParallaxSettingMake(CGPoint ratio, CGPoint startPos, CGPoint offset, CGPoint relVel, int zOrder) {
// ...
}
FMParallax.h
#import "FMParallaxChild.h"
....
MyController.h
#import "FMParallax.h"
....
AppDelegate.m
#import "MyController.h"
....
From this simplified setup I am getting a duplicate symbol linker error:
ld: duplicate symbol _FMParallaxSettingMake in MyController.o and AppDelegate.o
I can't find any import loops and I only import FMParallaxChild.h
in a single place, so what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其声明为 c 或 objc 的
static inline
:或者只是 c++ 或 objc++ 的
inline
:当然,对于 c++ 和 objc++,您的程序将依赖于单一定义规则在这种情况下(这是一个很好的默认值)。
问题在于,它将针对其可见 (
#include
d) 中的每个翻译进行导出。Declare it as
static inline
for c or objc:or just
inline
for c++ or objc++:of course, with c++ and objc++, your program will fall back on the One Definition Rule in this case (which is a good default).
The problem as it is, is that it will be exported for each translation it is visible (
#include
d) in.