2016-06-18 90 views
1

我在使用xcode編譯代碼。由於IOKit已經被列入「鏈接二進制與圖書館」,但我仍然得到以下錯誤:io_service_open_extended鏈接失敗

Undefined symbols for architecture x86_64:

"_io_connect_method_scalarI_scalarO"

"_io_service_open_extended"

_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)

雖然這兩個功能在程序中使用下面的代碼定義:

extern "C" kern_return_t io_service_open_extended 
(
    mach_port_t service, 
    task_t owningTask, 
    uint32_t connect_type, 
    NDR_record_t ndr, 
    io_buf_ptr_t properties, 
    mach_msg_type_number_t propertiesCnt, 
    kern_return_t *result, 
    mach_port_t *connection 
); 
extern "C" kern_return_t io_connect_method_scalarI_scalarO(
                  io_connect_t conn, uint32_t selector, 
                  io_scalar_inband64_t scalar_input, 
                  mach_msg_type_number_t scalar_inputCnt, 
                  io_struct_inband_t inband_output, 
                  mach_msg_type_number_t *inband_outputCnt 
                  ); 

但這些函數可以在Apple的API參考中找到,也可以用Google搜索。

+0

您提供自己的函數聲明的事實似乎表明這些函數不適用於公共消費,因爲您應該爲聲明包含一個頭文件。看看[源代碼](https://opensource.apple.com/source/IOKitUser/IOKitUser-1050.1.21/),看看你是否能找到它們被聲明和定義的地方。 – Droppy

回答

-1

試試這個:

將Build Active Architecture設置爲NO。

+0

這樣做會構建*更多* CPU體系結構,而不是*更少*從而增加鏈接錯誤的可能性,而不會降低它們。這是一個膝蓋混亂的樣板答案,並沒有理解它的作用。 – Droppy