Kadabash Kadabash - 6 months ago 28
C++ Question

How do I change the order in automake's CXXLINK?

I am trying to compile a simple C++ program with the automake tools. By itself, automake creates in its Makefile the line:


This way, however, i get some linker errors, which can be resolved by simply putting the
-o example example.cpp
part in the beginning of the g++ command instead of the end.

How can I instruct automake to put the
-o example example.cpp
in front of the linker commands?

Here is the


GLTest_SOURCES = main.cpp

AM_CXXFLAGS=@gllibs_CFLAGS@ -std=c++11 -pthread
AM_LDFLAGS=@gllibs_LIBS@ -lGL -lGLEW -lglfw -lX11 -lXi -lXrandr

Here are the linker errors:

g++ -I/usr/include/libdrm -std=c++11 -pthread -g -O2 -lGLEW -lGLU -lGL -lglfw -lGL -lGLEW -lglfw -lX11 -lXi -lXrandr -o GLTest main.o
main.o: In function `main':
main.cpp:8: undefined reference to `glfwInit'
main.cpp:9: undefined reference to `glfwWindowHint'
main.cpp:10: undefined reference to `glfwWindowHint'
main.cpp:11: undefined reference to `glfwWindowHint'
main.cpp:12: undefined reference to `glfwWindowHint'
main.cpp:14: undefined reference to `glfwCreateWindow'
collect2: error: ld returned 1 exit status

These are resolved when I compile it manually like this:

g++ -o GLTest main.cpp -I/usr/include/libdrm -std=c++11 -pthread -g -O2 -lGLEW -lGLU -lGL -lglfw -lGL -lGLEW -lglfw -lX11 -lXi -lXrandr


From the linker command in the output it looks like you are not using libtool.

Try adding AM_PROG_LIBTOOL to the configure.ac.