使用.cpp文件的Xcode iPhone程序:找不到符号 [英] xcode iphone program using .cpp file: symbol not found

查看:150
本文介绍了使用.cpp文件的Xcode iPhone程序:找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我发疯了......

This had been driving me crazy....

我有一个使用Apple示例cpp文件的iPhone应用程序. cpp文件是aqofflinerender.cpp.

I have an iPhone app that is using an Apple sample cpp file. The cpp file is aqofflinerender.cpp.

当我编译Apple示例项目AQOfflineRenderTest时,它将正确编译.当我将aqofflinerender.cpp文件复制到我的项目中并完全像Apple示例一样引用该文件中的方法时,出现以下错误:

When I compile the Apple sample project, AQOfflineRenderTest, it compiles correctly. When I copy the aqofflinerender.cpp file to my project and reference a method within the file exactly as the Apple sample, I get the following error:

    cd /Users/mike/Documents/xcode/insultthem
    setenv IPHONEOS_DEPLOYMENT_TARGET 3.0
    setenv MACOSX_DEPLOYMENT_TARGET 10.5
    setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk "-L/Users/mike/XCode Projects/Debug-iphoneos" "-F/Users/mike/XCode Projects/Debug-iphoneos" -filelist "/Users/mike/XCode Projects/insultthem.build/Debug-iphoneos/insultthem.build/Objects-normal/armv6/insultthem.LinkFileList" -mmacosx-version-min=10.5 -Wl,-dead_strip -miphoneos-version-min=3.0 -framework Foundation -framework UIKit -framework CoreGraphics -framework AVFoundation -framework SystemConfiguration -framework AudioToolbox -framework CoreData -framework MessageUI -framework IOKit -o "/Users/mike/XCode Projects/Debug-iphoneos/insultthem.app/insultthem"
Undefined symbols:
  "_DoAQOfflineRender", referenced from:
      -[AudioFileManipulation combineFiles:newFileName:] in AudioFileManipulation.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

.m文件中的方法定义如下:

In .m file, the method is defined as follows:

extern void DoAQOfflineRender(CFURLRef sourceURL1, CFURLRef sourceURL2, CFURLRef sourceURL3, CFURLRef destinationURL);

在.cpp文件中,方法如下:

In the .cpp file, the method is as follows:

void DoAQOfflineRender(CFURLRef sourceURL1, CFURLRef sourceURL2, CFURLRef sourceURL3, CFURLRef destinationURL) {

有人对解决这个问题有什么建议吗?

Does anyone have any suggestions for resolving this?

推荐答案

好...根据另一篇文章,在aqofflinerender.cpp文件中,我将函数包围如下:

Ok... Figured it out.... according to another post, in the aqofflinerender.cpp file, I surrounded the function as follows:

#if __cplusplus
extern "C" {
#endif

void DoAQOfflineRender(CFURLRef sourceURL, CFURLRef destinationURL) 
{
...
}


#if __cplusplus
}
#endif

很奇怪...因为它在Apple示例中没有#if __cplusplus行.猜测我的项目中缺少编译器选项...

Weird.... cause it works in the Apple example without the #if __cplusplus lines. Guessing that there is a compiler option missing in my project...

这些行告诉编译器将函数名称导出为符号,以便其他类可以查看"函数.

These lines tell the compiler to export the function name as the symbol so the other classes can "see" the function.

这篇关于使用.cpp文件的Xcode iPhone程序:找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆