私はかなり長い間 glut で OpenGL を使用してきましたが、この問題に遭遇したことはありません。
glutMouseFunc などのライブラリ関数を使用するために、c++/cli プロジェクトに glut ライブラリを含めようとしています。私のプロジェクトは既に gl.h と glu.h を使用しています。しかし、私が含める瞬間:
#include <gl/glut.h>
次の一連のエラー メッセージが表示されます。
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl/glut.h(490): error C3641: 'glutInit_ATEXIT_HACK' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl/glut.h(490): error C2664: '__glutInitWithExit' : cannot convert parameter 3 from 'void (__cdecl *)(int)' to 'void (__cdecl *)(int)'
1> Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl/glut.h(507): error C3641: 'glutCreateWindow_ATEXIT_HACK' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl/glut.h(507): error C2664: '__glutCreateWindowWithExit' : cannot convert parameter 2 from 'void (__cdecl *)(int)' to 'void (__cdecl *)(int)'
1> Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl/glut.h(553): error C3641: 'glutCreateMenu_ATEXIT_HACK' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\gl/glut.h(553): error C2664: '__glutCreateMenuWithExit' : cannot convert parameter 2 from 'void (__cdecl *)(int)' to 'void (__cdecl *)(int)'
1> Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type
プロジェクトのプロパティ(プロパティ>構成プロパティ>一般>共通言語ランタイムサポート)のclrサポートをclr:safeまたはclr:pure以外のものに切り替えることで、同様の問題が解決されたことを他のいくつかの場所で読みました。
実際、clrサポートの利用可能な4つのバージョンすべてでコンパイルを試みました:
共通言語ランタイム サポート (/clr)
純粋な MSIL 共通言語ランタイム サポート (/clr:pure)
安全な MSIL 共通言語ランタイム サポート (/clr:safe)
共通言語ランタイムのサポート、古い構文 (/clr:oldSyntax)
ただし、同じエラー メッセージが表示されます。この問題がどこから来るのかわかりません。私は他のプロジェクト (c++ のみ) で glut を使用しましたが、c++/cli を使い始めるまでこの問題に遭遇したことはありません。
これが何であるかについての洞察は大歓迎です。
前もって感謝します、
男
(ちなみに、関連性があれば Visual Studio 2010 を使用しています。)