Hugo Riggs
Hugo Riggs

Reputation: 79

Trouble compiling fractal animation program Xlib and glut

Downloaded the code from this source: http://n.ethz.ch/~vartokb/gl-shaders.html

I run the make file and I get undefined references to xlib and glut libraries. e.g.,

  undefined reference to `XOpenDisplay'
  undefined reference to `XDefaultScreen'
  undefined reference to `glXChooseVisual'
  .
  .
  .
   undefined reference to `__glewGenBuffers'
   undefined reference to `__glewBindBuffer'
   undefined reference to `__glewBufferData'

The compile line looks like this and the makefile is below:

   g++ -L/usr/include/GL/ -L/usr/include/X11/ -lm -lrt -lglut -lGLEW -lGL -lGLU -lX11 main.o events.o graphics.o -o gl-shaders

The Makefile:

NAME = gl-shaders
CXX = g++
CXXFLAGS = -O3
LDFLAGS = -L/usr/include/GL/ -L/usr/include/X11/ -lm -lrt -lglut -lGLEW -lGL -lGLU -lX11
SRCS = main.cpp events.cpp graphics.cpp
OBJS = $(SRCS:%.cpp=%.o)
HDRS = config.hpp main.hpp

all: $(NAME)

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

.cpp.o:
        $(CXX) $(CFLAGS) $(LFLAGS) -c $< -o $@

$(OBJS): $(HDRS)

clean:
        rm -f $(OBJS)
        rm -f $(NAME)

I have installed Xlib by running:

sudo aptitude install xorg-dev
sudo apt install xorg-dev
sudo apt-get install libx11-dev

And I installed freeglut a while ago. When I list the contents of the directories linked in the makefile I see:

 :l /usr/include/GL/
freeglut_ext.h  freeglut_std.h  glew.h   gl.h         glu.h         glut.h   glxext.h  glxint.h      glxmd.h     glxtokens.h  wglew.h
freeglut.h      glcorearb.h     glext.h  gl_mangle.h  glu_mangle.h  glxew.h  glx.h     glx_mangle.h  glxproto.h  internal/

and for Xlib:

l /usr/include/X11/
ap_keysym.h   Constraint.h  DECkeysym.h  HPkeysym.h    IntrinsicP.h  RectObj.h     ShellI.h      TranslateI.h  Xatom.h   Xdmcp.h       XKBlib.h    Xmd.h      Xpoll.h      Xthreads.h  Xwindows.h
bitmaps/      ConvertI.h    dri/         ICE/          keysymdef.h   RectObjP.h    ShellP.h      VarargsI.h    Xauth.h   XF86keysym.h  XlibConf.h  Xmu/       Xproto.h     Xtos.h      Xwinsock.h
CallbackI.h   Core.h        EventI.h     ImUtil.h      keysym.h      ResConfigP.h  SM/           Vendor.h      Xaw/      Xft/          Xlib.h      Xosdefs.h  Xprotostr.h  Xtrans/
Composite.h   CoreP.h       extensions/  InitialI.h    Object.h      ResourceI.h   StringDefs.h  VendorP.h     Xcms.h    Xfuncproto.h  Xlibint.h   Xos.h      Xregion.h    Xutil.h
CompositeP.h  CreateI.h     fonts/       Intrinsic.h   ObjectP.h     SelectionI.h  Sunkeysym.h   Xalloca.h     Xcursor/  Xfuncs.h      Xlib-xcb.h  Xos_r.h    Xresource.h  Xw32defs.h
ConstrainP.h  cursorfont.h  HookObjI.h   IntrinsicI.h  PassivGraI.h  Shell.h       ThreadsI.h    Xarch.h       Xdefs.h   X.h           Xlocale.h   xpm.h      xshmfence.h  XWDFile.h

Why do I get undefined references when I have all the required files for compilation?

Upvotes: 3

Views: 494

Answers (1)

Hugo Riggs
Hugo Riggs

Reputation: 79

My problem was parameter ordering, as user cyberguijarro points out over here: Linker problems in Ubuntu 11.10

@boto I know that. Actually, the problem was in the parameter order. Ubuntu 11.10 ships GCC 4.6.1, which apparently introduces stricter parameter ordering constraints. g++ test.cpp -lX11 works fine. – cyberguijarro Jan 24 '12 at 9:37

So by changing the compile line from this:

g++ -I/usr/include/GL/ -lglut -lGL -lGLEW -lGLU -I/usr/include/X11/ -lm -lrt -lX11 main.o events.o graphics.o -o gl-shaders

to this:

g++ main.o events.o graphics.o -I/usr/include/GL/ -lglut -lGL -lGLEW -lGLU -I/usr/include/X11/ -lm -lrt -lX11 -o gl-shaders

allowed it to compile.

Upvotes: 1

Related Questions