Referencing macOS SDK header is not resolving when compiling with clang - objective-c

I'm trying to link my Rust library with a macOS SDK. When trying to include a header from a macOS SDK in an .m file and compiling, the linker returns an error.
Code example:
#import <Foundation/Foundation.h>
#import <IOKit/KextManager.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
NSLog(#"Something");
}
return 0;
}
Error:
main.m:11:9: fatal error: 'IOKit/KextManager.h' file not found
#import <IOKit/KextManager.h>
^~~~~~~~~~~~~~~~~~~~~ 1 error generated.
When I reference the full path, the header gets included but I get other linker errors for some classes not found:
Code example:
#import <Foundation/Foundation.h>
#import "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/kext/KextManager.h"
int main(int argc, const char * argv[]) {
#autoreleasepool {
NSLog(#"Something");
}
return 0;
}
Error I'm getting:
Undefined symbols for architecture x86_64: "_NSLog", referenced
from:
_main in main-891267.o "___CFConstantStringClassReference", referenced from:
CFString in main-891267.o "_objc_autoreleasePoolPop", referenced from:
_main in main-891267.o "_objc_autoreleasePoolPush", referenced from:
_main in main-891267.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to
see invocation)
I suspect this is because other headers are not resolved properly.
How to make headers resolving to work properly so all includes work not only from Xcode?
This code compiles and runs directly from Xcode without any additional references but is not compiling from terminal:
#import <Foundation/Foundation.h>
#import "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/kext/KextManager.h"
//#import <IOKit/KextManager.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
CFDictionaryRef result = KextManagerCopyLoadedKextInfo(NULL, NULL);
NSLog(#"%#", result);
}
return 0;
}
Getting same linker error:
ld: warning: URGENT: building for OSX, but linking against dylib
(/usr/lib/libSystem.dylib) built for (unknown). Note: This will be an
error in the future. Undefined symbols for architecture x86_64:
"_KextManagerCopyLoadedKextInfo", referenced from:
_main in main-abff3c.o "_NSLog", referenced from:
_main in main-abff3c.o "___CFConstantStringClassReference", referenced from:
CFString in main-abff3c.o "_objc_autoreleasePoolPop", referenced from:
_main in main-abff3c.o "_objc_autoreleasePoolPush", referenced from:
_main in main-abff3c.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to
see invocation)
Update 2:
Compiler command:
clang -framework IOKit -framework Foundation main.m -o main
Works with full path to header, but does not for #include <IOKit/KextManager.h>

The solution is to link Xcode included frameworks into include folder.
For stable release:
ln -s /Applications/Xcode.app/Contents/Frameworks/ /usr/local/include/
And for Xcode beta:
ln -s /Applications/Xcode-beta.app/Contents/Frameworks/
/usr/local/include/
Then KextManager imported like this:
#import <IOKit/kext/KextManager.h>

Related

iOS using microsoft band build error

I created the project, imported the microsoft band sdk
http://developer.microsoftband.com/download/Microsoft%20Band%20SDK%20for%20iOS.zip
And I tried intimate the sdk sensor sample
http://developer.microsoftband.com/download/Microsoft%20Band%20SDK%20and%20Samples%20for%20iOS.zip
my viewcontroller.h:
#import <UIKit/UIKit.h>
#import <MicrosoftBandKit_iOS/MicrosoftBandKit_iOS.h>
#interface ViewController : UIViewController<MSBClientManagerDelegate>
#property (strong, nonatomic) IBOutlet UIActivityIndicatorView *ConnectionIndicator;
.
.
.
other UI components
.
.
.
#end
my viewcontroller.m:
#import "ViewController.h"
#interface ViewController ()
#property (weak,nonatomic)MSBClient *client;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[MSBClientManager sharedManager].delegate = self;
_client = [[[MSBClientManager sharedManager] attachedClients]firstObject];
if ( _client == nil ) {
NSLog(#"Band connected failed: No Band paired");
return;
}else{
[[MSBClientManager sharedManager] connectClient:_client];
NSLog(#"Trying to connect to Band...");
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)clientManager:(MSBClientManager *)clientManager clientDidConnect:(MSBClient *)client{
}
-(void)clientManager:(MSBClientManager *)clientManager clientDidDisconnect:(MSBClient *)client{
}
-(void)clientManager:(MSBClientManager *)clientManager client:(MSBClient *)client didFailToConnectWithError:(NSError *)error{
}
#end
Warning:
Ld DerivedData/SenseWatch/Build/Products/Debug-iphoneos/SenseWatch.app/SenseWatch normal arm64
cd /Users/Jieyi/Documents/Repo/SenseWatch
export IPHONEOS_DEPLOYMENT_TARGET=8.0
export PATH="/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode-beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk -L/Users/Jieyi/Documents/Repo/SenseWatch/DerivedData/SenseWatch/Build/Products/Debug-iphoneos -F/Users/Jieyi/Documents/Repo/SenseWatch/DerivedData/SenseWatch/Build/Products/Debug-iphoneos -F/Users/Jieyi/Downloads/MicrosoftBandKit_iOS_SAMPLES_1.3.10427.1 -filelist /Users/Jieyi/Documents/Repo/SenseWatch/DerivedData/SenseWatch/Build/Intermediates/SenseWatch.build/Debug-iphoneos/SenseWatch.build/Objects-normal/arm64/SenseWatch.LinkFileList -Xlinker -rpath -Xlinker #executable_path/Frameworks -miphoneos-version-min=8.0 -dead_strip -fembed-bitcode-marker -fobjc-arc -fobjc-link-runtime -framework MicrosoftBandKit_iOS -Xlinker -dependency_info -Xlinker /Users/Jieyi/Documents/Repo/SenseWatch/DerivedData/SenseWatch/Build/Intermediates/SenseWatch.build/Debug-iphoneos/SenseWatch.build/Objects-normal/arm64/SenseWatch_dependency_info.dat -o /Users/Jieyi/Documents/Repo/SenseWatch/DerivedData/SenseWatch/Build/Products/Debug-iphoneos/SenseWatch.app/SenseWatch
ld: warning: URGENT: all bitcode will be dropped because '/Users/Jieyi/Downloads/MicrosoftBandKit_iOS_SAMPLES_1.3.10427.1/MicrosoftBandKit_iOS.framework/MicrosoftBandKit_iOS(MSBClientManager.o)' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.
ld: warning: URGENT: all bitcode will be dropped because '/Users/Jieyi/Downloads/MicrosoftBandKit_iOS_SAMPLES_1.3.10427.1/MicrosoftBandKit_iOS.framework/MicrosoftBandKit_iOS(MSBBLEProvider.o)' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.
ld: warning: URGENT: all bitcode will be dropped because '/Users/Jieyi/Downloads/MicrosoftBandKit_iOS_SAMPLES_1.3.10427.1/MicrosoftBandKit_iOS.framework/MicrosoftBandKit_iOS(MSBClient.o)' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.
ld: warning: URGENT: all bitcode will be dropped because '/Users/Jieyi/Downloads/MicrosoftBandKit_iOS_SAMPLES_1.3.10427.1/MicrosoftBandKit_iOS.framework/MicrosoftBandKit_iOS(MSBDeviceManager.o)' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.
...
Error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_CBUUID", referenced from:
objc-class-ref in MicrosoftBandKit_iOS(MSBBLEProvider.o)
objc-class-ref in MicrosoftBandKit_iOS(MSBSpple.o)
objc-class-ref in MicrosoftBandKit_iOS(MSBPeripheral.o)
objc-class-ref in MicrosoftBandKit_iOS(MSBSensorManagerUtility.o)
objc-class-ref in MicrosoftBandKit_iOS(MSBZippyPushV2.o)
objc-class-ref in MicrosoftBandKit_iOS(MSBZippyCargo.o)
objc-class-ref in MicrosoftBandKit_iOS(MSBZippyCargoV2.o)
...
"_CBCentralManagerOptionShowPowerAlertKey", referenced from:
+[MSBBLEProvider buildCBCentralManagerOptions] in MicrosoftBandKit_iOS(MSBBLEProvider.o)
"_OBJC_CLASS_$_CBCentralManager", referenced from:
objc-class-ref in MicrosoftBandKit_iOS(MSBBLEProvider.o)
"_CBCentralManagerOptionRestoreIdentifierKey", referenced from:
+[MSBBLEProvider buildCBCentralManagerOptions] in MicrosoftBandKit_iOS(MSBBLEProvider.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
and I am pretty new to Xcode and objective-c
I have no idea what is this.
You are missing the CoreBuetooth framework. Include The framework under the link with libraries section.

clang: error: linker command failed with exit code 1 (use -v to see invocation) duplicate symbol _sprites for _game

I have a problem with my project. when i build my project, i have an error.
It shows duplicate symbol _sprites for _game
ld: 2 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I had this same error, it was because I defined a constant with the same name in two separate .m files. Once I changed the name in one of them, it compiled.
For example in my ViewController.m I had:
#import "ViewController.h"
const int IPHONE4 = 480;
and in my Menu.m:
#import "Menu.h"
const int IPHONE4 = 480;
I changed my Menu.m to:
#import "Menu.h"
const int IPHONE4H = 480;

Undefined symbols for architecture x86_64 in hello world

Today I'm learning Objective-C without Xcode following this Guide
Here's the hello world:
makclass.m
#import "makclass.h"
#import <stdio.h>
#implementation MakClass
-(void) age {
printf("Age is %d", age);
}
-(void) setAge: (int) a {
age = a;
}
+(void) say {
printf("Haha");
}
#end
makclass.h
#import <Foundation/NSObject.h>
#interface MakClass: NSObject {
int age;
}
-(void) age;
-(void) setAge: (int) a;
+(void) say;
#end
helloworld.m
#import <stdio.h>
#import "makclass.h"
int main(void) {
printf("Hello World");
MakClass *makclass = [[MakClass alloc] init];
[makclass setAge: 1];
[makclass age];
[MakClass say];
[makclass release];
return 0;
}
And clang helloworld.m give me the following errors:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MakClass", referenced from:
objc-class-ref in helloworld-XEijke.o
"_objc_msgSend", referenced from:
_main in helloworld-XEijke.o
"_objc_msgSend_fixup", referenced from:
l_objc_msgSend_fixup_alloc in helloworld-XEijke.o
l_objc_msgSend_fixup_release in helloworld-XEijke.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You need to make sure you pass in the framework and all the files as well:
clang -framework Foundation -o helloworld helloworld.m makclass.m
Welcome to Objective-C!
When you compile, you need to specify all of the implementation files that helloworld.m requires. Just because the header files are included does not mean that the implementation files will be included as well.
Additionally, since this is Objective-C, make sure you also include the -lObjC flag to include the Objective-C libraries.
So, the command that you should run will look like clang -lObjC helloworld.m makclass.m.
clang will then spit out a program called a.out, which you can run. If you want to change the name from a.out to, say, helloworld, you can specify that with the -o flag. For example:
clang -lObjc -o helloworld helloworld.m makclass.m
Hope this helps!

Calling Functions using Objective-C and C++

Alright, I'm trying to call a function in xcode but apparently it isn't working. I made an objective-c class, and typed in the following code into the implementation file:
#import "Person.h"
#implementation Person
void printthis()
{
NSLog(#"Hi, I have been printed");
}
int main(int argc, const char * argv[])
{
#autoreleasepool {
printthis();
}
return 0;
}
#end
Apparently, it returns the following error in xcode:
ld: 1 duplicate symbol for architecture x86_64
clang: error:
linker command failed with exit code 1 (use -v to see invocation)
Did you already have a main function somewhere else (probably main.m ?). If so the linker got confused -- you are not supposed to have duplicates of main function

Getting Strange Error Running Objective C Code

My project have no visible error but when i try to run it gives following error
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ConcreteScreen", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using my ContactScreen class in ViewController.m
i tried by #class ContactScree and #import "ContactScreen.h"
and in my ViewController i am using it as [ContactScreen myMethod];
when i comment out this line it work fine but now it is giving compile time error :(
yesterday it was wroking fine
here is my code
#import "ViewController.h"
#import "ConcreteScreen.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)btnContactPress:(id)sender{
NSLog(#"Contact Screen");
ConcreteScreen *coontact = [[ConcreteScreen alloc]init];
}
You confused ConcreteScreen and ContactScreen and compiler told you that it isn't aware about ConcreteScreen
Be sure your .m file is included in the project. It's possible to create it, use the header and all but it doesn't go into the build. Also it needs to be in the target.