Reciving a undefined refrence for glslang functions with g++

hello, i’m trying to incorporate the glslang c++ api into my program, however i am getting an error

undefined reference to glslang::InitializeProcess();

i have both tried installing glslang from source building and installing it into normal system-wide libs (my .a are in the proper places in usr/ locations… and my include libs are in the right place.
just to make sure i did not do something wrong i ALSO tired from apt-get repository the glslang-dev which also installed… still same error. on the command line it finds the librarys with the -l flag. i assume i’m missing a step, or need a particular path? or, do i need to include some particular folder into an external folder? is it just not possible to do this via g++? and need to use cmake (i’d prefer not to at this point). as i’m not so good at it yet, and i have other library issues, with cmake vs at the moment everything else works nicely and i’m still in the process of making lots of files, and changes. would rather stick to my g++ comple method. i’ve had diffcult finding examples that use just comand lines for compling… any help be thankful!

g++ -std=c++17 main.cpp vulkan_api.cpp vk_abstracionz.cpp vk_shaderz.cpp glad/src/vulkan.c exrtn_vulkan.cpp -o vlkantest.out -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi -lxcb -lglslang -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools

in my hpp.

#include <glslang/Public/ShaderLang.h>
#include <glslang/SPIRV/GlslangToSpv.h>
#include <glslang/SPIRV/spirv.hpp>
...
class parser_vulkan_modual{
...
    void init_glslang();
...
};

code in my .cpp

 void parser_vulkan_modual::init_glslang()
{
    if (!glslangInitialized)
    {   
        glslangInitialized = glslang::InitializeProcess();
       // glslangInitialized = ShInitialize(); - i also tried to see if i this would work... 
    }
}

i’ve tried with a make file… same result
the libglslang.a located in usr/local/lib is present. (i have also tried with -L /usr/local/lib just incase and when i do objdump -t libglslang.a

i can find the symbol

`0000000000000010 g     F .text	0000000000000015 glslang_initialize_process

CXX = g++
CXXFLAGS = -Wall -g -std=c++17
LIBS = -lglslang -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi -lxcb -lglslang -lSPIRV -lSPIRV-Tools-opt -lSPIRV-Tools

OBJ = main.o vulkan_api.o vk_abstracionz.o vk_shaderz.o exrtn_vulkan.o

vlkantest: ${OBJ}
${CXX} ${CXXFLAGS} -o $@ main.o vulkan_api.o vk_abstracionz.o vk_shaderz.o exrtn_vulkan.o ${LIBS}

main.o: main.cpp vk_shaderz.hpp vulkan_api.hpp

vulkan_api: vulkan_api.cpp vulkan_api.hpp

vk_abstracionz: vk_abstracionz.cpp vk_abstracionz.hpp

vk_shaderz: vk_shaderz.cpp vk_shaderz.hpp

exrtn_vulkan: exrtn_vulkan.cpp exrtn_vulkan.hpp

try

gcc --print-file-name libglslang.a

if your library is set correctly, it will show a full path to the library. On my archlinux setup will give the following path.

/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../lib/libglslang.a

By the way, the symbol for c++ is definitely not glslang_initialize_process, this is for c api. The c++ symbol is mangled by some certain rule(depends on your compiler and platform), this is called name mangling, you can search for more infos. In gcc world, It will look like this:

objdump -t /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../lib/libglslang.a |rg InitializeProcess
0000000000001950 g     F .text  0000000000000014 _ZN7glslang17InitializeProcessEv
0000000000000000         *UND*  0000000000000000 _ZN7glslang17InitializeProcessEv

Hope you can solve the problem, best wishes!

when i do

gcc --print-file-name libglslang.a

i get

/usr/lib/gcc/x86_64-linux-gnu/9/…/…/…/x86_64-linux-gnu/libglslang.a

and ah i was wondering if that was the c or c++ symbol makes sense it be mangled.
when i search the lib. i find

0000000000000000 UND 0000000000000000 _ZN7glslang17InitializeProcessEv

so though the lib is not the same one i was thinking it was (in the other usr/local/lib etc. this one that it is linking too is very much present.

Nothing else except this UND?
*UND* means: if the section is referenced in the file being dumped, but not defined there.
The right one should be F .text which means this is a function and is a text segment.

well then… this is intresting i did not have rg soo i had just done it manually on a wordprocessor but i installed it, and yes it appears

objdump -t /usr/lib/gcc/x86_64-linux-gnu/9/…/…/…/x86_64-linux-gnu/libglslang.a |rg InitializeProcess

only yeilds

0000000000000000 UND 0000000000000000 _ZN7glslang17InitializeProcessEv

i went ahead a purged both the glsang-dev and vulkan-sdk. i then reinstalled the vulkan-sdk still no dice… (from ubuntu repo) i then got the

glslang-master-linux-Release

and replaced all of the files in /usr/lib/x86_64-linux-gnu etc. same problem. no other result from the objdump nor changes in the complie result.

i ALSO have gone ahead and made a cmake and again, it finds the package ( i used 2 methods both find it, again it fails to resolve…

If I’m reading the source and CMakeLists.txt of glslang correctly the glslang::InitializeProcess function is actually in libMachineIndependent.a and for a static library build does not get combined into libglslang.a (for shared library build it looks like libglslang.so contains everything).
Can you check if libMachineIndependent.a contains a definition of the symbol and if so does adding -lMachineIndependent to the linker command line resolve the problem?

haha you know what. i literally. found this out myself like 10 min ago. i was im going through every .a via objdump and figure out where it is.
NOTE: however that JUST including -lMachineIndependent
was not enough as it also threw a ton of unresloved refs. i then was like okk… progress. you ALSO need, -lOSDependent and -lGenericCodeGen -lOGLCompiler also you have to make sure -lpthread comes AFTER the MI and OSD one. and now lol and behold it complies!
thx alll after 3 late eves of working on this resolved with all your support.

Glad you’ve find your way!
And I just wanna mention rg (ripgrep) is just a drop in replacement for grep, which is faster (and 2 char shorter then grep in command). I highly recommend it and even vscode is using it for global search task.

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.