简体   繁体   English

从 C++ 和 Objective-C++ 链接到 Cocoa Framework

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

I'm trying to use a Cocoa Framework (MultitouchSupport, to be specific) from within a basic Objective-C++ file, but I keep getting undefined symbol errors, as if g++ is supposed to have different linker flags than gcc.我正在尝试从基本的 Objective-C++ 文件中使用 Cocoa 框架(具体来说是 MultitouchSupport),但我不断收到未定义的符号错误,就好像 g++ 应该具有与 gcc 不同的 linker 标志。

My ultimate goal is to integrate a C++.networking library with some basic Objective-C code I got from here: http://steike.com/code/multitouch/ .我的最终目标是将 C++.networking 库与我从此处获得的一些基本 Objective-C 代码集成: http://steike.com/code/multitouch/

When I run this to compile the original code, it works fine:当我运行它来编译原始代码时,它工作正常:

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

But when I rename the file to test.mm , so that it can later include and reference C++ files, the following doesn't work:但是当我将文件重命名为test.mm以便以后可以包含和引用 C++ 文件时,以下内容不起作用:

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

And gives me these errors:并给我这些错误:

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

What do I need to do in order for this Objective-C++ file to see the Framework I'm looking for so I can use C++ with it?我需要做什么才能让这个 Objective-C++ 文件看到我正在寻找的框架,以便我可以使用 C++?

Thanks!谢谢!

In the header that declares those three functions, is there an extern "C" block that wraps them?在声明这三个函数的 header 中,是否有一个extern "C"块来包装它们? Something like this?是这样的吗?

#ifdef __cplusplus
extern "C" {
#endif

// function declarations here

#ifdef __cplusplus
}
#endif

If not: You could add one to the header file, or add a similar wrapper around your #import of that header file.如果不是:您可以将一个添加到 header 文件,或者在您的#import of that header 文件周围添加一个类似的包装器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM