gcc Invalid version (max ) error adding symbols: Bad value

I also encountered this issue. In my case, it was because my student forgot a -c tag when compiling an object.

The student had

gcc mySource.c -o myObject.o

but it should have been

gcc -c mySource.c -o myObject.o

instead.


So, I found the solution. The problem was:

I built a shared library - foo.so. foo was linked with some static libraries. I found that a lot of them included the __moddi3 function along with more libgcc stuff.

I was trying to link foo.so to an executable bar. bar also linked against static libraries and a lot of them also included the __moddi3 function along with more libgcc stuff.

The problem was that foo.so exported symbols it took from the static libraries - the __moddi3 function was among those symbols. See here a detailed cover of the scenario. So apparently what happened is that the executable took some libgcc stuff that weren't compatible with the __moddi3 function version that was exported by foo, Then when the linker encountered the __moddi3 version - It raised an error about me trying to link incompatible versions.

The Solution is given in the previous link. The way to deal with this is to use an export list in which you tell the compiler to export wanted symbols and hide all other symbols (using wildcard *).
Since I'm using CMake - I added -Wl,--version-script,exportmap to set_target_properties(foo PROPERTIES LINK_FLAGS. 'exportmap' is the name of my export list file. It's in the format of:

    {  
    global:  
         func_1;  
         func_2;  
         func_3;  
    local:  
         *;  
    }

If you're not using CMake add -Wl,--version-script,exportmap to C_FLAGS or CXX_FLAGS in the makefile.

use readelf -Ws foo.so to see your export symbols table.

Here's another good read on the subject.