重複の可能性:
Mac OS X Lion の FreeGLUT
最初のクイズ: 私の Mac のどこにも gl.h ファイルが見つからないのはなぜですか?! この質問に簡単に答えることができる場合、残りを読む必要さえないかもしれませんが、有名な「OSに統合されている」またはそんな感じ。
私の問題 詳細:
OpenGL を使用した .c ファイルのコンパイルで問題が発生しています。解決策が見つからないまま、何時間も Web を閲覧しました。ここに問題があります:
このソフトウェアを知っている人のために、私は Webots (ロボット シミュレーション ソフトウェア) を使用しており、物理プラグインを実装したいと考えています。試してみるために、既存の(そして機能している)プラグインからコードをコピーしました。gcc を使用する webbots でコンパイルしています (Xcode にはもう付属していないため、gcc コンパイラをインストールする必要がありました)。
問題は、.c ファイルに OpenGL/gl.h ファイルを含む「physics.h」ヘッダーが含まれていることです。「OpenGL/gl.h . no such file or directoy」というエラーが表示されます。
今、私は多くのことを試みました:
gl.h の検索を行う: 存在しないようです (手動またはファインダー検索機能を使用しても見つかりません)
インクルード OpenGL/gl.h を GLUT/glut.h に置き換える: glut.h に含まれているため、「gl.h and glu.h no such fil or directory」というエラーが表示されます。
メイクファイルとフレームワークで gl ライブラリをリンクする
おそらく、絶対パスまたは相対パスを使用したこれらのすべての組み合わせです。
OpenGL と GLUT は OS にネイティブにインストールされるはずなので (私は Lion 10.7.5 を使用しています)、必要なファイルはすべてそこにあるはずです。このため、このおそらく欠落しているファイルをダウンロードする方法が見つかりません...
さらに、私の同僚が試してみて、Linuxでコンパイルすることに成功しました! Linux は素晴らしいプラットフォームですが、私は今でも Mac を愛用しています。
私の問題はMakefileまたはphysic.hファイルにあると思うので、ここにあります:
Physic.h
:
#ifndef PHYSICS_H
#define PHYSICS_H
#include <ode/ode.h>
#ifdef WIN32
#include <windows.h>
#endif
#ifndef MACOS
#include <GL/gl.h>
#else
#include <OpenGL/gl.h>
#endif
/* callback functions to be implemented in your physics plugin */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
DLLEXPORT void webots_physics_init(dWorldID,dSpaceID,dJointGroupID);
DLLEXPORT int webots_physics_collide(dGeomID,dGeomID);
DLLEXPORT void webots_physics_step();
DLLEXPORT void webots_physics_step_end();
DLLEXPORT void webots_physics_cleanup();
DLLEXPORT void webots_physics_draw();
DLLEXPORT void webots_physics_predraw();
/* utility functions to be used in your callback functions */
#ifndef LINUX
extern dGeomID (*dWebotsGetGeomFromDEFProc)(const char *);
extern dBodyID (*dWebotsGetBodyFromDEFProc)(const char *);
extern void (*dWebotsSendProc)(int,const void *,int);
extern void* (*dWebotsReceiveProc)(int *);
extern void (*dWebotsConsolePrintfProc)(const char *, ...);
extern double (*dWebotsGetTimeProc)();
#define dWebotsGetGeomFromDEF(DEFName) (*dWebotsGetGeomFromDEFProc)(DEFName)
#define dWebotsGetBodyFromDEF(DEFName) (*dWebotsGetBodyFromDEFProc)(DEFName)
#define dWebotsSend(channel,buff,size) (*dWebotsSendProc)(channel,buff,size)
#define dWebotsReceive(size_ptr) (*dWebotsReceiveProc)(size_ptr)
#if defined(__VISUALC__) || defined (_MSC_VER) || defined(__BORLANDC__)
#define dWebotsConsolePrintf(format, ...) (*dWebotsConsolePrintfProc)(format, __VA_ARGS__)
#else
#define dWebotsConsolePrintf(format, ...) (*dWebotsConsolePrintfProc)(format, ## __VA_ARGS__)
#endif
#define dWebotsGetTime() (*dWebotsGetTimeProc)()
#else
dGeomID dWebotsGetGeomFromDEF(const char *DEFName);
dBodyID dWebotsGetBodyFromDEF(const char *DEFName);
void dWebotsSend(int channel,const void *buffer,int size);
void *dWebotsReceive(int *size);
void dWebotsConsolePrintf(const char *format, ...);
double dWebotsGetTime();
#endif
#ifdef __cplusplus
}
#endif
#endif /* PHYSICS_H */
メイクファイル:
###
### Standard Makefile for Webots physics plugins
###
### Supported platforms: Windows, Mac OS X, Linux
### Supported languages: C, C++
###
### Authors: Olivier Michel - www.cyberbotics.com
### Revised: Yvan Bourquin - September 30th, 2009.
###
### Uncomment the variables to customize the Makefile
### -----C Sources-----
###
### if your plugin uses several C source files:
C_SOURCES = my_contact_p_physics.c
### -----C++ Sources-----
###
### if your plugin uses several C++ source files:
# CPP_SOURCES = my_plugin.cpp my_clever_algo.cpp my_graphics.cpp
### or
# CC_SOURCES = my_plugin.cc my_clever_algo.cc my_graphics.cc
FRAMEWORK = -framework OpenGL -framework GLUT
### -----Options-----
###
### if special CFLAGS are necessary, for example to set optimization level or
### to find include files:
#CFLAGS=-O3 -I/System/Library/Frameworks/OpenGL.framework
###
### if your plugin needs additional libraries:
LIBRARIES=-L/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries -llibGL -llibGLU
### Do not modify: this includes Webots global Makefile.include
space :=
space +=
WEBOTS_HOME_PATH=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME))))
include $(WEBOTS_HOME_PATH)/resources/projects/default/plugins/physics/Makefile.include
PS: "my_contact_p_physics.c" (コンパイルに苦労している .c ファイル) には、ODE/ode.h ファイルと物理パスを絶対パスで含めるだけです。ODE が webbot に「統合」されているため、端末で直接コンパイルできません。これは、webbot で直接コンパイルする理由です。