OSX clang link error
Solved
General and Desktop
-
Hi!
I have a very simple project, just to test lists network interfaces, which
.pro
file is:TEMPLATE = app CONFIG += console c++17 CONFIG -= app_bundle CONFIG -= qt SOURCES += \ main.cpp
The
main.cpp
file is:#include <CoreFoundation/CFString.h> #include <SystemConfiguration/SCNetworkConfiguration.h> #include <iostream> int main() { int count = 0; CFArrayRef list; list = SCNetworkInterfaceCopyAll(); if (list != NULL) { count = CFArrayGetCount(list); } if (count == 0) { return 1; } for (int i = 0; i < count; i++) { SCNetworkInterfaceRef this_if; CFStringRef this_if_name; this_if = (SCNetworkInterfaceRef)CFArrayGetValueAtIndex(list, i); this_if_name = SCNetworkInterfaceGetBSDName(this_if); if (this_if_name == NULL) { continue; } { const CFIndex kCStringSize = 512; char str[kCStringSize]; bzero(str,kCStringSize); CFStringGetCString(this_if_name, str, kCStringSize, kCFStringEncodingUTF8); std::cout << str << std::endl; } } return 0; }
The compiler output:
12:08:47: Running steps for project list_network_interfaces... 12:08:47: Starting: "/usr/bin/make" clean -j4 /Users/rodrigo.canellas/Documents/Qt/5.15.1/clang_64/bin/qmake -o Makefile ../list_network_interfaces/list_network_interfaces.pro -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug rm -f main.o rm -f *~ core *.core 12:08:48: The process "/usr/bin/make" exited normally. 12:08:48: Starting: "/Users/rodrigo.canellas/Documents/Qt/5.15.1/clang_64/bin/qmake" /Users/rodrigo.canellas/studies/list_network_interfaces/list_network_interfaces.pro -spec macx-clang CONFIG+=debug CONFIG+=x86_64 CONFIG+=qml_debug 12:08:48: The process "/Users/rodrigo.canellas/Documents/Qt/5.15.1/clang_64/bin/qmake" exited normally. 12:08:48: Starting: "/usr/bin/make" -f /Users/rodrigo.canellas/studies/build-list_network_interfaces-Desktop_Qt_5_15_1_clang_64bit-Debug/Makefile qmake_all make: Nothing to be done for `qmake_all'. 12:08:48: The process "/usr/bin/make" exited normally. 12:08:48: Starting: "/usr/bin/make" -j4 /Library/Developer/CommandLineTools/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++1z -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wall -Wextra -fPIC -DQT_QML_DEBUG -I../list_network_interfaces -I. -I../../Documents/Qt/5.15.1/clang_64/mkspecs/macx-clang -o main.o ../list_network_interfaces/main.cpp /Library/Developer/CommandLineTools/usr/bin/clang++ -stdlib=libc++ -headerpad_max_install_names -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wl,-rpath,@executable_path/../Frameworks -o list_network_interfaces main.o Undefined symbols for architecture x86_64: "_CFArrayGetCount", referenced from: _main in main.o "_CFArrayGetValueAtIndex", referenced from: _main in main.o "_CFStringGetCString", referenced from: _main in main.o "_SCNetworkInterfaceCopyAll", referenced from: _main in main.o "_SCNetworkInterfaceGetBSDName", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [list_network_interfaces] Error 1 12:08:50: The process "/usr/bin/make" exited with code 2. Error while building/deploying project list_network_interfaces (kit: Desktop Qt 5.15.1 clang 64bit) When executing step "Make" 12:08:50: Elapsed time: 00:03.
I tried to include
QMAKE_CXXFLAGS += -framework Foundation
andLIBS += -lc++
in the.pro
file, as I read in another forum, but with no results.Does anyone know which libraries should I link?
Thanks!
-
The solution I found was to add
LIBS += -framework Foundation -framework SystemConfiguration
to the.pro
-
Hi and welcome to devnet,
Usually the include path of macOS headers is a good tip to what framework the header belongs to.