内联外部导致的重复符号

发布于 2025-01-07 01:07:44 字数 844 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煞人兵器 2025-01-14 01:07:44

将其声明为 c 或 objc 的 static inline

static inline FMParallaxSetting
  FMParallaxSettingMake(CGPoint ratio,
                        CGPoint startPos,
                        CGPoint offset,
                        CGPoint relVel,
                        int zOrder) {
  // ...
}

或者只是 c++ 或 objc++ 的 inline

inline FMParallaxSetting
  FMParallaxSettingMake(CGPoint ratio,
                        CGPoint startPos,
                        CGPoint offset,
                        CGPoint relVel,
                        int zOrder) {
  // ...
}

当然,对于 c++ 和 objc++,您的程序将依赖于单一定义规则在这种情况下(这是一个很好的默认值)。

问题在于,它将针对其可见 (#included) 中的每个翻译进行导出。

Declare it as static inline for c or objc:

static inline FMParallaxSetting
  FMParallaxSettingMake(CGPoint ratio,
                        CGPoint startPos,
                        CGPoint offset,
                        CGPoint relVel,
                        int zOrder) {
  // ...
}

or just inline for c++ or objc++:

inline FMParallaxSetting
  FMParallaxSettingMake(CGPoint ratio,
                        CGPoint startPos,
                        CGPoint offset,
                        CGPoint relVel,
                        int zOrder) {
  // ...
}

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 (#included) in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文