Objective-c character ++ not found weirdness

hej.h

void hej();

hej.m

void hej(){}

main.mm

#import "hej.h"

int main(int argc, char *argv[])
{

}

This gives me:

referenced "hej ()": _main in main.o character not found

If I rename main.mm to main.m (single m) or hej.m to mm or cpp, then it will work. (Although none of these "solutions" is preferable. Imagine that you want to use c-lib in objC ++ - you would not want to change the entire library, you probably could not even, and you need to use it in objC + +.)

What exactly is going on here?

+5
source share
1 answer

C (*.c, *.m) void hej() C _hej. ++ (*.cc, *.mm, ..), ++ 'mangled name', . ( , , void hej(int) void hej(char*)). hej.m C. main.mm ++, .

, , main.mm C, ++. hej.h, - , , hej.h C ++:

/* hej.h */
#ifdef __cplusplus
extern "C" {
#endif

void hej();

#ifdef __cplusplus
}
#endif

hej.h, main.mm :

extern "C" {
#import "hej.h"
}

int main(int argc, char *argv[])
{
}
+17

All Articles