I have an OpenGL Xcode project, but when I want to add a .h
and a .cpp
file, it doesn't compile, even if I tell not to compile those files.
I get this error:
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)
The underlying cause of the error is that read_png_image()
is a C function, but has been compiled with C++ linkage - which results in a 'mangled' symbol name that includes information about the types of the function's arguments.
The solution is to wrap the declaration of the function with extern "C"
:
extern "C"
{
void read_png_image(char const*, bool);
}
Presumably the .cpp
file you added includes the declaration - possibly form a pre-compiled header.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.