私は単純な C++、opengl プログラムを書いていますが、オブジェクト ファイルから実行可能ファイルを作成するのに苦労しています。以下を使用して、エラーなしで各 .cpp のオブジェクト ファイルを作成できます。
g++ -c filename.cpp ----> filename.o
各 .cpp はオブジェクトを作成するため、opengl ヘッダーが正常に検出されていると思われますが、オブジェクトから実行可能ファイルを作成しようとすると、次のように出力されます。
g++ -o OUTPUT Main.o Time.o Map.o Vehicle.o
Main.o: In function `init()':
Main.cpp:(.text+0x12a): undefined reference to `glEnable'
Main.cpp:(.text+0x134): undefined reference to `glShadeModel'
Main.cpp:(.text+0x14d): undefined reference to `glViewport'
Main.cpp:(.text+0x157): undefined reference to `glMatrixMode'
Main.cpp:(.text+0x15c): undefined reference to `glLoadIdentity'
g++ が、OpenGL 関数がどこにも見つからない、つまり、glu.h、gl.h などにリンクしていないことを通知していることに気付きました。しかし、オブジェクト ファイルが同様のエラーなしで作成されるのはなぜですか。私の実行可能ファイルを作成しませんか?オブジェクト ファイルは、.exe と同じリンク エラーに悩まされませんか? -I と g++ -o RUN Time.o Main.o Map.o Vehicle.o -L/usr/include/GL/ -lGL -lGLU を試し、OpenGL ディレクトリのパスも確認しました。
各ファイルのヘッダーは次のとおりです。
libgl.h:
#ifndef LIBGL_H
#define LIBGL_H
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "Time.h"
#include "Link.h"
#endif
時間.h:
#ifndef TIME_H
#define TIME_H
extern float GLOBAL_TIME;
#endif
Map.h
#ifndef MAP_H
#define MAP_H
#include "libgl.h"
....
#endif
Vehicle.h:
#ifndef VEHICLE_H
#define VEHICLE_H
#include "libgl.h"
...
#endif
Main.cpp:
#include "libgl.h"
#include "Map.h"
#include "Vehicle.h"
...
ヘッダー/リンクとコンパイルに関して欠けているものがあります。誰か提案があれば、ぜひお寄せください。