On 2014-11-06 17:06, Christian Schneider wrote:
Oh, just found out, it seems that currently the extern C declarations
don't work. This comes from the original Chocolat range.d

extern (C) {

     NSRange      NSUnionRange(NSRange range1, NSRange range2) ;
     NSRange      NSIntersectionRange(NSRange range1, NSRange range2) ;
     NSString     NSStringFromRange(NSRange range) ;
     NSRange      NSRangeFromString(NSString aString) ;

     NSRange     NSMakeRange(NSUInteger loc, NSUInteger len) ;
     NSUInteger     NSMaxRange(NSRange range) ;
     bool         NSEqualRanges(NSRange range1, NSRange range2) ;

When trying to use NSMakeRange i get:

Undefined symbols for architecture x86_64:
   "_NSMakeRange", referenced from: ....

I wasn't able to link with the symbol either. But when I tried in Objective-C it worked, but only when I imported Foundation.h, not when I declared NSMakeRange myself. That got me thinking and I had a look in the Foundation NSRange.h header file. "NSMakeRange" and friends are implement directly in the header file to allow inlining. D cannot access inlined functions if they don't exist in a library.

In general you need to reimplement these functions in D. In this particular case, with NSMakeRange, you can just do this in D instead:

auto range = NSRange(1, 2);

The above is a syntax that is allowed for all structs. If you really want to type "NSMakeRange" you need implement the function yourself or make an alias and use the above syntax:

alias NSMakeRange = NSRange;

The downside with the alias is that it allows to use "NSMakeRange" as a struct as well:

NSMakeRange range;

Also when I tried to declare / use extern strings like from

APPKIT_EXTERN NSString *NSApplicationDidHideNotification;

I found no way to get this working. Is this a limitation of the current
64 bit port?

I think that should work. How did you declare it? It should be declared like this:

extern (C) extern NSString NSApplicationDidHideNotification;

I tried with a standard D compiler and void* instead of NSString and that worked.

"extern (C)" tells the compiler to use C linkage, the second "extern" tells the compiler this symbols is defined somewhere else, i.e. in some library.

/Jacob Carlborg

Reply via email to