2

我正在尝试在基本的 Objective-C++ 文件中使用 Cocoa 框架(具体来说是 MultitouchSupport),但我不断收到未定义的符号错误,好像 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++?

谢谢!

4

1 回答 1

1

在声明这三个函数的头文件中,是否有一个extern "C"包装它们的块?像这样的东西?

#ifdef __cplusplus
extern "C" {
#endif

// function declarations here

#ifdef __cplusplus
}
#endif

如果不是:您可以在头文件中添加一个,或者在该#import头文件周围添加一个类似的包装器。

于 2012-04-06T05:14:24.980 回答