emscripten-core / emscripten-core/emsdk
Error when running (or linking) with GLFW
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 821
- Avg merge
- 1h 25m
- Merged PRs (30d)
- 3
Description
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](https://emscripten.org/docs/compiling/Building-Projects.html#building-projects) and [this one](https://thatonegamedev.com/cpp/programming-a-c-game-for-the-web-emscripten/#project-structure) 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.

Here's my CMakeLists.txt
```cmake
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
```bash
ROOT="/home/arthur/dev/deps/emsdk/upstream/emscripten"
$ROOT/emcmake cmake ..
$ROOT/emmake make
```
And its succesfull output is the following

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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.