Building my libraries on Mac suddenly started to fail with XCode Version 11.3 (11C29).
I was able to isolate one problem:
It seems that when you use sin and cos in the same function, the optimizer will use __sincosf_stret to calculate both at once but this result in a link error.
So what did I do:
- Create a new XCode project, cmd line tool, objectiv-c
- Change the main.m to main.mm to allow C++
- Change main as:
#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;
}
I'm using in my project:
- C++: C++14, libC++
- Base SDK: MacOS
- Deployment target 10.14
Building in Debug works fine, building for profiling (Release version with optimization) will fail giving the following error message:
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
When I change the deployment target to 10.7, the sincosf_stret is found, but I get 2 ARC errors:
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
Trying different deployment targets give:
- 10.7: 2 ARC link errors
- 10.10: 2 ARC link errors AND _sincosf_ret error
- 10.12 or higher: _sincosf_ret error
I can't belief that it is not possible to use sin/cos in one function. So I hope someone has a hint to resolve this problem. I have to build multiplatform libraries. It worked fine for years. Recently I switched to XCode 11 and to BaseSDK "MacOS". Before I used some special tool to reinstall BaseSDK 10.7 for XCode 9. I wanted to get rid of the necessety of using this special tool for reinstalling BaseSDK 10.7 after each XCode update.
Thanks,
Rudi
First I built it on 10.15.3. Then I tried 10.14.6. I ran it under the time profiler with default settings, which appear to be "fastest,smallest". I also tried running the exported archive from the command line. Again, no problems.
But isn't your complain about linking? What does it matter how I run it then?