Comment #0 by reach.supermike — 2015-12-14T19:57:33Z
When I run the code at the bottom of this page on OSX El Capitan with the compiler flag options specified, I get the following errors and cannot proceed:
$ dmd -L-framework -LFoundation test.d
test.d(6): Error: undefined identifier 'selector'
test.d(12): Error: undefined identifier 'selector'
test.d(13): Error: undefined identifier 'selector'
Evidently it really doesn't like 'selector'. Here's the version of DMD I'm running, which I got from Homebrew:
$ dmd --version
DMD64 D Compiler v2.069
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
Comment #1 by doob — 2015-12-15T08:04:22Z
I added the code below for reference. It works perfectly fine for me using Yosemite. It's most likely an issue with the installation of the compiler.
// test.d
module main;
extern (Objective-C)
interface Class
{
NSString alloc() @selector("alloc");
}
extern (Objective-C)
interface NSString
{
NSString initWithUTF8String(in char* str) @selector("initWithUTF8String:");
void release() @selector("release");
}
extern (C) void NSLog(NSString, ...);
extern (C) Class objc_lookUpClass(in char* name);
void main()
{
auto cls = objc_lookUpClass("NSString");
auto str = cls.alloc().initWithUTF8String("Hello World!");
NSLog(str);
str.release();
}
Comment #2 by reach.supermike — 2015-12-15T08:16:11Z
Here's the fix. It has to do with El Capitan and brew.
I found the fix:
$ sudo brew update
$ sudo brew uninstall --force dmd
$ sudo su
$ cd /Library
$ rm -rfd D
$ exit
$ sudo brew install dmd
This not only takes one from an older dmd to a more current version (in my case, from 2.068 to 2.069), but it also fixes a bug where /Library/D doesn't get updated. (Besides, the El Capitan version of 2.069 now doesn't use /Library/D.)
When I did that, I found I was able to compile like so:
volomike:cpptod4 mike$ dmd -m64 -L-framework -LFoundation test.d
volomike:cpptod4 mike$ ls
test test.d test.o
volomike:cpptod4 mike$ ./test
2015-12-15 03:07:52.669 test[7308:116958] Hello World!
volomike:cpptod4 mike$
So, it not only used an Objective C NSString object, but it fed it to NSLog and I got console output in NSLog format.
Comment #3 by ag0aep6g — 2015-12-15T12:02:20Z
Changing from FIXED to WORKSFORME since this was apparently an installation problem.