質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Cocoa

CocoaはMac OS X用のアプリケーションを構築する為の主要なフレームワークのひとつです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

1995閲覧

macOS C++ cocoaを利用したい

sudo-san

総合スコア5

Cocoa

CocoaはMac OS X用のアプリケーションを構築する為の主要なフレームワークのひとつです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2021/04/15 14:11

編集2021/04/15 15:01

前提・実現したいこと

C++でcocoaを利用したプログラムを作成したい

発生している問題・エラーメッセージ

g++ hello-glfw.cpp -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -Wno-deprecated-declaration
warning: unknown warning option '-Wno-deprecated-declaration'; did you mean
'-Wno-deprecated-declarations'? [-Wunknown-warning-option]
hello-glfw.cpp:7:2: warning: 'glClear' is deprecated: first deprecated in macOS
10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to silence
these warnings) [-Wdeprecated-declarations]
glClear(GL_COLOR_BUFFER_BIT);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2394:13: note:
'glClear' has been explicitly marked deprecated here
extern void glClear (GLbitfield mask) OPENGL_DEPRECATED(10.0, 10.14);
^
hello-glfw.cpp:8:2: warning: 'glClearColor' is deprecated: first deprecated in
macOS 10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to
silence these warnings) [-Wdeprecated-declarations]
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2396:13: note:
'glClearColor' has been explicitly marked deprecated here
extern void glClearColor (GLclampf red, GLclampf green, GLclampf blue, G...
^
hello-glfw.cpp:9:2: warning: 'glColor3f' is deprecated: first deprecated in
macOS 10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to
silence these warnings) [-Wdeprecated-declarations]
glColor3f(0.0f, 0.6f, 0.2f);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2405:13: note:
'glColor3f' has been explicitly marked deprecated here
extern void glColor3f (GLfloat red, GLfloat green, GLfloat blue) OPENGL_...
^
hello-glfw.cpp:10:2: warning: 'glBegin' is deprecated: first deprecated in macOS
10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to silence
these warnings) [-Wdeprecated-declarations]
glBegin(GL_POLYGON);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2385:13: note:
'glBegin' has been explicitly marked deprecated here
extern void glBegin (GLenum mode) OPENGL_DEPRECATED(10.0, 10.14);
^
hello-glfw.cpp:11:2: warning: 'glVertex2f' is deprecated: first deprecated in
macOS 10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to
silence these warnings) [-Wdeprecated-declarations]
glVertex2f(-0.9f, -0.9f);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2732:13: note:
'glVertex2f' has been explicitly marked deprecated here
extern void glVertex2f (GLfloat x, GLfloat y) OPENGL_DEPRECATED(10.0, 10.14);
^
hello-glfw.cpp:12:2: warning: 'glVertex2f' is deprecated: first deprecated in
macOS 10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to
silence these warnings) [-Wdeprecated-declarations]
glVertex2f(0.9f, -0.9f);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2732:13: note:
'glVertex2f' has been explicitly marked deprecated here
extern void glVertex2f (GLfloat x, GLfloat y) OPENGL_DEPRECATED(10.0, 10.14);
^
hello-glfw.cpp:13:2: warning: 'glVertex2f' is deprecated: first deprecated in
macOS 10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to
silence these warnings) [-Wdeprecated-declarations]
glVertex2f(0.9f, 0.9f);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2732:13: note:
'glVertex2f' has been explicitly marked deprecated here
extern void glVertex2f (GLfloat x, GLfloat y) OPENGL_DEPRECATED(10.0, 10.14);
^
hello-glfw.cpp:14:2: warning: 'glVertex2f' is deprecated: first deprecated in
macOS 10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to
silence these warnings) [-Wdeprecated-declarations]
glVertex2f(-0.9f, 0.9f);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2732:13: note:
'glVertex2f' has been explicitly marked deprecated here
extern void glVertex2f (GLfloat x, GLfloat y) OPENGL_DEPRECATED(10.0, 10.14);
^
hello-glfw.cpp:15:2: warning: 'glEnd' is deprecated: first deprecated in macOS
10.14 - OpenGL API deprecated. (Define GL_SILENCE_DEPRECATION to silence
these warnings) [-Wdeprecated-declarations]
glEnd();
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2474:13: note:
'glEnd' has been explicitly marked deprecated here
extern void glEnd (void) OPENGL_DEPRECATED(10.0, 10.14);
^
10 warnings generated.

該当のソースコード

#include <iostream>
#include <GLFW/glfw3.h>
#pragma comment(lib, "GLFW3.lib")
#pragma comment(lib, "opengl32.lib")

void display() {
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glColor3f(0.0f, 0.6f, 0.2f);
glBegin(GL_POLYGON);
glVertex2f(-0.9f, -0.9f);
glVertex2f(0.9f, -0.9f);
glVertex2f(0.9f, 0.9f);
glVertex2f(-0.9f, 0.9f);
glEnd();
}

int main(void)
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(512, 512, "Hello OpenGL", NULL, NULL);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
display();
glfwSwapBuffers(window);
glfwPollEvents();
}

glfwDestroyWindow(window); glfwTerminate(); return 0;

}

試したこと

CocoaなしでのC++でのみでのhello worldなどの出力プログラムは動作確認済み
Cocoaとの相性との検索をしたもののそれらしきことを記述したサイトは見つけられませんでした

補足情報(FW/ツールのバージョンなど)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

-lglfw-framework Cocoa

-lglfw と -framework の間に空白が必要です。

-framework IOKit-framework CoreVideo–Wno-deprecated-declarations

IOKit と -framework の間に空白が必要です。CoreVideo と -Wno-... の間に空白が必要です。

投稿2021/04/15 14:47

int32_t

総合スコア20832

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sudo-san

2021/04/15 15:11 編集

ありがとうございます。こちらで動きました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問