2

I am trying to write a console based application to access a Canon camera on Mac OS X 10.7.5. I am using XCode version 4.6 for the same. This is the program I am trying to write

#import <Foundation/Foundation.h>
#include "EDSDK.h"
#include "EDSDKErrors.h"
#include "EDSDKTypes.h"


int main()
{
    @autoreleasepool {
        EdsError error = EDS_ERR_OK;
        EdsCameraListRef cameraList = NULL;
        EdsUInt32 count = 0;
        EdsDeviceInfo deviceInfo;
        bool isSDKLoaded;

        // Initialization of SDK
        error = EdsInitializeSDK();

        //Acquisition of camera list
        if(error == EDS_ERR_OK)
        {
            isSDKLoaded = YES;
            error = EdsGetCameraList(&cameraList);
        }
        if(cameraList != NULL) {
            EdsRelease(cameraList);
            cameraList = NULL;
        }

    }
    return 0;
}

It compiles successfully but when I run the program it crashes when the EdsGetCameraList function returns. The error shown is 'dyld misaligned_stack_error'. I understand that this has something to do with the fact that MacOS X wants the stack to be 16-byte aligned. The SDK I am using is only available for 32 bit architectures and hence, I have set the architecture accordingly. I tried setting the "Other C flags" under Build Settings in XCode to include the flag "-falign-stack=assume-16-byte" as well.

The sample that came along with the Canon EDSDK works fine. The version of the SDK being used is the one developed by Canon in 2006-2007 updated on 06-03-16. I have no other version information on it.

Following is the dump from the logs : http://pastebin.com/vfDWeZnr

What could I be possibly doing wrong?

I am really new to Objective-C and hence, the mix up of C and Objective-C code.

Thanks!

Jatin
  • 31,116
  • 15
  • 98
  • 163
niting
  • 2,384
  • 3
  • 19
  • 20

1 Answers1

0

Are you sure that you don't need to initialize cameraList? I imagine that the function wants to write to the address you supply but that points to NULL, hence the error. In C I'd use malloc() here to obtain a pointer but I don't know the equivalent for objective-C.

Max Leske
  • 5,007
  • 6
  • 42
  • 54
  • The EdsGetCameraList function does that for me. All the sample codes all over the internet, use the same form of initialization. They initialize it to NULL and call the function. Correct me if you feel that I am still wrong. – niting Apr 10 '13 at 08:03
  • Where did you find that code? On line 124 of your log there's this: `dlopen(NULL, 0x00000110)`. This means you're trying to open a dynamic library at path `NULL` which is obviously nonsense. So I wonder how that could have worked for the person who wrote the documentation. – Max Leske Apr 10 '13 at 12:52
  • Strangely, I stopped using Xcode with LLVM and moved to Vim with g++ and it compiled and ran just fine. I have no clue why that happened, possibly because of compilation flags or something of that sort. – niting Apr 15 '13 at 05:32