4

Possible Duplicate:
GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'

Alright so I'm trying to compile a shared object library made up of 2 object files and a static library. I'm linking to libraries, but only Lua is actually used in MY objects the others are used in the .a file.

Here's the IDE generated linking step:

g++ -shared  obj/Debug/GL/Window/Window.o obj/Debug/main.o   -o bin/Debug/libLOOGL.so -lX11 -lXrandr -lGL -llua5.2  /home/matt/Desktop/Development/LOOGL/lib/bin/OOGL.a

Here's the output of ldd on the result:

ldd loogl.so
  linux-vdso.so.1 =>  (0x00007fff30b3e000)
  liblua5.2.so.0 => /usr/lib/x86_64-linux-gnu/liblua5.2.so.0 (0x00007f521b53e000)
  libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f521b23e000)
  libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f521b027000)
  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f521ac68000)
  libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f521a96e000)
  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f521a769000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f521b991000)

The necessary libraries are not linked and the result will not run, it is missing references.

Community
  • 1
  • 1

1 Answers1

3

The order of libraries on the link line is important:

Try:

g++ -shared  obj/Debug/GL/Window/Window.o obj/Debug/main.o   -o bin/Debug/libLOOGL.so /home/matt/Desktop/Development/LOOGL/lib/bin/OOGL.a -lX11 -lXrandr -lGL -llua5.2  
Martin York
  • 257,169
  • 86
  • 333
  • 562