emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
3k stars 682 forks source link

Error when running (or linking) with GLFW #1428

Open arthurBricq opened 2 months ago

arthurBricq commented 2 months ago

Hello everyone, and thanks in advance for the support.

I have been trying to compile small example of mine with OpenGL+GLFW+GLAD. The C++ code is accessible here: https://github.com/arthurBricq/RubicsCube/, alongside with the emscripten scripts that I use to compile and run (https://github.com/arthurBricq/RubicsCube/tree/main/build_emscripten). Of course the C++ executable works.

By following several tutorials, mostly the officials and this one I successfully managed to compile my code. The problem is that when I run the code (with http local server to open the generated .html file), I get an error : Exception thrown, see JavaScript console. But the exception in the console seems very very obscure to me...

It seems to be Aborted(native code called abort()) but really I couldn't find more about the error.

image

Here's my CMakeLists.txt

cmake_minimum_required( VERSION 3.5 )
project(Tuto1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)

if (EMSCRIPTEN)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s WASM=1")
    set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif ()

if(NOT EMSCRIPTEN) 
    # not adding glfw when compiling with emscripten
    set(OpenGL_GL_PREFERENCE GLVND)
    find_package(OpenGL REQUIRED)
    find_package(glfw3 REQUIRED)
    include_directories( ${OPENGL_INCLUDE_DIRS} )
endif()

include_directories("./glad/include")
include_directories("./glm")

set( GLFW_BUILD_DOCS OFF CACHE BOOL  "GLFW lib only" )
set( GLFW_INSTALL OFF CACHE BOOL  "GLFW lib only" )
set( GLAD_GL "" )

add_executable(Hello3D main3d.cpp glad/src/glad.c shader.cpp)
target_link_libraries(Hello3D ${OPENGL_LIBRARIES} glfw)

My compilation script is

ROOT="/home/arthur/dev/deps/emsdk/upstream/emscripten"
$ROOT/emcmake cmake ..
$ROOT/emmake make

And its succesfull output is the following

image

So, considering the warnings, I am assuming that there is a linking problem. But I really did not the solution on the already existing issues of this forum.

Thanks in advance

PS: I use Ubuntu

kripken commented 2 months ago

Some tips are here:

https://emscripten.org/docs/porting/Debugging.html

In particular, build with -g to get proper symbol names. That would show function names in the stack trace, so you would see what is calling abort().