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:
- compile single file to object file:
$compiler $options $includes -c $file -o $object
- 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:
sudo apt-get install gcc-7 g++-7 g++-7-multilib gfortran-7
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
sudo update-alternatives --config gcc
Now it works fine but I wish it to work with the latest gcc-9!