Static linking on Mac OS ?
-
Hi guys,
I'm trying to port my windows Qt app to Mac OS.
My project use an external library, on windows I did compile this external library myself to "Ant_lib.lib" and use that lib for compile in my main project.On Mac OS, I did the same thing, I compiled the external lib to "libANT_LIB.a" and then try to use it to compile my main project. However, I get some error on the compile.
I heard that you cannot static link libraries on mac OS, is it true? "source":http://nelsonslog.wordpress.com/2013/04/24/macos-doesnt-support-static-binaries/Here is the .pro file used to compile the static library :
@QT -= gui
TARGET = ANT_LIB
TEMPLATE = libCONFIG += staticlib
CONFIG += releaseinclude (common/common.pri)
include (inc/inc.pri)
include (software/ANTFS/ANTFS.pri)
include (software/serial/serial.pri)
include (software/serial/device_management/device_management.pri)
include (software/system/system.pri)
include (software/USB/USB.pri)
include (software/USB/device_handles/device_handles.pri)
include (software/USB/devices/devices.pri)
include (software/USB/iokit_driver/iokit_driver.pri)@For the record, here are the errors i'm getting when building my main project :
@Undefined symbols for architecture x86_64:
"_CFDictionarySetValue", referenced from:
USBDeviceHandleSI::GetAllDevices() in libANT_LIB.a(usb_device_handle_vcp.o)
USBDeviceHandleSI::FindModems(unsigned int*) in libANT_LIB.a(usb_device_handle_vcp.o)
"_CFNumberGetValue", referenced from:
USBDeviceSI::USBDeviceSI(unsigned int const&) in libANT_LIB.a(usb_device_vcp.o)
USBDeviceSI::GetDeviceNumber(unsigned int const&, __CFString const*) in libANT_LIB.a(usb_device_vcp.o)@└(°ᴥ°)┘ Thanks if you can direct a newbie Mac user! └(°ᴥ°)┘
-
-
I looked at CFNumber functions. They are a part of
"OS X CoreFoundation framework":https://developer.apple.com/library/mac/documentation/corefoundation/Reference/CFNumberRef/Reference/reference.htmlMaybe you should add CoreFoundation as an external library in you project.
I've never used QtCreator with OS X specific functions so can not help here.
-
Thanks I figured I was missing some libraries.
I added theses 2 libs in my main project .pro
LIBS += -framework IOKit
LIBS += -framework CoreFoundationnow the _CFDictionarySetValue errors and friends are gone!
With this I reduced the list of errors from ~150 to a few left :)Here are the last one, hopefully I can figure those one also
@ "std::_List_node_base::hook(std::_List_node_base*)", referenced from:
IOKitDeviceHandle::SendSyncControlTransfer(unsigned char, unsigned char, unsigned short, unsigned short, unsigned char*, unsigned short, unsigned int, int&) in libANT_LIB.a(iokit_device_handle.o)
IOKitDeviceHandle::SendSyncInterruptTransfer(unsigned char, unsigned char*, int, unsigned int, int&) in libANT_LIB.a(iokit_device_handle.o)
IOKitDeviceHandle::SendSyncBulkTransfer(unsigned char, unsigned char*, int, unsigned int, int&) in libANT_LIB.a(iokit_device_handle.o)
"std::_List_node_base::unhook()", referenced from:
IOKitDeviceHandle::SendSyncControlTransfer(unsigned char, unsigned char, unsigned short, unsigned short, unsigned char*, unsigned short, unsigned int, int&) in libANT_LIB.a(iokit_device_handle.o)
IOKitDeviceHandle::SendSyncInterruptTransfer(unsigned char, unsigned char*, int, unsigned int, int&) in libANT_LIB.a(iokit_device_handle.o)
IOKitDeviceHandle::SendSyncBulkTransfer(unsigned char, unsigned char*, int, unsigned int, int&) in libANT_LIB.a(iokit_device_handle.o)
"std::__throw_length_error(char const*)", referenced from:
std::vector<USBDevice const**, std::allocator<USBDevice const**> >::_M_insert_aux(__gnu_cxx::__normal_iterator<USBDevice const***, std::vector<USBDevice const**, std::allocator<USBDevice const**> > >, USBDevice const** const&) in libANT_LIB.a(usb_device_handle_mac.o)
std::vector<USBDeviceIOKit const**, std::allocator<USBDeviceIOKit const**> >::_M_insert_aux(__gnu_cxx::__normal_iterator<USBDeviceIOKit const***, std::vector<USBDeviceIOKit const**, std::allocator<USBDeviceIOKit const**> > >, USBDeviceIOKit const** const&) in libANT_LIB.a(usb_device_handle_mac.o)@ -
"This maybe the case with std:: errors":http://stackoverflow.com/questions/12920891/std-linker-error-with-apple-llvm-4-1
-
oh nice I fixed it using this:
changing ../Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf
from
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
to
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
"source":http://stackoverflow.com/questions/20342896/solved-qt5-1-qt5-2-mac-os-10-9-mavericks-xcode-5-0-2-undefined-symbolsalso added this to both of my project (static lib and the main project)
CONFIG += c++11
CONFIG += x86_64
CONFIG -= i386Then recompiled and error are gone, thanks!