Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OSX clang link error
Forum Updated to NodeBB v4.3 + New Features

OSX clang link error

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 435 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RodrigoCanellas
    wrote on last edited by
    #1

    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 and LIBS += -lc++ in the .pro file, as I read in another forum, but with no results.

    Does anyone know which libraries should I link?

    Thanks!

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RodrigoCanellas
      wrote on last edited by
      #2

      The solution I found was to add LIBS += -framework Foundation -framework SystemConfiguration to the .pro

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Usually the include path of macOS headers is a good tip to what framework the header belongs to.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved