On my Debian 9 system with Code::Blocks IDE I used to compile and link fine my gtk+3.0 application. But after update to the newest Debian 10 the linker cannot link to gtk+3.0 correctly.

Here are the command line macros in my Code::Blocsk IDE:

  1. compile single file to object file: $compiler $options $includes -c $file -o $object
  2. link object files to console executable: $linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs

This is the compiler's way of making object files:

g++ -Wall -std=c++11 -g -fPIC -c /home/pekov/Workshop/CodeBlocks/UniPhy_dev/math_module/coordinateTransform.cpp -o obj/Debug/coordinateTransform.o

This is the linker's attempt that fails (after the -rdynamic flag are my own libraries that compile fine):

g++ -o bin/Debug/tester obj/Debug/main.o -static-libgcc -lboost_iostreams -lboost_system -lboost_filesystem -lboost_serialization -lcomplex_bessel -larmadillo -lprocps -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -rdynamic ../math_module/bin/Debug/libmath_module.so ../poroelasticity_module/bin/Debug/libporoelasticity_module.a ../shared_library/bin/Debug/libshared_library.so ../BEM-FEM_library/bin/Debug/libBEM-FEM_library.so ../BEM_module/bin/Debug/libBEM_module.a ../elasticity_module/bin/Debug/libelasticity_module.a ../CAD_module/bin/Debug/libCAD_module.a ../GUI_module/bin/Debug/libGUI_module.a ../expression_parser/bin/Debug/libparser.a

The linker message is in the first encountered gtk+3.0 function:

undefined reference to 'gtk_widget_get_type'

I tried to extract more information from the linker but couldn't find anything else but the message above.

After the system upgraded the gcc compiler also upgraded and I think this could be the problem, but downgrading gcc is anything else but good idea. I tried with kali linux (rolling release) but the output is the same.

So I have found a solution (from here) by changing the compiler from gcc-9 to gcc-7:

  1. sudo apt-get install gcc-7 g++-7 g++-7-multilib gfortran-7
  2. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-7
  3. sudo update-alternatives --config gcc

Now it works fine but I wish it to work with the latest gcc-9!

1 Answer 1


I don’t know what the variables in $linker $libdirs -o $exe_output $link_objects $link_resobjects $link_options $libs correspond to, but the issue here is that the linker now tracks undefined objects in the order they’re encountered, and only resolves objects which have been previously missed. This means that libraries need to be specified after the objects which need their symbols: -lboost_iostreams ... -lglib-2.0 needs to come after libparser.a in your example.

  • Unfortunately this didn't work. I have shifted the order like you suggested but the problem remains. I also have shifted the order of the libraries in different ways but noting helped. Just for now I will use gcc-7 till I find a clue. Thanks though!
    – Pekov
    Sep 17, 2019 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .