-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;
}
答案 0 :(得分:3)
您需要链接CoreFoundation.framework,这是您在第一行代码中包含的内容。 (CF
中的___CFConstantStringClassReference
和kCFBooleanTrue
代表CoreFoundation。