我正在尝试从基本的 Objective-C++ 文件中使用 Cocoa Framework(具体来说是 MultitouchSupport),但我不断收到 undefined symbol 错误,就好像 g++ 应该具有与 gcc 不同的链接器标志。
我的最终目标是将 C++ 网络库与我从此处获得的一些基本 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"
block ?是这样的吗?
#ifdef __cplusplus
extern "C" {
#endif
// function declarations here
#ifdef __cplusplus
}
#endif
如果没有:您可以将一个添加到头文件中,或者在该头文件的 #import
周围添加一个类似的包装器。
关于c++ - 从 C++ 和 Objective-C++ 链接 Cocoa Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10039360/