Objective C

时间:2015-07-17 05:49:22

标签: c++ objective-c macos linker objective-c++

我正在尝试为用C ++编写的OS X应用程序创建一个窗口(目前使用的是Xcode 6.4)。在阅读StackOverflow和其他地方关于Objective-C ++,PIMPL以及为Objective-C类和对象创建适当的C ++接口/包装之后,我想出了以下内容:

main.cpp中:

#include "WindowController.h"

int main(int argc, const char * argv[]) {
    WindowController *windowController = new WindowController();
    return 0;
}

WindowController.h:

#ifndef _WindowController_h
#define _WindowController_h

class WindowController
{
public:
    WindowController();
    ~WindowController();

    void init();
    void createWindow(int width, int height);
    void destroyWindow();

};

#endif

WindowController-objc.h:

#ifndef _WindowController_objc_h
#define _WindowController_objc_h

@interface WindowControllerObjC : NSObject

- (void) WindowController::createWindowWithWidth: (int) width
AndHeight: (int) height;

@end

#endif

WindowController.mm:

#import "WindowController.h"
#import "WindowController-objc.h"

@implementation WindowControllerObjC

AppView view;

WindowController::WindowController() {}

WindowController::~WindowController() {
    [(id)self dealloc];
}

void WindowController::init(void) {
    self = [[RTRTWindowController alloc] init];
}

void WindowController::createWindow(int width, int height) {
    (id)self createWindowWithWidth: width AndHeight: height];
}

void WindowController::destroyWindow(void) {
    // remove window
}

- (void) createWindowWithWidth: (int) width AndHeight: (int) height {
    // create window and initialize view
}

我的原帖是关于解决此链接器错误:

Undefined symbols for architecture x86_64:
  "WindowController::WindowController()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
发布后5分钟,我发现我从目标中的“Compile Sources”中遗漏了WindowController.mm,因此编译器甚至从未查看过WindowController.mm。这就是链接器抱怨无法找到构造函数(叹息)的原因。

然而,为了后代,我想留下这篇文章(和链接器错误)并将这篇文章扩展到围绕Objective-C对象制作C ++包装器的主题。据我所知,逆变得引起了很多关注,但这个特殊问题并没有得到很好的处理。

我可以从现在开始解决我自己上面所有可爱的错误,但是为了在其他人的StackOverflow上有这个,如果有人比我对这个主题了解得多,那么就想用这个例子来表示彻底的主题演练(或纠正我的错误),这太棒了!

0 个答案:

没有答案
相关问题