MacOS上的XCode 11项目不要在一个函数中使用sin和cos:未定义的符号“ ___ sincosf_stret”

问题描述 投票:1回答:1

[在Mac上构建我的库突然因XCode版本11.3(11C29)而失败。

我能够隔离一个问题:

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

所以我做了什么:

  1. [创建新的XCode项目,cmd线工具,objectiv-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;
}

在Debug中构建可以正常工作,为配置文件(带有优化的发行版)构建将失败,并显示以下错误消息:

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。因此,我希望有人能解决此问题。

谢谢,

Rudi

c++ xcode macos clang++ cmath
1个回答
0
投票

重新安装XCode解决了我的问题。另一位开发人员在他的系统上对其进行了尝试,并且似乎可以正常工作。这使我决定删除XCode并重新安装。现在问题解决了。 XCode本身没有问题。

© www.soinside.com 2019 - 2024. All rights reserved.