You are missing an import.
objc_msgSend declared in <objc/message.h> .
objc_getClass declared in <objc/runtime.h> .
sel_getUid and sel_registerName declared in <objc/objc.h> .
Now, given that <objc/objc.h> has already been imported <objc/runtime.h> , importing the latter along with <objc/message.h > should be sufficient.
I tested it in the following example and it works as expected
#include <CoreFoundation/CoreFoundation.h> // Needed for CFSTR #include <objc/runtime.h> #include <objc/message.h> int main(int argc, char *argv[]) { id alert = (id (*)(id, SEL))objc_msgSend((id (*)(id, SEL))objc_msgSend(objc_getClass("NSAlert"), sel_registerName("alloc")), sel_registerName("init")); (void (*)(id, SEL, int))objc_msgSend(alert, sel_getUid("setAlertStyle:"), 1); // NSInformationalAlertStyle is defined in AppKit, so let just use 1 (void (*)(id, SEL, id))objc_msgSend(alert, sel_getUid("setMessageText:"), CFSTR("Hello World!")); (void (*)(id, SEL, id))objc_msgSend(alert, sel_getUid("setInformativeText:"), CFSTR("Hello World!")); (int (*)(id, SEL))objc_msgSend(alert, sel_getUid("runModal")); }
Note
I added an explicit cast to objc_msgSend , as suggested by Greg Parker in the comments.
source share