Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile pragma doesn't work for Obj-C #9492

Open
iffy opened this issue Oct 24, 2018 · 0 comments
Open

compile pragma doesn't work for Obj-C #9492

iffy opened this issue Oct 24, 2018 · 0 comments

Comments

@iffy
Copy link
Contributor

iffy commented Oct 24, 2018

Using the compile pragma to compile an Obj-C file doesn't work (at least not in the same way as inlining the Obj-C code using emit works).

Example

Given two files (sample.nim and guts.m):

{.compile: "guts.m" .}

type
  Id {.importc: "id", header: "<Cocoa/Cocoa.h>", final.} = distinct int

proc newGreeter: Id {.importobjc: "Greeter new", nodecl.}
proc greet(self: Id, x, y: int) {.importobjc: "greet", nodecl.}

var g = newGreeter()
g.greet(12, 34)
#include <Cocoa/Cocoa.h>
@interface Greeter:NSObject
{
}

- (void)greet:(long)x y:(long)dummy;
@end

#include <stdio.h>
@implementation Greeter

- (void)greet:(long)x y:(long)dummy
{
  printf("Hello, World!\n");
}
@end

#include <stdlib.h>

Current Output

$ nim objc -r sample.nim 
Hint: used config file '/Users/matt/lib/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: sample [Processing]
CC: guts
CC: sample
CC: stdlib_system
Error: execution of an external compiler program 'clang -c  -w  -I/Users/matt/lib/Nim/lib -o /Users/matt/.cache/nim/sample_d/sample.m.o /Users/matt/.cache/nim/sample_d/sample.m' failed with exit code: 1

/Users/matt/.cache/nim/sample_d/sample.m:109:30: error: use of undeclared identifier 'Greeter'; did you mean 'kNeuter'?
        g_P5lmsTG5mYVhG5BJh5KFZQ = [Greeter new];
                                    ^~~~~~~
                                    kNeuter
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/SpeechSynthesis.framework/Headers/SpeechSynthesis.h:149:3: note: 'kNeuter' declared here
  kNeuter                       = 0,
  ^
1 error generated.

Expected Output

Hello World!

Additional Information

It works if I include the Obj-C code using an emit like this:

{.emit: """
#include <Cocoa/Cocoa.h>
@interface Greeter:NSObject
{
}

- (void)greet:(long)x y:(long)dummy;
@end

#include <stdio.h>
@implementation Greeter

- (void)greet:(long)x y:(long)dummy
{
  printf("Hello, World!\n");
}
@end

#include <stdlib.h>
""".}

type
  Id {.importc: "id", header: "<Cocoa/Cocoa.h>", final.} = distinct int

proc newGreeter: Id {.importobjc: "Greeter new", nodecl.}
proc greet(self: Id, x, y: int) {.importobjc: "greet", nodecl.}

var g = newGreeter()
g.greet(12, 34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants