Baffled by a compiler error!!!

Discussion in 'iOS Programming' started by jerrywickey, May 11, 2009.

  1. jerrywickey macrumors member

    Joined:
    Apr 16, 2009
    Location:
    Key West
    #1
    dejo helped me find the syntax for system sound.

    His code worked perfectly, as did the code when I modified it to make my test code before inserting it in the project I am working on.

    dejo's code worked perfectly. My modifications of dejo's code worked perfectly. However, when I inserted the perfectly working modificed code in my project it did not work.

    Below you will find the same code. The first works the second fails to compile.

    I first suspected something conflicted with it. I looked for three days and tested everything from file names to the project bundle. I can find nothing. Finally I attempted a fresh test code. After trying my modified code fresh and the started a new project using dejo's original code again, it didn't work either. It gave me the same error as the project in which I was inserting the working code.

    The first test project I made with dejo's code still works. Additional test projects I made with the same code from dejo don't work and give me the same compiler errors. Obviously, for the same code to work once and not to work the next time, I am missing some compiler option or setting which I happened to get right the first time and never again.

    The working code follows then the code which does not work. (yes. they are the same code, but the first ones works and the second does not.

    Hopefully someone will see the problem right away and be able to pin it down. I am stumped.


    This code compiles and plays the GuitarScale properly.
    Code:
    // file SysSoundViewController.h
    
    #import <UIKit/UIKit.h>
    #import <AudioToolbox/AudioToolbox.h>
    
    @interface SysSoundViewController : UIViewController {
    	SystemSoundID	theSoundFile;
    }
    
    @property (readwrite)	SystemSoundID	theSoundFile;
    
    @end
    
    
    // file SysSoundViewController.m
    
    #import "SysSoundViewController.h"
    
    @implementation SysSoundViewController
    
    @synthesize theSoundFile;
    
    - (void) viewDidLoad {
    	AudioServicesCreateSystemSoundID( CFBundleCopyResourceURL( CFBundleGetMainBundle(), CFSTR( "GuitarScale"), CFSTR( "wav"), NULL), &theSoundFile);
    	AudioServicesPlaySystemSound(self.theSoundFile);
    	[super viewDidLoad];
    }
    
    - (void) dealloc {
    	[super dealloc];
    }
    
    @end
    

    This code, however, does not compile and gives the error below:
    Code:
    // file SecTestViewController.h
    
    #import <UIKit/UIKit.h>
    #import <AudioToolbox/AudioToolbox.h>
    
    @interface SecTestViewController : UIViewController {
    	SystemSoundID	theSoundFile;
    
    }
    
    @property (readwrite)	SystemSoundID	theSoundFile;
    
    @end
    
    
    // file SecTestViewController.m
    #import "SecTestViewController.h"
    
    @implementation SecTestViewController
    
    @synthesize theSoundFile;
    
    - (void)viewDidLoad {
    	AudioServicesCreateSystemSoundID( CFBundleCopyResourceURL( CFBundleGetMainBundle(), CFSTR( "GuitarScale"), CFSTR( "wav"), NULL), &theSoundFile);
    	AudioServicesPlaySystemSound(self.theSoundFile);
        [super viewDidLoad];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
        // Release anything that's not essential, such as cached data
    }
    
    - (void)dealloc {
        [super dealloc];
    }
    
    @end
    
    This second code gives me this compiler error quoted verbatum:

    collect2: Id returned 1 exit status
    symbol(s) not found
    -[SecTestViewController viewDidLoad] in SecTestViewController.o
    "*AudioServicesCreateSystemSoundID", referenced from:
    -[SecTestViewController viewDidLoad] in SecTestViewController.o
    "*AudioServicesPlaySystemSound", referenced from:

    end quote:
     
  2. jpyc7 macrumors 6502

    Joined:
    Mar 8, 2009
    Location:
    Denver, CO
    #2
    linking error

    Technically, you seem to have a linking error, not a compiling error. I don't use Xcode so I don't know how you specify the libraries that you are linking to. Anyway, I suggest googling about linking with Xcode and that might tell you what you need to tweak.

    Looking at your error message, I think it is saying that there is a symbol you used in your program, *AudioServicesCreateSystemSoundID, which is not in the libraries you are linking to. So you need to specify the correct extra library.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
  4. jerrywickey thread starter macrumors member

    Joined:
    Apr 16, 2009
    Location:
    Key West
    #4
    I checked this forum today at 3:21 and thanks to your advice, at 3:26 had it workin'

    You guys are great. Thanks.

    So the line #import <AudioToolbox/AudioToolbox.h> in the header isn't enough to actually import the AudioToolbox files huh?

    Well ok. So long as I know that.

    Thanks again.

    Jerry
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    No, it doesn't import the files. Just the header file. But you still need to make sure you have the framework files linked in to your project. Linking and importing are somewhat different.
     

Share This Page