moai / moai-dev

This is the development repo of Moai SDK.
http://getmoai.com
943 stars 313 forks source link

Linux build fails (and how to somehow fix it) #1207

Open iskolbin opened 6 years ago

iskolbin commented 6 years ago

Tried to build current branch recently, and build failed. After some trial I finally successfully build it, but with some hacks, so let me just list my problems and my 'fixes'.

  1. My system: Ubuntu 18.04.1 LTS on MSI Dominator laptop (2K14 or so)
  2. expat not compiling, complaining on You do not have support for any sources of high quality entropy, Upd thx @ciwrl, updated cmake:
    diff --git a/cmake/cmake/cmake-modules/platform-linux.cmake b/cmake/cmake/cmake-modules/platform-linux.cmake
    index 7b61c0c2d..c91cce9a6 100644
    --- a/cmake/cmake/cmake-modules/platform-linux.cmake
    +++ b/cmake/cmake/cmake-modules/platform-linux.cmake
    @@ -1,3 +1,3 @@
    #find_package ( OpenGL REQUIRED )
    -  set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPOSIX  -DNDEBUG -DHAVE_MEMMOVE" )
    -  set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DPOSIX " )
    \ No newline at end of file
    +  set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPOSIX  -DNDEBUG -DHAVE_MEMMOVE -DXML_DEV_URANDOM" )
    +  set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DPOSIX " )
  3. Old SDL2, build failed with:
    libmoai/third-party/sdl2/install/lib/libSDL2.a(SDL_waylandvideo.c.o): In function `wl_registry_bind':
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'
    libmoai/third-party/sdl2/install/lib/libSDL2.a(SDL_waylandvideo.c.o):/usr/include/wayland-client-protocol.h:1079: more undefined references to `wl_proxy_marshal_constructor_versioned' follow
    libmoai/third-party/sdl2/install/lib/libSDL2.a(SDL_waylandevents.c.o): In function `wl_registry_bind':
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'
    libmoai/third-party/sdl2/install/lib/libSDL2.a(SDL_waylandtouch.c.o): In function `wl_registry_bind':
    /usr/include/wayland-client-protocol.h:1079: undefined reference to `wl_proxy_marshal_constructor_versioned'

    to heal this, just updated SDL2 to 2.0.8, updated cmake file (see 5), note about bug and fix: http://blfs-dev.linuxfromscratch.narkive.com/bJ1fxg4e/sdl2-2-0-4-fails-to-compile-with-wayland-1-12-0

  4. Problems building sndio:
    libmoai/third-party/sdl2/install/lib/libSDL2.a(SDL_sndioaudio.c.o): In function `SNDIO_Init':
    SDL_sndioaudio.c:(.text+0xa3): undefined reference to `sio_open'
    SDL_sndioaudio.c:(.text+0xb1): undefined reference to `sio_close'
    SDL_sndioaudio.c:(.text+0xbf): undefined reference to `sio_setpar'
    SDL_sndioaudio.c:(.text+0xcd): undefined reference to `sio_getpar'
    SDL_sndioaudio.c:(.text+0xdb): undefined reference to `sio_start'
    SDL_sndioaudio.c:(.text+0xe9): undefined reference to `sio_stop'
    SDL_sndioaudio.c:(.text+0xf7): undefined reference to `sio_read'
    SDL_sndioaudio.c:(.text+0x105): undefined reference to `sio_write'
    SDL_sndioaudio.c:(.text+0x113): undefined reference to `sio_nfds'
    SDL_sndioaudio.c:(.text+0x121): undefined reference to `sio_pollfd'
    SDL_sndioaudio.c:(.text+0x12f): undefined reference to `sio_revents'
    SDL_sndioaudio.c:(.text+0x13d): undefined reference to `sio_eof'
    SDL_sndioaudio.c:(.text+0x14b): undefined reference to `sio_initpar'

    which is healed by adding link flag to cmake file (taken from https://stackoverflow.com/questions/41608136/sdl-sndioaudio-c-undefined-reference-to-sio#41621638), updted cmake file (see 5)

  5. Update SDL2 cmake file for new version and sndio fix
    
    diff --git a/cmake/cmake/third-party/sdl2/CMakeLists.txt b/cmake/cmake/third-party/sdl2/CMakeLists.txt
    index 6f85c3528..fa67a342e 100644
    --- a/cmake/cmake/third-party/sdl2/CMakeLists.txt
    +++ b/cmake/cmake/third-party/sdl2/CMakeLists.txt
    @@ -2,13 +2,13 @@ cmake_minimum_required ( VERSION 3.0 )
    project ( SDL2-static )
    include(ExternalProject)

-set (SDL2_SOURCE_DIR "${MOAI_ROOT}/3rdparty/sdl2-2.0.4") +set (SDL2_SOURCE_DIR "${MOAI_ROOT}/3rdparty/sdl2-2.0.8") set (SDL2_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/binarydir") ExternalProject_Add(sdl2 SOURCE_DIR "${SDL2_SOURCE_DIR}" CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/install" -DSDL_SHARED=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DLIBC=ON CMAKE_CACHE_ARGS "-DSDL2_SOURCE_DIR:string=${SDL2_SOURCE_DIR}" "-DSDL2_BINARY_DIR:string=${SDL2_BINARY_DIR}" "-DSDL_STATIC:bool=on" "-DSDL_SHARED:bool=off"

@@ -35,7 +35,6 @@ add_library(SDL2-static INTERFACE)

todo install headers too :)

target_include_directories(SDL2-static INTERFACE "${SDL2_SOURCE_DIR}/include_moai" "${SDL2_SOURCE_DIR}/include" ) -target_link_libraries(SDL2-static INTERFACE SDL2-static-imp )

+target_link_libraries(SDL2-static INTERFACE SDL2-static-imp sndio )

install(TARGETS SDL2-static EXPORT libmoai ARCHIVE DESTINATION lib)

6. Missing variable in `src/zl-gfx/ZLGfxDevice.cpp` (commented out, but used), fixed by using global variable, defined in this file
```diff
diff --git a/src/zl-gfx/ZLGfxDevice.cpp b/src/zl-gfx/ZLGfxDevice.cpp
index 409956b72..92287f688 100644
--- a/src/zl-gfx/ZLGfxDevice.cpp
+++ b/src/zl-gfx/ZLGfxDevice.cpp
@@ -124,7 +124,7 @@ void ZLGfxDevice::Initialize () {

                // if framebuffer object is not in code, check to see if it's available as
                // an extension and remap to core function pointers if so
-               if (( isOpenGLES == false ) && ( majorVersion < 3 )) {
+               if (( isOpenGLES == false ) && ( sMajorVersion < 3 )) {

                        if ( glewIsSupported ( "GL_EXT_framebuffer_object" )) {
  1. Cannot build moai-http-client, I guess problems with expat. Cannot find MOAIXmlParser. To fix this I modified #if guards:

    
    diff --git a/src/moai-http-client/MOAIHttpTaskBase.cpp b/src/moai-http-client/MOAIHttpTaskBase.cpp
    index d0d15f02f..5ac22486e 100644
    --- a/src/moai-http-client/MOAIHttpTaskBase.cpp
    +++ b/src/moai-http-client/MOAIHttpTaskBase.cpp
    @@ -3,7 +3,7 @@
    
    #include "pch.h"

-#if MOAI_WITH_TINYXML +#if MOAI_WITH_TINYXML && MOAI_WITH_EXPAT

include

endif

@@ -225,7 +225,7 @@ int MOAIHttpTaskBase::_isBusy ( lua_State L ) { int MOAIHttpTaskBase::_parseXml ( lua_State L ) { MOAI_LUA_SETUP ( MOAIHttpTaskBase, "U" )


Hope this will help:)
ciwrl commented 6 years ago

Proper fix should be to declare your entropy source as a CFLAG

https://github.com/moai/moai-dev/blob/develop/cmake/cmake/cmake-modules/platform-linux.cmake#L2

Add -DXML_DEV_URANDOM to that line.

This should remove the need for further dependency updates.

iskolbin commented 6 years ago

@ciwrl thx, updated