OpenGL libraries linkage on linux

2019-08-10 10:39发布

I coded a small OpenGL program displaying a simple quad. To do the job done, I linked -lglut in my Makefile. Until here all is ok.

Here's my Makefile content :

NAME        =   Quad

CXX     =   g++

SRCS        =   main.cpp

OBJS        =   $(SRCS:.cpp=.o)

CXXFLAGS    +=  -W  -Werror -Wextra

LIBX        +=  -lglut

RM      =   rm  -f

all     :   $(NAME)

$(NAME)     :   $(OBJS)
            $(CXX)  -o  $(NAME) $(OBJS) $(LIBX)

clean       :
            find . \( -name "*.o" -o -name "*~" -o -name "#*#" \) -exec $(RM) {} \;

fclean      :   clean
            $(RM)   $(NAME)

re      :   fclean  all

.PHONY      :   all     \
            clean       \
            fclean      \
            re

But now I want to make a linkage with my own librairies resources files. Here's the content of my project directory :

main.cpp
Makefile
Outbuilding/GL/include/glut.h
Outbuilding/GL/lib/glut32.lib

My include declaration in main.cpp

#include "gl/glut.h"

I tried to edit the following Makefile but it does not work (the file gl/glut.h is not found) :

NAME        =   Quad

CXX     =   g++

SRCS        =   main.cpp

OBJS        =   $(SRCS:.cpp=.o)

CXXFLAGS    +=  -W  -Werror -Wextra

INCLUDE     +=  -I./Outbuilding/GL/include -L./Outbuilding/GL/lib
LIBX        +=  -lglut

RM      =   rm  -f

all     :   $(NAME)

$(NAME)     :   $(OBJS)
            $(CXX)  -o  $(NAME) $(OBJS) $(INCLUDE) $(LIBX)

clean       :
            find . \( -name "*.o" -o -name "*~" -o -name "#*#" \) -exec $(RM) {} \;

fclean      :   clean
            $(RM)   $(NAME)

re      :   fclean  all

.PHONY      :   all     \
            clean       \
            fclean      \
            re

I also tried in my source file to link directly glut.h (#include "./Outbuilding/GL/include/gl/glut.h") but I have the following error :

error : "APIENTRY" redefined

Does anyone can help me ?

1条回答
贼婆χ
2楼-- · 2019-08-10 11:33

Your glut.h file is in the wrong folder.

Normally glut.h is a gl folder, either global or local to your project.

Just create a folder called *gl8 inside Outbuilding/GL/include/ and move the glut.h into it.

查看更多
登录 后发表回答