要链接的库(OSX)

时间:2012-12-24 00:49:29

标签: c macos build linker

是的,请有人帮我。我正在使用-lIOKit进行链接,但显然还需要另一个库。

Undefined symbols for architecture x86_64:
  "___CFConstantStringClassReference", referenced from:
      CFString in code-9daAw9.o
  "_kCFBooleanTrue", referenced from:
      _dimDisplayNow in code-9daAw9.o

以下是代码(位于http://www.cocoabuilder.com/archive/cocoa/191807-sleep-display.html

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>

static int dimDisplayNow(void) 
{
    io_registry_entry_t r =
        IORegistryEntryFromPath(kIOMasterPortDefault,
        "IOService:/IOResources/IODisplayWrangler");
    if(!r) return 1;
    int err = IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"),
                                           kCFBooleanTrue);
    IOObjectRelease(r);
    return err;
}

int main(int argc, char **argv)
{
    dimDisplayNow();
    return 0;
}

1 个答案:

答案 0 :(得分:3)

您需要链接CoreFoundation.framework,这是您在第一行代码中包含的内容。 (CF中的___CFConstantStringClassReferencekCFBooleanTrue代表CoreFoundation。