2013-09-25 51 views
0

我有以下代碼,並且不斷收到EXC_BAD_ACCESS錯誤。我有這個代碼貼的更復雜的副本,但我煮的問題下面的代碼:命令行實用程序中安裝網絡共享的分段錯誤

#import <Foundation/Foundation.h> 
#include <NetFS/NetFS.h> 

int main(int argc, const char * argv[]){ 
    @autoreleasepool { 

     NSURL * share = [NSURL URLWithString: @"smb://192.168.0.100/lib"]; 
     NSURL * path = [NSURL URLWithString: @"/Users/bogdan/Network/Library/"]; 
     CFURLRef share2 = (__bridge CFURLRef) share; 
     CFURLRef path2 = (__bridge CFURLRef) path; 

     NetFSMountURLSync(share2, path2, NULL, NULL, NULL, NULL, NULL); 
    } 
    return 0; 
} 

的問題是與「NetFSMountURLSync」行,但我想不出是什麼問題。我認爲我正在使用它,我刪除了所有我可以選擇的選項。運行後,共享被掛載,但之後,我得到了錯誤。

+0

您是否可以複製粘貼CLI輸入和輸出?你如何運行可執行文件? –

+0

您是否嘗試過從GDB或LLDB手動運行可執行文件,而無需Xcode? – Macmade

+0

輸入:./mysmbmount smb://192.168.0.101/lib/Users/bogdan/Network/lib/Bunzilla2 輸出:分段錯誤:11 – Bogdan

回答

0

明白了!顯然,即使我不關心返回的掛載點,我仍然必須將一個變量傳遞給該函數,以便它可以將其存儲在那裏。此代碼的工作原理:

int main(int argc, const char * argv[]){ 

@autoreleasepool { 

    NSURL * share = [NSURL URLWithString: @"smb://192.168.0.100/lib"]; 
    NSURL * path = [NSURL URLWithString: @"/Users/bogdan/Network/Library/"]; 
    CFURLRef share2 = (__bridge CFURLRef) share; 
    CFURLRef path2 = (__bridge CFURLRef) path; 
    CFArrayRef mountpoints = NULL; 

    NetFSMountURLSync(share2, path2, NULL, NULL, NULL, NULL, &mountpoints); 
} 
return 0; 
}