Cannot find identifiers when compiling android project in visual studio

444 Views Asked by At

I successfully generated a visual studio project with Android ndk. Now I am trying to compile such project (by simply opening the solution and the building the BUILD_ALL project). The line I used to compile is the following (I am trying to build Ceres for Android):

cmake -G "Visual Studio 16" -A arm64 -DCMAKE_PREFIX_PATH=D:\DEV\ceres\gflags\build-gflags -DCMAKE_TOOLCHAIN_FILE="C:\Users\l.gagliano\AppData\Local\Android\Sdk\ndk\16.1.4479499\build\cmake\android.toolchain.cmake" -DEigen3_DIR=D:\DEV\ceres\eigen\build -DANDROID_ABI=arm64-v8a -DANDROID_STL=c++_static -DANDROID_NATIVE_API_LEVEL=android-24 -DBUILD_SHARED_LIBS=ON -DMINIGLOG=ON D:\DEV\ceres\ceres-solver-2.1.0

What I get however is a bunch of errors (I only post few of them cause the whole output is too big and moreover they're the same across all the sample projects).

Build started...
1>------ Build started: Project: ceres_internal, Configuration: Debug arm64 ------
1>ANDROID_HOME=C:\\Microsoft\AndroidSDK\25
1>ANT_HOME=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Apps\apache-ant-1.9.3
1>JAVA_HOME=C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot
1>NDK_ROOT=C:\\Microsoft\AndroidNDK64\android-ndk-r16b
1>ANDROID_HOME=C:\\Microsoft\AndroidSDK\25
1>ANT_HOME=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Apps\apache-ant-1.9.3
1>JAVA_HOME=C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot
1>NDK_ROOT=C:\\Microsoft\AndroidNDK64\android-ndk-r16b
1>partitioned_matrix_view_2_2_2.cc
1>In file included from <built-in>:370:
1><command line>(3,9): warning : '__ANDROID_API__' macro redefined [-Wmacro-redefined]
1>#define __ANDROID_API__ 24
1>        ^
1><command line>(1,9):  note: previous definition is here
1>#define __ANDROID_API__ 19
1>        ^
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres\generated\partitioned_matrix_view_2_2_2.cc:47:
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres/partitioned_matrix_view_impl.h:31:
1>In file included from C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\algorithm:641:
1>In file included from C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\cstring:61:
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(74,64): error : use of undeclared identifier 'strchr'
1>char* __libcpp_strchr(const char* __s, int __c) {return (char*)strchr(__s, __c);}
1>                                                               ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(81,75): error : use of undeclared identifier 'strpbrk'
1>char* __libcpp_strpbrk(const char* __s1, const char* __s2) {return (char*)strpbrk(__s1, __s2);}
1>                                                                          ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(88,65): error : use of undeclared identifier 'strrchr'; did you mean 'strchr'?
1>char* __libcpp_strrchr(const char* __s, int __c) {return (char*)strrchr(__s, __c);}
1>                                                                ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(76,13):  note: 'strchr' declared here
1>const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
1>            ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(95,76): error : use of undeclared identifier 'memchr'
1>void* __libcpp_memchr(const void* __s, int __c, size_t __n) {return (void*)memchr(__s, __c, __n);}
1>                                                                           ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(102,74): error : use of undeclared identifier 'strstr'; did you mean 'strchr'?
1>char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
1>                                                                         ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(78,13):  note: 'strchr' declared here
1>      char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
1>            ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(102,74): error : no matching function for call to 'strchr'
1>char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
1>                                                                         ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(78,13):  note: candidate disabled: <no message provided>
1>      char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
1>            ^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(102,81): error : cannot initialize a parameter of type 'char *' with an lvalue of type 'const char *'
1>char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
1>                                                                                ^~~~
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(78,32):  note: passing argument to parameter '__s' here
1>      char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
1>                               ^
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres\generated\partitioned_matrix_view_2_2_2.cc:47:
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres/partitioned_matrix_view_impl.h:31:
1>In file included from C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\algorithm:641:
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\cstring(70,9): error : no member named 'memcpy' in the global namespace; did you mean 'memchr'?
1>using ::memcpy;
1>      ~~^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(97,13):  note: 'memchr' declared here
1>const void* memchr(const void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
1>            ^
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres\generated\partitioned_matrix_view_2_2_2.cc:47:
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres/partitioned_matrix_view_impl.h:31:
1>In file included from C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\algorithm:641:
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\cstring(71,9): error : no member named 'memmove' in the global namespace
1>using ::memmove;
1>      ~~^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\cstring(72,9): error : no member named 'strcpy' in the global namespace; did you mean 'strchr'?
1>using ::strcpy;
1>      ~~^
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\string.h(76,13):  note: 'strchr' declared here
1>const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
1>            ^
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres\generated\partitioned_matrix_view_2_2_2.cc:47:
1>In file included from D:\DEV\ceres\ceres-solver-2.1.0\internal\ceres/partitioned_matrix_view_impl.h:31:
1>In file included from C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\algorithm:641:
1>C:\\Microsoft\AndroidNDK64\android-ndk-r16b\sources\cxx-stl\llvm-libc++\include\cstring(73,9): error : no member named 'strncpy' in the global namespace
1>using ::strncpy;

I am not sure where these error are coming from, my first suspicion is maybe the C++ standard being used but I cannot tell for sure. Can anyone give me an insight of where the problem might be?

2

There are 2 best solutions below

3
On

The Ceres for Android guide recommends using -DANDROID_STL=c++_shared for building Ceres. You are using -DANDROID_STL=c++_static, so STL is not being detected.

You can find a good explanation here: Confustion about Android NDK libc++ libc++_shared, libstdc++

0
On

This worked at the end:

cmake -G "Visual Studio 16" -A arm64 -DCMAKE_PREFIX_PATH=D:\DEV\ceres\gflags\build-gflags -DCMAKE_TOOLCHAIN_FILE="C:\Microsoft\AndroidNDK64\android-ndk-r16b\build\cmake\android.toolchain.cmake" -DEigen3_DIR=D:\DEV\ceres\eigen\build -DANDROID_ABI=arm64-v8a -DANDROID_STL=c++_shared -DANDROID_NATIVE_API_LEVEL=android-24 -DBUILD_SHARED_LIBS=ON -DMINIGLOG=ON -DCMAKE_CXX_STANDARD=14 D:\DEV\ceres\ceres-solver-2.1.0

Namely changing from:

-DCMAKE_TOOLCHAIN_FILE="C:\Users\l.gagliano\AppData\Local\Android\Sdk\ndk\16.1.4479499\build\cmake\android.toolchain.cmake"

To

-DCMAKE_TOOLCHAIN_FILE="C:\Microsoft\AndroidNDK64\android-ndk-r16b\build\cmake\android.toolchain.cmake"

I was generating a visual studio project but with the wrong ndk location (though it was also r16b) but I guess the visual studio one has something special that the other doesn't have.