g++ fails with an undefined reference to symbol 'dlclose@@GLIBC_2.2.5' even with '-ldl'

13,904

You simply need to add the flags "-Wl and --start-group"

for scons add LINKFLAGS=['-Wl,--start-group'].

Reference: https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc

Share:
13,904

Related videos on Youtube

codedcosmos
Author by

codedcosmos

Updated on September 18, 2022

Comments

  • codedcosmos
    codedcosmos over 1 year

    I'm trying to compile a program with GLAD and SDL2 using scons (though scons isn't really relevant since g++ is the issue)

    scons runs the following command to compile part of the program:

    g++ -o out/cpptest bin/src/MainTest.o bin/src/main.o -L/usr/local/lib -Lbin/lib -ldl -lm -lGL -lGLU -lX11 -lpthread -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lglad -lSDL2 -pthread
    

    g++ returns the following error message:

    /usr/bin/ld: bin/lib/libglad.a(glad.c.o): undefined reference to symbol 
    'dlclose@@GLIBC_2
    .2.5'
     /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libdl.so: error 
     adding symbols: DSO missing from command line
     collect2: error: ld returned 1 exit status
    

    Some advice would be much apreciated.

    Also note the following flags ARE present:

        -ldl -lm -lpthread -pthread