首页 > 解决方案 > 在 C++ 上使用 Cocoa 创建一个简单的 OpenGL 应用程序

问题描述

我正在学习https://riptutorial.com/opengl/example/13875/creating-opengl-4-1-with-cplusplus-and-cocoa上的教程,但该项目无法构建。我可能猜想 XCode 混合了我的 Cpp 和 Obj-C 文件。在 Application.hpp 中,它建议用 Obj-C“类”替换“类”并添加分号,而在 MacApp.h 中它找不到要包含的内存。

我已经为此苦苦挣扎了一段时间,但找不到解决方案。

应用程序.hpp

#include <OpenGL/gl3.h>

class Application { // Suggests "Class" and a semicolon
private:
    GLuint          program;
    GLuint          vao;
public:
    Application();
    void update();
    ~Application();

};

MacApp.h

#import <Cocoa/Cocoa.h>
#import "Application.hpp"
#import <memory> // Error here

NSApplication* application;

@interface MacApp : NSWindow <NSApplicationDelegate>{
    std::shared_ptr<Application> appInstance;
}
@property (nonatomic, retain) NSOpenGLView* glView;
-(void) drawLoop:(NSTimer*) timer;
@end

UPD:将 Cpp 标准库从 libstdc++ 更改为 libc++(LLVM...) 并将应用程序指针移动到 main.m 文件中解决了问题

标签: c++objective-ccocoaopengl

解决方案


推荐阅读