如何配置xCode 4来编译objective-c++而不添加a。毫米的文件

时间:2022-09-07 08:43:23

I am trying to describe my problem clearly for you, so it might be a little long, and I really appreciate that if you can read it and provide some suggestion. Thanks.

我正在努力为您清晰地描述我的问题,所以可能会有点长,如果您能阅读并提供一些建议,我将不胜感激。谢谢。

I have a library project, let's call it MyCppLib, which contains some legacy c++ code, and I add a adapter class in this project so that I can use it with out using objective-c++ in other project. Here is an overview of MyCppLib project.

我有一个库项目,我们称它为MyCppLib,它包含一些遗留的c++代码,我在这个项目中添加了一个适配器类,以便在其他项目中使用objective-c++ +时使用它。这里是MyCppLib项目的概述。

Project MyCppLib
- some legacy c++ code
- Adapter.h
- Adapter.mm

项目MyCppLib -一些遗留的c++代码适配器。h - Adapter.mm

I have another project, let's call it Main project, which use the MyCppLib project as a static library. So I use xCode 4 to compile MyCppLib, and get libMyCppLib.a, and config Main project in xCode 4 to link it with Main project. Here is an overview of Main project.

我有另一个项目,我们称之为主项目,它使用MyCppLib项目作为静态库。因此,我使用xCode 4编译MyCppLib,并获得libMyCppLib。在xCode 4中配置主项目,将其与主项目链接。这里是主要项目的概述。

Project Main
- Some objective-c classes which DO NOT contain '.mm' file
- Adapter.h
- libMyCppLib.a as a static library

Project Main——一些不包含'的objective-c类。毫米的文件——适配器。h - libMyCppLib。a作为静态库。

While I compile the Main project in xCode 4 I get some errors:

当我在xCode 4中编译主项目时,我得到了一些错误:

Undefined symbols for architecture armv6:
"operator new(unsigned long)", referenced from:
-[Adapter init] in libMyCppLib.a(Adapter.o)
my::cpp::namespace::MyCppClass::MyCppClass()in libMyCppLib.a(MyCppClass.o)

架构armv6的未定义符号:“新操作符(无符号长)”,引用自libMyCppLib.a(Adapter.o)中的:::cpp:::命名空间::MyCppClass::MyCppClass()

... some other similar errors

…一些其他类似的错误

ld: symbol(s) not found for architecture armv6
collect2: ld returned 1 exit status

没有为架构armv6 collect2找到的符号:ld返回1退出状态

I figure it might because the Main project do not have an objective-c++ capability, so I add a '.mm' file to the Main project. And now Main project should be like this:

我认为这可能是因为主项目没有objective-c++功能,所以我添加了一个'。文件到主项目。现在主要项目应该是这样的:

Project Main
- Some objective-c classes which DO NOT contain '.mm' file
- Adapter.h
- libMyCppLib.a as a static library
- DummyObjCpp.h
- DummyObjCpp.mm

Project Main——一些不包含'的objective-c类。毫米的文件——适配器。h - libMyCppLib。作为一个静态库- DummyObjCpp。h - DummyObjCpp.mm

Then, I compile the Main project, and it succeed!

然后,我编译主项目,它成功了!

So, finally, my question is: how can I configure the Main project to have objective-c++ capability without adding a '.mm' file?

因此,最后,我的问题是:如何在不添加“a”的情况下将主项目配置为具有objective-c++功能。毫米的文件?

1 个解决方案

#1


6  

OK, I've read over the question a few times, but I'm still not sure I understand the problem.

好吧,我已经读过这个问题好几次了,但我仍然不确定我是否理解这个问题。

While I've done a lot with Objective-C, C++, and Objective-C++, I haven't encountered the scenario you've described with static libraries (since most of my development is for OS X rather than iOS, where dynamic libraries are allowed and preferred).

虽然我已经用Objective-C、c++和objective - c++做了很多工作,但我还没有遇到静态库所描述的场景(因为我的大部分开发都是针对OS X而不是iOS的,在iOS中,动态库是允许的,也是首选的)。

It sounds like there might be an issue in your second project because the .h file by itself doesn't tell enough about what's contained in the .a (namely that when you combine it with the rest of your executable, you'll need to be linked against libstdc++.dylib). You might try changing the "File Type" of the Adapter.h header file from the default of C header to C++ header as shown in the image below:

听起来您的第二个项目可能会有问题,因为.h文件本身并不能充分说明.a中包含的内容(也就是说,当您将其与可执行文件的其他部分结合在一起时,您将需要链接到libstdc+ .dylib)。您可以尝试更改适配器的“文件类型”。h标头文件从默认的C标头文件到c++标头文件,如下图所示:

如何配置xCode 4来编译objective-c++而不添加a。毫米的文件

#1


6  

OK, I've read over the question a few times, but I'm still not sure I understand the problem.

好吧,我已经读过这个问题好几次了,但我仍然不确定我是否理解这个问题。

While I've done a lot with Objective-C, C++, and Objective-C++, I haven't encountered the scenario you've described with static libraries (since most of my development is for OS X rather than iOS, where dynamic libraries are allowed and preferred).

虽然我已经用Objective-C、c++和objective - c++做了很多工作,但我还没有遇到静态库所描述的场景(因为我的大部分开发都是针对OS X而不是iOS的,在iOS中,动态库是允许的,也是首选的)。

It sounds like there might be an issue in your second project because the .h file by itself doesn't tell enough about what's contained in the .a (namely that when you combine it with the rest of your executable, you'll need to be linked against libstdc++.dylib). You might try changing the "File Type" of the Adapter.h header file from the default of C header to C++ header as shown in the image below:

听起来您的第二个项目可能会有问题,因为.h文件本身并不能充分说明.a中包含的内容(也就是说,当您将其与可执行文件的其他部分结合在一起时,您将需要链接到libstdc+ .dylib)。您可以尝试更改适配器的“文件类型”。h标头文件从默认的C标头文件到c++标头文件,如下图所示:

如何配置xCode 4来编译objective-c++而不添加a。毫米的文件