ld: symbol(s) not found for architecture arm64

I'm attempting to determine whether there is a currently logged on user via the SCDynamicStoreCopyConsoleUser function.

My code look something along the lines of:

#include <SystemConfiguration/SystemConfiguration.h>

bool isUserLoggedOn()
{
    CFStringRef name = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
    if (name != NULL)
    {
        CFRelease(name);
        return true;
    }
    return false;
}

I am getting the following error output on compilation:

Undefined symbols for architecture arm64:
    "_CFRelease", referenced from:
        isUserLoggedOn() in UserInfo.cpp.o
    "_SCDynamicStoreCopyConsoleUser", referenced from:
        isUserLoggedOn() in UserInfo.cpp.o
ld: symbol(s) not found for architecture arm64
Answered by DTS Engineer in 797230022

You're likely missing a reference to the SystemConfiguration framework in the Link Binary with Libraries build phase.

— Ed Ford,  DTS Engineer

Accepted Answer

You're likely missing a reference to the SystemConfiguration framework in the Link Binary with Libraries build phase.

— Ed Ford,  DTS Engineer

Assuming you get your linking issue sorted out (thanks Ed!), I’d like to get a better idea of what you’re doing with SCDynamicStoreCopyConsoleUser. It’s a tricky API because:

  • There can be zero or more logged in GUI users.

  • They can be a mixture of local (via Fast User Switching) and remote (via Screen Sharing) users.

Many folks I see trying to use this routine don’t understand these subtleties, and thus write code that breaks when it encounter some the first time.

So, what are you expecting to do with SCDynamicStoreCopyConsoleUser?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I'm attempting to resolve the name of the current logged on user, or the last logged on user if there is no current logged on user. This data is only being collected for the purposes of reporting.

It's an attempt to recreate logic running on a windows application that checks the attributes of the explorer.exe process to determine the user, and falls back on querying the wmi.

Also thank you Ed, the solution to my problem was to link the frameworks required in my CMake config as follows:

find_library(SYSTEM_CONFIGURATION SystemConfiguration REQUIRED)
find_library(CORE_FOUNDATION CoreFoundation REQUIRED)
target_link_libraries(<target name> PRIVATE ${SYSTEM_CONFIGURATION} ${CORE_FOUNDATION})
ld: symbol(s) not found for architecture arm64
 
 
Q