38

I'd like to import runtime's header to use objc_msgSend but I'm getting:

error: NSObjCRuntime.h: No such file or directory

Should I add something to the header search path?

3 Answers 3

61

You need to include <objc/message.h> (you'll find the related headers in /usr/include/objc) and link to the objc (/usr/lib/libobjc.dylib) library.

1
  • 1
    It worked! Can you share where did you find that? I've browsed the apple docs, google code search, and nothing ! Feb 4, 2011 at 10:04
38

#import <Foundation/NSObjCRuntime.h> does work

but you probably need

#import <objc/runtime.h>

like this Apple example does

upd: since iOS 7 #import <Foundation/NSObjCRuntime.h> replaced to #import <objc/NSObjCRuntime.h> but i recommend to use #import <objc/runtime.h> anyway

1
  • 2
    The method objc_msgSend is declared in <objc/message.h>, not in <objc/runtime.h>. So you will get a warning for implicitly declaring library function.
    – DawnSong
    Sep 28, 2015 at 5:30
2

When using Xcode 6 and later, you will get an error after #include<objc/message.h>. It can be resolved like this

#include <objc/message.h>
void foo(void *object) {
  typedef void (*send_type)(id, SEL, int);
  send_type func = (send_type)objc_msgSend;
  func(object, sel_getUid("foo:"), 5);
}

http://devstreaming.apple.com/videos/wwdc/2014/417xx2zsyyp8zcs/417/417_whats_new_in_llvm.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.