PDA

View Full Version : Using qmake with an Objective C project



Blackened Justice
4th March 2012, 12:02
Hey everyone,

I'm trying to learn a bit of Objective C, and figured that I could just use a regular qmake project and Qt Creator as an IDE. I didn't find much documentation regarding this, so I just fooled around a bit, trying to see if I could make it work. Well, I can't ;) Here's my current .pro file:

LIBS += -lobjc

OBJECTIVE_HEADERS += Hello.h

OBJECTIVE_SOURCES += Hello.m \
main.m

When I try to compile it, I get the following output:

g++ -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -Wl,-O1 -o objc -L/usr/lib -lobjc -lQtGui -lQtCore -lpthread
/usr/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [objc] Error 1
If I compile it manually, with "gcc -lobjc Hello.m main.m -o Hello" everything goes smoothly, so it's clearly a problem of my understanding of qmake ;)

Cheers

ChrisW67
4th March 2012, 22:33
Try adding:


CONFIG += objective_c

if you are on a Mac. This should pull in the Objective C custom compiler that is going to do something with the OBJECTIVE_SOURCES variable (not OBJECTIVE_HEADERS AFAICT). If you are not on Mac then the feature does not exist, and you will probably have to roll your own.

I've also seen mention that the file extension needs to .mm but I have not verified that.

Blackened Justice
8th March 2012, 23:16
I am not on a Mac (but I'm planning on getting the next-gen iMac), I'm running Arch Linux right now. I will try using the .mm extension, and see if it fixes anything.

Cheers