簡體   English   中英

從 C++ 和 Objective-C++ 鏈接到 Cocoa Framework

[英]Link with Cocoa Framework from C++ and Objective-C++

我正在嘗試從基本的 Objective-C++ 文件中使用 Cocoa 框架(具體來說是 MultitouchSupport),但我不斷收到未定義的符號錯誤,就好像 g++ 應該具有與 gcc 不同的 linker 標志。

我的最終目標是將 C++.networking 庫與我從此處獲得的一些基本 Objective-C 代碼集成: http://steike.com/code/multitouch/

當我運行它來編譯原始代碼時,它工作正常:

gcc -F/System/Library/PrivateFrameworks -framework MultitouchSupport test.m -o test -std=c99

但是當我將文件重命名為test.mm以便以后可以包含和引用 C++ 文件時,以下內容不起作用:

g++ -F/System/Library/PrivateFrameworks -framework MultitouchSupport test.mm -o test

並給我這些錯誤:

Undefined symbols for architecture x86_64:
"MTDeviceCreateDefault()", referenced from:
    _main in ccq0vzuM.o
"MTRegisterContactFrameCallback(void*, int (*)(int, Finger*, int, double, int))", referenced from:
    _main in ccq0vzuM.o
"MTDeviceStart(void*, int)", referenced from:
    _main in ccq0vzuM.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [testpp] Error 1

我需要做什么才能讓這個 Objective-C++ 文件看到我正在尋找的框架,以便我可以使用 C++?

謝謝!

在聲明這三個函數的 header 中,是否有一個extern "C"塊來包裝它們? 是這樣的嗎?

#ifdef __cplusplus
extern "C" {
#endif

// function declarations here

#ifdef __cplusplus
}
#endif

如果不是:您可以將一個添加到 header 文件,或者在您的#import of that header 文件周圍添加一個類似的包裝器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM