C++에서 opengl을 사용하여 간단한 obj 로더를 만들려고합니다. 하나의 명령으로 모든 것이 잘 작동 컴파일 ,g ++로 객체를 연결할 때 문제가 발생했습니다.
g++ -o main main.cpp timer.cpp screen.cpp obj_loader.cpp `sdl-config --cflags --libs` `pkg-config --cflags --libs glu`
반환 오류없이.
컴파일 오브젝트는 개별적으로
g++ main.cpp -o main.o -c -Wall `sdl-config --cflags --libs` `pkg-config glu --cflags --libs`
g++ obj_loader.cpp -o obj_loader.o -c -Wall `sdl-config --cflags --libs` `pkg-config glu --cflags --libs`
g++ timer.cpp -o timer.o -c -Wall `sdl-config --cflags --libs` `pkg-config glu --cflags --libs`
g++ screen.cpp -o screen.o -c -Wall `sdl-config --cflags --libs` `pkg-config glu --cflags --libs`
는 오류를 반환하지, 잘 너무 작동합니다.
main.o: In function `draw()':
main.cpp:(.text+0x1d): undefined reference to `glColor3f'
main.cpp:(.text+0x27): undefined reference to `glBegin'
main.cpp:(.text+0x36): undefined reference to `glVertex2i'
main.cpp:(.text+0x45): undefined reference to `glVertex2i'
main.cpp:(.text+0x54): undefined reference to `glVertex2i'
main.cpp:(.text+0x63): undefined reference to `glVertex2i'
main.cpp:(.text+0x68): undefined reference to `glEnd'
main.o: In function `main':
main.cpp:(.text+0xf8): undefined reference to `SDL_PollEvent'
main.cpp:(.text+0x10b): undefined reference to `glClear'
main.cpp:(.text+0x115): undefined reference to `SDL_GL_SwapBuffers'
main.cpp:(.text+0x11a): undefined reference to `glFinish'
main.cpp:(.text+0x14e): undefined reference to `SDL_Delay'
timer.o: In function `Timer::start()':
timer.cpp:(.text+0x4d): undefined reference to `SDL_GetTicks'
timer.o: In function `Timer::pause()':
timer.cpp:(.text+0xa6): undefined reference to `SDL_GetTicks'
timer.o: In function `Timer::unpause()':
timer.cpp:(.text+0xe5): undefined reference to `SDL_GetTicks'
timer.o: In function `Timer::tick()':
timer.cpp:(.text+0x136): undefined reference to `SDL_GetTicks'
timer.o: In function `Timer::get_ticks()':
timer.cpp:(.text+0x172): undefined reference to `SDL_GetTicks'
screen.o: In function `init()':
screen.cpp:(.text+0xa): undefined reference to `SDL_Init'
screen.cpp:(.text+0x31): undefined reference to `SDL_SetVideoMode'
screen.cpp:(.text+0x64): undefined reference to `SDL_WM_SetCaption'
screen.o: In function `init_GL()':
screen.cpp:(.text+0x80): undefined reference to `glClearColor'
screen.cpp:(.text+0x8a): undefined reference to `glMatrixMode'
screen.cpp:(.text+0x8f): undefined reference to `glLoadIdentity'
screen.cpp:(.text+0xc0): undefined reference to `glOrtho'
screen.cpp:(.text+0xca): undefined reference to `glMatrixMode'
screen.cpp:(.text+0xcf): undefined reference to `glLoadIdentity'
screen.cpp:(.text+0xd4): undefined reference to `glGetError'
screen.o: In function `clean_up()':
screen.cpp:(.text+0xf4): undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status
내 포함 된 라이브러리
은 다음과 같습니다 : 최종g++ main.o obj_loader.o timer.o screen.o -o main
을 실행하는 경우에는
, 나는 정의되지 않은 참조 오류의 무리를 얻을 수
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
#include "GL/gl.h"
#include "GL/glu.h"
내 메이크 :
CC=g++
SDL_FLAGS=`sdl-config --cflags --libs`
GL_FLAGS=`pkg-config glu --cflags --libs`
CFLAGS=-c -Wall
FLAGS=$(CFLAGS) $(SDL_FLAGS) $(GL_FLAGS)
LDFLAGS=
SOURCES=main.cpp obj_loader.cpp timer.cpp screen.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o [email protected] $(LDFLAGS)
.cpp.o:
$(CC) $< -o [email protected] $(FLAGS)
clean:
rm -f *o main
예를 들어 명령 줄에서 작동하지 않는 명령 줄은 작동하는 라이브러리가 필요한 라이브러리를 링크하는 것을 보여주지 않습니다. 당신의 Makefile은 똑같은 문제를 가진 것 같습니다. 나는 그것이 작동하기를 기대하지 않을 것이다. –