开发者

How to config xCode 4 to compile objective-c++ without adding a '.mm' file

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.

Project MyCppLib

- some legacy c++ code

- Adapter.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.

Project Main

- Some objective-c classes which DO NOT contain '.mm' file

- Adapter.h

- libMyCppLib.a as a static library

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

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)

... some other similar errors

ld: symbol(s) not found for architecture armv6

collect2: ld returned 1 exit status

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:

Project Main

- Some objectiv开发者_StackOverflow中文版e-c classes which DO NOT contain '.mm' file

- Adapter.h

- libMyCppLib.a as a static library

- 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?


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).

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:

How to config xCode 4 to compile objective-c++ without adding a '.mm' file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜