如何使用 Clang 链接 macOS 上的 Core 框架?

sdg*_*sdh 4 c++ macos linker clang

我正在尝试使用 Clang 在 macOS 上构建 C++ 应用程序。我正在使用 CoreAudio API,因此我需要链接 CoreServices 框架。但是,我收到以下错误:

clang:错误:未知参数:'-framework CoreServices'

这是我的 Clang 版本:

clang --version 
clang version 3.9.1 (tags/RELEASE_391/final)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /usr/local/bin
Run Code Online (Sandbox Code Playgroud)

这些是我的链接器标志:

-framework CoreServices
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

fle*_*hie 6

以下程序代码打印出输出设备占用的大小(这只是为了使用 CoreAudio API 的一些功能):

// main.cpp
#include <cstdlib>
#include <cstdio>

#include <CoreAudio/CoreAudio.h>
#include <CoreServices/CoreServices.h>

int
main (void)
{
    AudioObjectPropertyAddress property = {
        kAudioHardwarePropertyDevices,
        kAudioObjectPropertyScopeGlobal,
        kAudioObjectPropertyElementMaster
    };

    OSStatus status;
    UInt32 size;

    status = AudioObjectGetPropertyDataSize(
            kAudioObjectSystemObject,
            &property,
            0,
            NULL,
            &size);

    printf("status(%d), size: %d\n", status, size);

    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

该 C++ 程序可以通过以下方式编译:

clang -framework CoreServices -framework CoreAudio main.cpp
Run Code Online (Sandbox Code Playgroud)

并会生成一个a.out可执行文件,然后您可以使用它调用

./a.out
> status(0), siz
Run Code Online (Sandbox Code Playgroud)