开发者

xcode iphone program using .cpp file: symbol not found

This had been driving me crazy....

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

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/iP开发者_JAVA百科honeOS.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

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

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

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?


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

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.


Doesn't the Apple code come with an include file too? Usually, example code made from Apple always has an include file.
If there is that file, you need to use it too, I think.


Have you tried changing the .cpp file to a .mm file? I vaguely remember something like that's what the compiler expects when there's a mix of objective-c and c++.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜