简体   繁体   English

C ++导入的库未正确编译

[英]C++ imported library not compiled correctly

I've included the headers of a static library (taglib.a to parse music files on the file system) in my Xcode project). 我在我的Xcode项目中包含了静态库的头(用于解析文件系统上音乐文件的taglib.a)。

The library is written in C++. 该库是用C ++编写的。 It seems the compiler in Xcode believes it's an objective-C library instead. 似乎Xcode中的编译器认为它是一个Objective-C库。

I get this compile error in the included header: taglib.h 我在包含的标头中得到了此编译错误:taglib.h

Unknown type name 'namespace'

Usually for this kind of problem the solution is change the extension of the file to .mm to inform the compiler is not only objective-C, but in this case it's an header. 通常针对这种问题,解决方案是将文件扩展名更改为.mm,以通知编译器不仅是Objective-C,而且在这种情况下是标头。 And it's the header of an imported library, not even in my project tree. 它是导入库的头,甚至不在我的项目树中。

How to solve this? 如何解决呢?

在此处输入图片说明

File using the library (#import "taglib/taglib.h") 使用库文件(#import“ taglib / taglib.h”)

在此处输入图片说明

Set it as C++ header. 将其设置为C ++标头。 It will be fine. 没事的。

在此处输入图片说明

在出现错误的地方,必须使用c ++编译器编译包含有问题的.h文件,因此,如果您具有main.m,则需要将其更改为main.mm-如果您具有foo.c,则需要将其更改为foo.cpp-这不是免费的,因为现在您住在该编译单元的c ++领域中。因此另一种方法是制作一个处理c ++库的ObjC ++类。纯C编译单元。

通过重新启动xCode已解决了该问题。

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

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