danginsburg / opengles3-book

OpenGL ES 3.0 Programming Guide Sample Code
MIT License
1.92k stars 746 forks source link

how to compile a libCommon.a that can be used on Android Platform? #64

Open perfectworld0415 opened 4 years ago

perfectworld0415 commented 4 years ago

I compiled it with NDK toolchains on Ubuntu , errors happened like X11/Xlib.h' file not found? Anyone knows how to solve it?

danginsburg commented 4 years ago

It sounds like it's building the Linux/X11 version instead of the Android version. It should be using this: https://github.com/danginsburg/opengles3-book/blob/master/Common/Source/Android/esUtil_Android.c

@javedrabbani can you advise?

javedrabbani commented 4 years ago

@perfectworld0415 Can you please share how you are building on Ubuntu? I mean please share how you are invoking CMake to build for android?

perfectworld0415 commented 4 years ago

@perfectworld0415 Can you please share how you are building on Ubuntu? I mean please share how you are invoking CMake to build for android?

Cmakelist.txt: set ( common_src Source/esShader.c Source/esShapes.c Source/esTransform.c Source/esUtil.c )

Win32 Platform files

if(WIN32) set( common_platform_src Source/Win32/esUtil_win32.c ) add_library( Common STATIC ${common_src} ${common_platform_src} ) target_link_libraries( Common ${OPENGLES3_LIBRARY} ${EGL_LIBRARY} ) else() find_package(X11) find_library(M_LIB m) find_package(Threads) find_library(android-lib android) find_library(log-lib log )

set( common_platform_src Source/LinuxX11/esUtil_X11.c )

set( common_platform_src Source/Android/esUtil_Android.c )
# add_library( Common STATIC ${common_src} ${common_platform_src} )
add_library( Common SHARED ${common_src} ${common_platform_src} )
target_link_libraries( Common ${OPENGLES3_LIBRARY} ${EGL_LIBRARY} ${X11_LIBRARIES} ${M_LIB} ${CMAKE_THREAD_LIBS_INIT} ${android-lib} ${log-lib})

endif()

Cmake : cmake -DCMAKE_TOOLCHAIN_FILE=/home/codingbo/Liuqc/android-ndk-r20/build/cmake/android.toolchain.cmake \ -DANDROID_ABI="arm64-v8a" \ -DANDROID_ARM_NEON=ON \ -DANDROID_STL=c++_static \ -DANDROID_PLATFORM=android-24 \ ..

error : CMakeFiles/Common.dir/Source/Android/esUtil_Android.c.o: In function android_main': /home/codingbo/Liuqc/WorkSpace/opengles3-book-master/Common/Source/Android/esUtil_Android.c:142: undefined reference toapp_dummy' CMakeFiles/Common.dir/Source/Android/esUtil_Android.c.o: In function HandleCommand': /home/codingbo/Liuqc/WorkSpace/opengles3-book-master/Common/Source/Android/esUtil_Android.c:86: undefined reference toesMain' /home/codingbo/Liuqc/WorkSpace/opengles3-book-master/Common/Source/Android/esUtil_Android.c:86: undefined reference to `esMain' clang: error: linker command failed with exit code 1 (use -v to see invocation) Common/CMakeFiles/Common.dir/build.make:148: recipe for target 'Common/libCommon.so' failed