Skip to content

Linker error undefined symbol: glMultMatrixd when using GLU with gl4es on Emscripten #490

@arti-max

Description

@arti-max

Hello,

I'm encountering a linking issue when trying to use GLU with gl4es in an Emscripten project. I've been following the advice from previously created issues (like #352), but I'm still hitting a wall.

When I add a call to gluPerspective, I get the following linker error:

wasm-ld: error: D:/!jsproj/CrossCraftWebPP/lib/libGLU.a(project.o): undefined symbol: glMultMatrixd

Here is what I've done so far:

Successfully compiled gl4es with -DEXPORT_LIB=1 to make GL symbols visible.

Created a CMakeLists.txt for the ptitSeb/GLU repository and compiled libGLU.a for Emscripten, resolving issues with register keyword and LONG_MAX along the way.

Disabled name mangling for GLU by commenting out #include "glu_mangle.h" in the gl4es version of glu.h.

Despite all this, the glMultMatrixd symbol required by GLU cannot be found in gl4es during the final link stage.

Here is my project's CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(CrossCraftWebPP)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

set(SOURCES
    src/main.cpp
    src/render/Tessellator.cpp
)

add_executable(CrossCraftWebPP ${SOURCES})

if(EMSCRIPTEN)
    target_link_libraries(CrossCraftWebPP PRIVATE 
        glfw
        -Wl,--start-group
        "${CMAKE_CURRENT_SOURCE_DIR}/lib/libGLU.a"
        "${CMAKE_CURRENT_SOURCE_DIR}/lib/libGL.a"
        -Wl,--end-group
    )

    set_target_properties(CrossCraftWebPP PROPERTIES 
        LINK_FLAGS "\
            -s WASM=1 \
            -s USE_GLFW=3 \
            -s FULL_ES2=1 \
            -s ALLOW_MEMORY_GROWTH=1 \
        "
    )
    
    set_target_properties(CrossCraftWebPP PROPERTIES SHELL_FILE "${CMAKE_SOURCE_DIR}/index.html")
    set_target_properties(CrossCraftWebPP PROPERTIES OUTPUT_NAME "game")
    set_target_properties(CrossCraftWebPP PROPERTIES SUFFIX ".html")
endif()

Am I missing a crucial step, or is there a fundamental incompatibility here?

Any help or insight would be greatly appreciated. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions