Open lwyj123 opened 3 years ago
@lwyj123 getting the same error with SDL2.
CMakeLists.txt
(top level)
cmake_minimum_required(VERSION 3.13)
project(MRT1-C-Praktikum)
enable_language(C)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2")
# Unterverzeichnisse
add_subdirectory(mrt_lib)
# Ausführbares Programm
add_executable(fraktal_sets main.c)
target_link_libraries(fraktal_sets PUBLIC mrt_lib)
CMakeLists.txt
(sub-level, inside a library)
add_library(mrt_lib src/fraktal.c src/graphic.c src/dialog.c)
target_include_directories(mrt_lib PUBLIC include)
running emcmake cmake ..
and then emmake make
produces the following errors:
make: make
[ 66%] Built target mrt_lib
[ 83%] Linking C executable fraktal_sets.js
error: undefined symbol: SDL_CreateRenderer (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _SDL_CreateRenderer may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_CreateTexture (referenced by top-level compiled C/C++ code)
warning: _SDL_CreateTexture may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_CreateWindow (referenced by top-level compiled C/C++ code)
warning: _SDL_CreateWindow may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_DestroyTexture (referenced by top-level compiled C/C++ code)
warning: _SDL_DestroyTexture may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_RenderClear (referenced by top-level compiled C/C++ code)
warning: _SDL_RenderClear may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_RenderCopy (referenced by top-level compiled C/C++ code)
warning: _SDL_RenderCopy may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_RenderDrawPoint (referenced by top-level compiled C/C++ code)
warning: _SDL_RenderDrawPoint may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_RenderPresent (referenced by top-level compiled C/C++ code)
warning: _SDL_RenderPresent may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_RenderSetLogicalSize (referenced by top-level compiled C/C++ code)
warning: _SDL_RenderSetLogicalSize may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_SetHint (referenced by top-level compiled C/C++ code)
warning: _SDL_SetHint may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_SetRenderDrawColor (referenced by top-level compiled C/C++ code)
warning: _SDL_SetRenderDrawColor may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: SDL_SetRenderTarget (referenced by top-level compiled C/C++ code)
warning: _SDL_SetRenderTarget may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: '/home/lennart/tools/emsdk/node/12.18.1_64bit/bin/node /home/lennart/tools/emsdk/upstream/emscripten/src/compiler.js /tmp/tmp9pqun6ca.txt' failed (1)
make[2]: *** [CMakeFiles/fraktal_sets.dir/build.make:88: fraktal_sets.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/fraktal_sets.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
My main problem with the build process with emscripten (+ cmake) is, that I still don't fully understand, where and how I have to add the SDL Library. I understand it, if I only have one source file and how to add it there with emcc. But with a larger projekt, it becomes a bit confusing and unfortunately after hours of searching I can't find information about it, neither on emscripten.org.
The project compiled just fine of course, when only using CMake (the CMakeLists.txt files I changed since then), the errors are appearing only now, since I'm trying to bring the program into the web.
@Noxdor add to your target_link_libraries the SDL2 lib like here:
target_link_libraries(jngl PUBLIC ${FREETYPE_LIBRARIES} ${OPENAL_LIBRARY} SDL2 freetype ogg vorbis)
@pinguin999 Thanks, actually I figured it out already quit a while back, but yeah, that solved the problem. Quit an amazing technology WASM. Just takes some time to get used to the new toolchain and the few but important changes in the code.
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
I built a simple demo for rendering a simple arch in window using SDL2 + cairo. But I get some error when I try to do it with emscripten and get the error like
error: undefined symbol: cairo_set_line_width (referenced by top-level compiled C/C++ code)
.Here is the
CMakeLists.txt
And below is the shell script I used for dev.
But after I run the command
cmmake make
, I get the error log:but if I run the native cmake like below
It just works fine.