![](/img/trans.png)
[英]c++ header file not found when compiling ios project in xcode
[英]Xcode iOS Project Fails When I Add C++ Code
我有一个OpenGL Xcode项目,但是当我想添加.h
和.cpp
文件时,即使我告诉不要编译那些文件,它也不会编译。
我收到此错误:
Apple Mach-O linker error
Undefined symbols for architecture i386:
"_read_png_image", referenced from:
read_png_texture(char const*, bool) in TextureUtilities.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
该错误的根本原因是read_png_image()
是C函数,但已使用C ++链接进行编译-这会导致符号名称混乱,其中包含有关函数参数类型的信息。
解决的方法是用extern "C"
包装函数的声明:
extern "C"
{
void read_png_image(char const*, bool);
}
大概您添加的.cpp
文件包含了声明-可能形成一个预编译的标头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.