Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failure for android on Windows #927

Closed
yuanyazhen opened this issue Mar 5, 2019 · 8 comments · Fixed by #968
Closed

Build failure for android on Windows #927

yuanyazhen opened this issue Mar 5, 2019 · 8 comments · Fixed by #968
Assignees

Comments

@yuanyazhen
Copy link

yuanyazhen commented Mar 5, 2019

Describe the bug
cannot build android aar on Windows

To Reproduce
The first error happened in the second steps of Build stages (describled at android/Windows.md)

clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] testCCompiler.c:2:3: error: "The CMAKE_C_COMPILER is set to a C++ compiler" # error "The CMAKE_C_COMPILER is set to a C++ compiler"

I check the toolchain cmake in the filament/build/toolchain-arm7-linux-android.cmake

if(WIN32)
set(COMPILER_SUFFIX ".cmd")
set(CMAKE_AR ${TOOLCHAIN}/bin/${ARCH}-ar.exe CACHE FILEPATH "Archiver")
endif()
set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/${ARCH}${API_LEVEL}-clang${COMPILER_SUFFIX})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/bin/${ARCH}${API_LEVEL}-clang++${COMPILER_SUFFIX})
set(CMAKE_AR ${TOOLCHAIN}/bin/${ARCH}-ar${COMPILER_SUFFIX})
set(CMAKE_RANLIB ${TOOLCHAIN}/bin/${ARCH}-ranlib${COMPILER_SUFFIX})
set(CMAKE_STRIP ${TOOLCHAIN}/bin/${ARCH}-strip${COMPILER_SUFFIX})

But the NDK(r19) doesn't have the arm7-linux-android21-clang.cmd, so as the -ar.cmd or ranlib.

So i change the .cmake into follows

set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/clang.exe)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/bin/clang++.exe)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DANDROID --target=armv7a-linux-androideabi21 -fno-addrsig" CACHE STRING "Toolchain CFLAGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} --stdlib=libc++" CACHE STRING "Toolchain CXXFLAGS")
set(CMAKE_AR ${TOOLCHAIN}/bin/${ARCH}-ar.exe)
set(CMAKE_RANLIB ${TOOLCHAIN}/bin/${ARCH}-ranlib.exe)
set(CMAKE_STRIP ${TOOLCHAIN}/bin/${ARCH}-strip.exe)

it successfully write makefiles.

But the ninja install complained

clang.exe: error: unsupported option '-fPIC' for target 'x86_64-w64-windows-gnu'
clang.exe: error: unsupported option '-fPIC' for target 'x86_64-w64-windows-gnu'

So i change the .cmake
set(CMAKE_POSITION_INDEPENDENT_CODE OFF) ON ->OFF

But the ninja still complains with -fPIC on materials.S.o, after some digging.
in the filament/CMakeLists.txt , i commented

set(LINUX_COMPILER_FLAGS
-fPIC
)

Now all the libs is build. [Maybe not all?]

image

So i went to generate filament-android.

but i got

D:/Projects/Filament_Windows/out/android-release/filament/lib/armeabi-v7a/libfilament.a(Engine.cpp.o):Engine.cpp:function filament::details::FEngine::init(): error: undefined reference to 'MATERIALS_PACKAGE' D:/Projects/Filament_Windows/out/android-release/filament/lib/armeabi-v7a/libfilament.a(Engine.cpp.o):Engine.cpp:function filament::details::FEngine::init(): error: undefined reference to 'MATERIALS_PACKAGE' D:/Projects/Filament_Windows/out/android-release/filament/lib/armeabi-v7a/libfilament.a(Skybox.cpp.o):Skybox.cpp:function filament::details::FSkybox::createMaterial(filament::details::FEngine&, bool): error: undefined reference to 'MATERIALS_PACKAGE' D:/Projects/Filament_Windows/out/android-release/filament/lib/armeabi-v7a/libfilament.a(Skybox.cpp.o):Skybox.cpp:function filament::details::FSkybox::createMaterial(filament::details::FEngine&, bool): error: undefined reference to 'MATERIALS_PACKAGE' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation) inja: build stopped: subcommand failed.

Now i am really stucked.

Several unsuccessful attemtion.

  1. Try aarch64, similar issue with fPIE
  2. try build libfilamat.a, and add it in the filament-android's CMakeList.txt, still failed.

So any suggestion?

@bejado bejado self-assigned this Mar 5, 2019
@romainguy
Copy link
Collaborator

But the NDK(r19) doesn't have the arm7-linux-android21-clang.cmd, so as the -ar.cmd or ranlib.

What executables does the Windows NDK provide instead? Is it just clang.exe and clang++.exe?

@yuanyazhen
Copy link
Author

yuanyazhen commented Mar 6, 2019

Sorry for the typo.

image

The NDK(r19) does have the arm7-linux-android21-clang.cmd but it doesn't have clang++.cmd.

Moreover, in their clang.cmd, they are using clang++, that's why the cmake complains.

@echo off setlocal call :find_bin if "%1" == "-cc1" goto :L set "_BIN_DIR=" && %_BIN_DIR%clang++.exe --target=armv7a-linux-androideabi21 -fno-addrsig -stdlib=libc++ %*

for the -ar and ranlib, only .exe exists.

@romainguy
Copy link
Collaborator

Thank you, we'll fix the toolchain file.

@maikschulze
Copy link

Hi @CgGraphic , hi @romainguy

I went through similar issues and just a minute ago successfully compiled the filament libraries for Android.

1.) Broken ndk19b

From my understanding, the error "The CMAKE_C_COMPILER is set to a C++ compiler" is known and has been fixed in the NDK 19 and 20 branches:
android/ndk#920

I downloaded the appropriate NDK build here:
https://partner.android.com/partnerdash/d/partnerandroidbuild#p:id=buildlist&a=100621237&h=YnJhbmNoPWFvc3AtbmRrLXJlbGVhc2UtcjE5JnByb2R1Y3Q9d2luNjQ

, specifically android-ndk-5345600-windows-x86_64.zip

I've replaced the contents \android-sdk\ndk-bundle with zip. This fixed the compiler test.

2.) Adaptions to toolchain files

a) toolchain-aarch64-linux-android.cmake

I've commented out these three lines:

#set(CMAKE_AR           ${TOOLCHAIN}/bin/${ARCH}-ar${COMPILER_SUFFIX})
#set(CMAKE_RANLIB       ${TOOLCHAIN}/bin/${ARCH}-ranlib${COMPILER_SUFFIX})
#set(CMAKE_STRIP        ${TOOLCHAIN}/bin/${ARCH}-strip${COMPILER_SUFFIX})

b) toolchain-arm7-linux-android.cmake

I've adadapted these three lines:

set(CMAKE_AR           ${TOOLCHAIN}/bin/${AR_ARCH}-ar.exe)
set(CMAKE_RANLIB       ${TOOLCHAIN}/bin/${AR_ARCH}-ranlib.exe)
set(CMAKE_STRIP        ${TOOLCHAIN}/bin/${AR_ARCH}-strip.exe)

I hope this helps!

@yuanyazhen
Copy link
Author

@maikschulze Thanks,

It seems that to successfully run the android sample, the CMakeLists.txt needs to be changed too.
Otherwise, the link will fail as I described.

I change line 321 from

WEBGL OR WIN32

to

WEBGL OR WIN32 OR ANDROID

Now, the android samples run successfully.

@romainguy
Copy link
Collaborator

@maikschulze Thank you, I'm about to upload a change with the proper fixes.

romainguy added a commit that referenced this issue Mar 12, 2019
@romainguy
Copy link
Collaborator

You can try PR #968 to see if it fixes your issues with the new NDK.

romainguy added a commit that referenced this issue Mar 12, 2019
* Fix Android builds on Windows

This PR fixes #927

* Add missing endline

* Fix armv7a Android builds
@maikschulze
Copy link

@romainguy ,
thank you very much for the quick fixes. I can confirm that this proper approach works. The Android samples also run successfully on x86 and armv7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants