PDA

View Full Version : using Carbon api on mac error:Undefined symbols for architecture x86_64



fong
2nd April 2015, 03:19
Hi

I'm using Qt5.3(qt-opensource-mac-x64-clang-5.3.1.dmg) on mac os x 10.10.1,xcode6

I need to use the GetKeys() in carbon in a staticlib,so I did the following:
1).add header file in .cpp

#include <Carbon/Carbon.h>
2).add framework include in xxx.pro

LIBS += -framework Carbon

mylib compiles ok,but when myapp to link the lib, it throws error:

Undefined symbols for architecture x86_64:
"_GetKeys", referenced from:
Platform::get_keyboard_modifiers() in libxxx.a(platform.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've tryed to add QMAKE_LFLAGS += -L/System/Library/Frameworks/Carbon in xxx.pro,but it didn't work.

can anyone tell me why,or is there a way in Qt to take the place of Carbon/GetKeys()?
Thanks

fong
2nd April 2015, 12:19
Solved.

What I did:
1).remove "LIBS += -framework Carbon" from xxx.pro(xxx.pro is project file of xxxlib)
2).add following to myapp.pro(myapp.pro is project file of myapp,who used the xxxlib)
"LIBS += /System/Library/Frameworks/Carbon.framework/Carbon",
instead of "LIBS += -framework Carbon"

So it seems to be a library path problem,but I want to know why and the internal theory.
Can anyone tell me, or anything talked in Qt's or Apple's documents?

Thanks

jefftee
2nd April 2015, 16:41
I would have thought the correct way to include the framework would have been:

LIBS += -F/System/Library/Frameworks/Carbon.framework/Carbon -framework Carbon
INCLUDEPATH += /System/Library/Frameworks/Carbon.framework/Carbon/Headers/

Have you tried the above?

fong
3rd April 2015, 03:11
Thank you
I tried, it also worked.
Could you please which's the most correct way to include the framework? Any document talked about it?

jefftee
3rd April 2015, 05:01
Thank you
I tried, it also worked.
Could you please which's the most correct way to include the framework? Any document talked about it?
The method I posted is the most correct in my opinion. Should work with any framework, etc.

As far as I know, all of the documentation regarding frameworks in the toolchain are Apple docs (you can google around to see what you can find), since the Xcode toolchain is used for Mac compiling and linking. qmake just provides a way for the developer to pass options to the compile and link steps, but those are not Qt options, they're options for the compiler/linker, etc.