我刚刚制作了一个程序,可以在Visual Studio中完美地编译和运行,并且应该与Android兼容(不使用特定于操作系统的Include),但是在Android Studio中的C++stl列表开始和结束迭代器函数下有一个红色错误Swiggle(以及编译失败的直接结果)。我对cmake几乎没有经验,因为它是与VS的唯一区别之一,所以它似乎是一个可能的罪魁祸首。
cpp文件:
void cellStats::removeAllMatches(int row, int col, int val)
{
std::list<layout>::iterator Layout = layoutListPointer.begin(); // Error here
while (Layout != layoutListPointer.end()) { // Error here
if (Layout->get(row, col) != val) {
layoutListPointer.erase(Layout);
}
else {
Layout++;
}
}
update();
}
头文件:
public:
void cellStats::removeAllMatches(int row, int col, int val)
//More
private:
std::list<layout> layoutListPointer;
//more
克马克主义者。txt:
cmake_minimum_required(VERSION 3.4.1)
set (CMAKE_CXX_STANDARD 11)
include_directories(${MY_SOURCE_DIR}/src/main/cpp)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
add_library(cellStats-class SHARED src/main/cpp/cellStats.cpp)
add_library(board-class SHARED src/main/cpp/board.cpp)
add_library(cell-class SHARED src/main/cpp/cell.cpp)
add_library(layout-class SHARED src/main/cpp/layout.cpp)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
编辑:错误日志为:
Build command failed.
Error while executing process C:\Users\Metagross\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\Metagross\AndroidStudioProjects\VoltorbFlipCalculator2\app\.externalNativeBuild\cmake\debug\x86 --target cellStats-class}
[1/2] Building CXX object CMakeFiles/cellStats-class.dir/src/main/cpp/cellStats.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libcellStats-class.so
FAILED: cmd.exe /C "cd . && C:\Users\Metagross\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android --gcc-toolchain=C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -LC:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libcellStats-class.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libcellStats-class.so CMakeFiles/cellStats-class.dir/src/main/cpp/cellStats.cpp.o -latomic -lm "C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++_static.a" "C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/x86/libc++abi.a" && cd ."
C:\Users\Metagross\AndroidStudioProjects\VoltorbFlipCalculator2\app\src\main\cpp/cellStats.cpp:39: error: undefined reference to 'layout::get(int, int)'
C:\Users\Metagross\AndroidStudioProjects\VoltorbFlipCalculator2\app\src\main\cpp/cellStats.cpp:91: error: undefined reference to 'layout::get(int, int)'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
C:/Users/Metagross/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/memory:1687: error: undefined reference to 'layout::~layout()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.