MacOS 上的 Xcode 11 项目不在一个函数中使用 sin 和 cos:未定义的符号"___sincosf_stret"



在Mac上构建我的库突然在Xcode版本11.3(11C29(中开始失败。

我能够隔离一个问题:

似乎当您在同一函数中使用 sin 和 cos 时,优化器将使用 __sincosf_stret 同时计算两者。

那我做了什么:

  1. 创建一个新的Xcode项目,cmd线工具,objective-c
  2. 将 main.m 更改为 main.mm 以允许C++
  3. 将主要更改为:
#import <Foundation/Foundation.h>
#include <cmath>
void coordinateCalculator(float angle, float radius, float& x, float& y) {
float mySin = sin(angle);
float myCos = cos(angle);
x = radius * myCos;
y = radius * mySin;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
float myAngle = 0.0;
float theX, theY;
float radius = 100.0;
while (myAngle < 360.0) {
coordinateCalculator(myAngle, radius, theX, theY);
NSLog(@"My coordinates: %f, %f",theX,theY);
myAngle += 1.0;
}
}
return 0;
}

在调试中构建工作正常,为配置文件(具有优化的发布版本(构建将失败,并显示以下错误消息:

Undefined symbols for architecture x86_64:
"___sincosf_stret", referenced from:
coordinateCalculator(float, float, float&, float&) in main.o
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我正在构建:

  • C++: C++14, libC++
  • 基本 SDK:MacOS
  • 部署目标 10.14

当我将部署目标更改为 10.7 时,找到了sincosf_stret,但出现 2 个 ARC 错误:

Undefined symbols for architecture x86_64:
"_objc_loadClassref", referenced from:
__ARCLite__load() in libarclite_macosx.a(arclite.o)
"_objc_readClassPair", referenced from:
__ARCLite__load() in libarclite_macosx.a(arclite.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

使用部署 SDK 让我:

  • 10.7: 2 个 ARC 链接错误
  • 10.10:2 个 ARC 链接错误和 _sincosf_ret 错误
  • 10.12 或更高版本:_sincosf_ret错误

我不敢相信不可能在一个函数中使用 sin/cos。

重新安装XCode解决了我的问题。另一位开发人员在他的系统上尝试过,它似乎有效。这让我决定删除XCode并重新安装它。问题现在消失了。XCode本身没有问题。

最新更新