I'm trying to create Swift OS X app now, and found difficulty using ScriptingBridge.
I included proper iTunes.h file, and Xcode is not giving any error when I wrote "iTunesApplication" as type.
However, when I compile(run) the app, it gives me error :(
Does anybody know about this issue?
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_iTunesApplication", referenced from:
__TFC12LoveYouChloe11AppDelegate10showWindowfS0_FPSs9AnyObject_T_ in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And here is my code:
var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") as iTunesApplication
iTunes.playpause()
The best way to solve this is to take the generated Objective-C Scripting Bridge header and convert it into a native Swift. I wrote a Python script (here) that can do that for you. You can see my answer here for a better explanation of what exactly is going on if you're interested.
Instead of
var iTunes: iTunesApplication = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
use
var iTunes: AnyObject = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
Sometimes the compiler gets confused when you are accessing two or more properties in a row(no idea why) so you may need to use a temporary variable. E.g.:
Instead of:
let songName: String = iTunes.playlists[0].songs[0].name
Try:
let song: AnyObject = iTunes.playlists[0].songs[0]
let songName = song.name
Or Alternatively the faster (this also works if you declare iTunes as an SBApplication) :
let songName: String = iTunes.valueAtIndex(0, inPropertyWithKey: "playlists").valueAtIndex(0, inPropertyWithKey: "songs").valueForKey("name")
EDIT:
You can also generate the .swift headers as specified here: https://github.com/tingraldi/SwiftScripting
Related
I meet an error called "Symbol not found" on matlab. The error message is in below.
Symbol not found: __ZNKSt5ctypeIcE13_M_widen_initEv
Referenced from: blabla/lib/buildW.mexmaci64
Expected in: /usr/lib/libstdc++.6.0.9.dylib
There are quite bunch of questions like me, but I never found the solution of this problem. The former threads mentioned conflicts between the updated clang and the clang used.
Here are exmaples of questions on the similar question.
Need help finding Undefined Symbols
Handling "dyld: lazy symbol binding failed: Symbol not found" error when nm does not find symbol
https://github.com/Homebrew/homebrew-core/issues/4902
I currently installed Xcode 9.2.
And in matlab, I use MacOSX10.13.sdk like below.
>> edit ([matlabroot '/bin/maci64/mexopts/clang++_maci64.xml'])
...
...
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" />
<cmdReturns name="find $$ -name MacOSX10.13.sdk" />
Also, I found that there are three files in "/usr/lib"
/usr/lib/libstdc++.6.0.9.dylib
/usr/lib/libstdc++.6.dylib
/usr/lib/libstdc++.dylib
Can anyone help me?
The symbol __ZNKSt5ctypeIcE13_M_widen_initEv (demangled std::ctype<char>::_M_widen_init() const) is defined in libstdc++.dylib but if you execute
nm /usr/lib/libstdc++.dylib | fgrep __ZNKSt5ctypeIcE13_M_widen_initEv
you will get
0000000000006a14 t __ZNKSt5ctypeIcE13_M_widen_initEv
as result. The t means that it's defined in the TEXT section but it's a local symbol which cannot referenced from outside the library.
Clang in Xcode uses
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib/libstdc++.tbd
for linking instead of /usr/lib/libstdc++.dylib. This is a human readable file which contains only the name of the public symbols in libstdc++.dylib. Since the symbol above is private it is not listed in the .tbd file.
I am trying to create a nsmanagedobject (User) by going to the Editor menu and then selecting Create NSManagedObject Subclass...this generates four files:
User+CoreDataClass.h
User+CoreDataClass.m
User+CoreDataProperties.h
User+CoreDataProperties.m
In one of my viewcontrollers I import User+CoreDataClass.h and then have this code:
//create new account entity
User* thisUser = [NSEntityDescription
insertNewObjectForEntityForName:#"User"
inManagedObjectContext:self.myController.myDataManager.managedObjectContext];
When I then build the app, I get the following clang error:
duplicate symbol _OBJC_CLASS_$_User in:
/Users/xxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/StarDate-fzkjccyoiwhfvvczdwkvkmtbioqw/Build/Intermediates/StarDate.build/Debug-iphonesimulator/StarDate.build/Objects-normal/x86_64/User+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_User in:
/Users/xxxxxxxxxxxx/Library/Developer/Xcode/DerivedData/StarDate-fzkjccyoiwhfvvczdwkvkmtbioqw/Build/Intermediates/StarDate.build/Debug-iphonesimulator/StarDate.build/Objects-normal/x86_64/User+CoreDataClass.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried cleaning the app and deleting my derived data but that had no results. The only way I can clear the error is to delete the generated files. Which obviously is not going to be what I need. Why is XCode creating duplicate files off this menu command? Is there a setting that I missed?
Thanks
You are manually creating NSManagedObject subclasses, that Xcode 8 already has created for you and thus get duplicated symbols.
You can find detailed information how to solve this in this answer.
I'm trying to integrate WebRTC in one OSX Desktop application and I'm getting some errors when I try to link with webRTC library. The issue is:
Undefined symbols for architecture x86_64:
"_AVMediaTypeMuxed", referenced from:
cricket::GetAVFoundationVideoDevices(std::vector<cricket::Device, std::allocator<cricket::Device> >*) in libWebRTC-arm64-debug.a(libjingle_media.macdevicemanagermm.o)
This tell me that I have not defined this symbol in my libjingle_media.a, wich is true according with it:
$ nm libjingle_media.a | grep _AVMediaTypeMuxed
warning: /Applications/Xcode64.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: no name list
U _AVMediaTypeMuxed
I have built WebRTC using this flags:
GYP_DEFINES="build_with_libjingle=1 build_with_chromium=0 libjingle_objc=1 OS=mac target_arch=x64"
GYP_GENERATORS="ninja"
GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out_mac"
and of course with ninja, running previously gclient runhooks. Any idea about what is happening with this?
To solve this issue, you need to use a particular framework that implements the function, in this case a framework called AVFoundation
I'm trying to get a simple OCMock test for OSX up and running, but can't seem to get the install right. I believe I've followed the instructions, but the test build is failing at the link step.
Within fooTests.m:
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#interface fooTests : XCTestCase
#end
#implementation fooTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testOCMockPass {
id mock = [OCMockObject mockForClass:NSString.class];
[[[mock stub] andReturn:#"mocktest"] lowercaseString];
NSString *returnValue = [mock lowercaseString];
STAssertEqualObjects(#"mocktest", returnValue, #"Should have returned the expected string.");
}
#end
But on build, I get the following warnings/errors:
fooTests.m:56:5: Implicit declaration of function 'STAssertEqualObjects' is invalid in C99
Undefined symbols for architecture x86_64:
"_STAssertEqualObjects", referenced from:
-[fooTests testOCMockPass] in fooTests.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've got "Link Binary with Library" linking with XCTest & OCMock in the test build phase. OCMock.framework is in the base directory, which is also in the search path for frameworks and for headers. Can anyone assist in telling me what I'm doing wrong please?
It looks as though the compiler doesn't know what STAssertEqualObjects() is (i.e. I haven't included something) and hence it doesn't know what to link with, hence the other 2 errors. I just don't know what else I need to include.
This is not an OCMock problem. You are using XCUnit (the Xcode 5 unit testing framework), but you are calling STAssertEqualObjects (from OCUnit, the Xcode 4 unit testing framework). Simply change that to XCTAssertEqualObjects.
I am trying to build an application in Xcode 3.2.4 and am getting the following linker error:
Undefined symbols:
"___block_global_1", referenced from:
___block_holder_tmp_1.120 in foobarbaz.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I'm at a loss to explain what I've done in my source file that might be causing the error. I do have a block that I am defining as a global variable, like so:
typedef void(^error_block_t)(NSError* error);
error_block_t error_handler_s = ^void(NSError* error)
{
//...
}
This block is defined in an empty namespace in the source (I'm compiling Objective-C++.) Everything compiles without error.
Update: Moving the block to be a local variable for the routine that references it is a viable (though not preferred) workaround.
What gives?
If the error_handler_s is not intended to be exported, you could make it static as another workaround.
namespace {
...
static error_block_t error_handler_s = ^void(NSError* error) { ... };
...
}
Otherwise, I believe this is a bug in gcc.
At this point I believe this issue to be a bug.