SIGFPE (unknown crash reason) - (GLThread)

I have an app which works fine for iOS. Unfortunately I can’t get it to run on android. It just crashes with showing SIGFPE (unknown crash reason) in GLThread:

Now the only part in my code which is different to ios is:

AppDelegate:

after

register_all_packages();

This Code

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

    //second - save it:
    const std::string dbPath = FileUtils::getInstance()->getWritablePath() + "mydatabase.db";

    if(!FileUtils::getInstance()->isFileExist (dbPath)){
        
        const std::string filePath = FileUtils::getInstance()->fullPathForFilename("mydatabase.db");

        auto data =  FileUtils::getInstance()->getDataFromFile(filePath);

FileUtils::getInstance()->writeDataToFile(data, dbPath);
        
    }
    
#endif

DatabaseReader: <- Class where the reading is happening

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
    const std::string dbPath = FileUtils::getInstance()->getWritablePath() + "mydatabase.db";
#else
    const std::string dbPath = FileUtils::getInstance()->fullPathForFilename("mydatabase.db");
#endif

The exception is thrown more or less randomly. I tried to debug with breakpoints, but I couln’t find anything.

I have a database included for the app. So I put the database under res/data. On start I copy it to a folder where android can access it. The database reading works on both plattforms. So I can read the data from the database and I got the SQLITE_OK from Sqlite.

Informations from android studio:

NDK Version: 21.3.6528147
Android Studio: 4.1

Is the way how I copy the database on start incorrect? I really dont know what else is wrong cause on Xcode it works great without any errors.

Thank you very much.

Here the last line of the log:

1604261195.159667015 <5395> send packet: $[{"name":"com.my.game","registers":{"11":"ffffffff","13":"d0fadaff","14":"71bb76f2","15":"249d79f2"}],"tid":422}],{"name":"Jit thread pool","registers":{"11":"01000000","13":"d85c50e1","14":"3dc56ff0","15":"0cd075f2"}],"tid":428}],{"name":"Runtime worker ","registers":{"11":"01000000","13":"d8ac1cf5","14":"3dc56ff0","15":"0cd075f2"}],"tid":429}],{"name":"Runtime worker ","registers":{"11":"01000000","13":"d80c0af4","14":"3dc56ff0","15":"0cd075f2"}],"tid":430}],{"name":"Runtime worker ","registers":{"11":"01000000","13":"d8fc08f4","14":"3dc56ff0","15":"0cd075f2"}],"tid":431}],{"name":"Runtime worker ","registers":{"11":"01000000","13":"d84c40e1","14":"3dc56ff0","15":"0cd075f2"}],"tid":432}],{"name":"Signal Catcher","registers":{"11":"60a27bf2","13":"60013fe1","14":"93a976f2","15":"54a079f2"}],"tid":433}],{"name":"ADB-JDWP Connec","registers":{"11":"00000000","13":"00f02ee1","14":"df8f76f2","15":"f89e79f2"}],"tid":434}],{"name":"HeapTaskDaemon","registers":{"11":"60a27bf2","13":"7047c1c3","14":"4fc86ff0","15":"0cd075f2"}],"tid":435}],{"name":"ReferenceQueueD","registers":{"11":"01000000","13":"90b1b0c3","14":"3dc56ff0","15":"0cd075f2"}],"tid":436}],{"name":"FinalizerDaemon","registers":{"11":"01000000","13":"c01ea0c3","14":"3dc56ff0","15":"0cd075f2"}],"tid":437}],{"name":"FinalizerWatchd","registers":{"11":"60a27bf2","13":"28928fc3","14":"4fc86ff0","15":"0cd075f2"}],"tid":438}],{"name":"Binder:422_1","registers":{"11":"00000000","13":"f8306fc3","14":"c17a76f2","15":"609e79f2"}],"tid":439}],{"name":"Binder:422_2","registers":{"11":"00000000","13":"f8205fc3","14":"c17a76f2","15":"609e79f2"}],"tid":440}],{"name":"Binder:422_3","registers":{"11":"00000000","13":"f8104fc3","14":"c17a76f2","15":"609e79f2"}],"tid":445}],{"name":"Binder:422_4","registers":{"11":"00000000","13":"f8003fc3","14":"c17a76f2","15":"609e79f2"}],"tid":451}],{"name":"JDWP Transport ","registers":{"11":"18d016c3","13":"f8ce16c3","14":"1d2876f2","15":"0cd075f2"}],"tid":528}],{"name":"JDWP Event Help","registers":{"11":"005c55da","13":"40bf06c3","14":"1d2876f2","15":"0cd075f2"}],"tid":529}],{"name":"JDWP Command Re","registers":{"11":"e8b0f6c2","13":"90b0f6c2","14":"df8f76f2","15":"f89e79f2"}],"tid":530}],{"name":"Profile Saver","registers":{"11":"60a27bf2","13":"18c199c2","14":"4fc86ff0","15":"0cd075f2"}],"tid":532}],{"name":"RenderThread","registers":{"11":"ffffffff","13":"08b089c2","14":"71bb76f2","15":"249d79f2"}],"tid":533}],{"name":"magnifier pixel","registers":{"11":"ffffffff","13":"509179c2","14":"71bb76f2","15":"249d79f2"}],"tid":536}],{"description":"unknown crash reason","name":"GLThread 66806","reason":"signal","registers":{"11":"ccf468c2","13":"c0ee68c2","14":"6f2738c2","15":"d8b379f2"}],"signal":8,"tid":537}],{"name":"Studio:Agent","registers":{"11":"303278c1","13":"583178c1","14":"1d2876f2","15":"0cd075f2"}],"tid":542}],{"name":"Studio:Socket","registers":{"11":"881f68c1","13":"001f68c1","14":"039176f2","15":"489f79f2"}],"tid":543}],{"name":"AsyncTask }1","registers":{"11":"60a27bf2","13":"48f657c1","14":"59e09bf0","15":"0cd075f2"}],"tid":544}],{"name":"AsyncTask }2","registers":{"11":"60a27bf2","13":"486647c1","14":"59e09bf0","15":"0cd075f2"}],"tid":545}],{"name":"mali-mem-purge","registers":{"11":"00000000","13":"b0f136c1","14":"bb0178f2","15":"dcab79f2"}],"tid":547}],{"name":"mali-utility-wo","registers":{"11":"30e226c1","13":"68e126c1","14":"1d2876f2","15":"0cd075f2"}],"tid":548}],{"name":"mali-utility-wo","registers":{"11":"30d216c1","13":"68d116c1","14":"1d2876f2","15":"0cd075f2"}],"tid":549}],{"name":"mali-utility-wo","registers":{"11":"30c206c1","13":"68c106c1","14":"1d2876f2","15":"0cd075f2"}],"tid":550}],{"name":"mali-utility-wo","registers":{"11":"30b2f6c0","13":"68b1f6c0","14":"1d2876f2","15":"0cd075f2"}],"tid":551}],{"name":"mali-utility-wo","registers":{"11":"30a2e6c0","13":"68a1e6c0","14":"1d2876f2","15":"0cd075f2"}],"tid":552}],{"name":"mali-utility-wo","registers":{"11":"3092d6c0","13":"6891d6c0","14":"1d2876f2","15":"0cd075f2"}],"tid":553}],{"name":"mali-utility-wo","registers":{"11":"3082c6c0","13":"6881c6c0","14":"1d2876f2","15":"0cd075f2"}],"tid":554}],{"name":"mali-utility-wo","registers":{"11":"3072b6c0","13":"6871b6c0","14":"1d2876f2","15":"0cd075f2"}],"tid":555}],{"name":"mali-cmar-backe","registers":{"11":"00e5aac2","13":"5860a6c0","14":"df8f76f2","15":"f89e79f2"}],"tid":556}],{"name":"mali-hist-dump","registers":{"11":"00000000","13":"485196c0","14":"1d2876f2","15":"0cd075f2"}],"tid":557}],{"name":"hwuiTask0","registers":{"11":"30621ec0","13":"40611ec0","14":"1d2876f2","15":"0cd075f2"}],"tid":558}],{"name":"hwuiTask1","registers":{"11":"30520ec0","13":"40510ec0","14":"1d2876f2","15":"0cd075f2"}],"tid":559}],{"name":"Studio:Socket","registers":{"11":"01010000","13":"a0d0f6bf","14":"1d2876f2","15":"0cd075f2"}],"tid":560}],{"name":"Studio:Socket","registers":{"11":"01010000","13":"a0c0e6bf","14":"1d2876f2","15":"0cd075f2"}],"tid":561}],{"name":"Studio:Socket","registers":{"11":"00000000","13":"68b0d6bf","14":"1d2876f2","15":"0cd075f2"}],"tid":562}],{"name":"Thread-7","registers":{"11":"607868e1","13":"6094c6bf","14":"df8f76f2","15":"f89e79f2"}],"tid":563}],{"name":"Studio:Heartbea","registers":{"11":"bca17cbe","13":"70a07cbe","14":"bb0178f2","15":"dcab79f2"}],"tid":564}],{"name":"Studio:Socket","registers":{"11":"ffffff7f","13":"70202bbe","14":"1d2876f2","15":"0cd075f2"}],"tid":569}]]#93

Here the full gdb-log:

log.txt.zip (76.7 KB)

Are you not even able to link a debugger to it before it crashes?

I can set breakpoints and step through the code via “Step over”, “Step in” or jumping to the next breakpoints, from my point of understanding, the debugger is then linked right? The exception is thrown before any rendering is happening. Before that I read the mentioned database above, make some data calculation and assign the those more or less to objects.

What could be the reason for a crash like that? A memory issue or more database related?

Thanks again for your help #R101

You generally have two options: you can attach a debugger to an already running app, or you can start the executable with a debugger, so it hooks in before the app starts.

Whether it’s rendering or not is irrelevant, since you won’t even be looking at the app window at all, and your only concern is to step through the code around the area where you think it’s crashing. Put a breakpoint on a line of code before the crash happens, and if you’re not sure where, then just put a breakpoint at the first line you know that shouldn’t crash, which in your case would be register_all_packages();. Step from there, and you’re bound to find out precisely what is causing the crash.

Yeah. I think I have to break the code which seems to throw the exception piece by piece. I already tried it with your method of going through the code by using step over or step in. The only weird thing is that when I use those method it seems not to be thrown. But as far as I not use step in at some point and use step over it throwed. I think I have to comment out code to find the bug. I just thought maybe the exception indicates to a obvious issue.

I hope I find the problem and if so I’ll write the answer here in the topic

Given that it’s working when you step line by line, are you by any chance using threads anywhere in your code? In DatabaseReader perhaps? If so, that’s most likely to be the cause of your problems, especially if you call cocos2d-x code from a different thread.

No I don’t use threads at all. I use sqlite3pp for a nicer way to interact with SQLite, which does not use any multithreading as I can see, and the normal sqlite.c. All the other code which is written by me is not using any threading. I’ll check what cause this problem.

Does this indicate that I have Multithreading somewhere running?

Ok. I think it has something to do with my SQlite interactions. I comment out some code and now it works. I’ll have a look what happend here.

Using the same SQLite DB instance from different threads may also be a problem, especially if you’re writing data. If you access SQLite from any callbacks (like button presses etc), just check which thread they’re running on.

I can’t think of anything other reason you would be having issues besides threads at the moment.

I use SQLiteCpp and SQLite quite extensively, and I haven’t encountered any issues with it as of yet.

Ok that sounds very promising to debug into SQlite. I come across your SQlite library. I’m using this one sqlite3cpp. I find this way of querying super useful which choose me sqlite3cpp over SQLiteCpp

for (sqlite3pp::query::iterator i = qry.begin(); i != qry.end(); ++i) {
  string name, phone;
  (*i).getter() >> sqlite3pp::ignore >> name >> phone;
  cout << "\t" << name << "\t" << phone << endl;
}

Anyway maybe sqlite3cpp is having issues which leads to the exception. The functions for building the data classes, which I was talking above looks like this:

sqlite3pp::database DatabaseReader::getDatabase(){

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
    const std::string dbPath = FileUtils::getInstance()->getWritablePath() + "mydatabase.db";
#else
    const std::string dbPath = FileUtils::getInstance()->fullPathForFilename("mydatabase.db");
#endif
    
    sqlite3pp::database db(dbPath.c_str());
    return db;
    
}

MyTableDataHolder DatabaseReader::get(int index){
    
    auto db = this->getDatabase();
    
    std::ostringstream ss;
    ss << "SELECT * FROM my_table WHERE id=";
    ss << index;
    
    sqlite3pp::query qry(db, ss.str().c_str());

...

They where called multiple times during a for loop but never in a thread. The database is also closed after the function ends in case that there is something wrong.

Anyway maybe there is something wrong in the library. I would like to use your library suggestion cause it looks also more supported.

How exactly do I link it with CMake? I copied SQliteCpp in my cocos2d/external folder. Do I have to link it now like this in the CMakeLists?

...

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cocos2d/external/SQLiteCpp)

include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/cocos2d/external/SQLiteCpp/include
)

target_link_libraries(SQLiteCpp
        sqlite3
        pthread
        dl
        )

# add cross-platforms source files and header files

Sorry this question seems maybe simple for you but I’m not that familiar with CMake and I couldn’t find any documentation from a quick search. For me cocos2dx seems kind of magic in terms of the CMake stuff :sweat_smile: The Box2D library for example is not listed anywhere in the CMake but seems to work or do I have to link it also in CMake?

Thanks again for your help. I think the CMake question for the new SQlite library is still related to the topic therefore I’m not creating a new topic

This is as good a time as any to dig into CMake and at least figure out enough about it to do what you need.

You have two options when it comes to SQLiteCpp. One is that you use the SQLite that comes with it, and the other is that you provide your own version of SQLite, and ensure that SQLiteCpp is linked against it. I personally went with the latter option, so the CMake snippets below reflect that.

At the top of your CMakeLists.txt, just before the include(CocosBuildSet) line, add this to disable the cocos2d-x built-in SQLite:

set(BUILD_EXT_SQLITE OFF CACHE BOOL "Build with internal SQLite support" FORCE)

Now scroll down a bit in the file, and you’ll see something similar to this:

target_link_libraries(${APP_NAME} PRIVATE cocos2d)
target_include_directories(${APP_NAME}
    PRIVATE Classes
    PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/
)

Note that I changed the cocos2d library to be linked as PRIVATE, and you will need to make sure you use a keyword (PUBLIC, PRIVATE or INTERFACE) for any other target_link_libraries that link to ${APP_NAME}:

# Updated version of SQLite3 (must disable it in the Cocos2d-x cmake scripts first...)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/sqlite3 ${PROJECT_BINARY_DIR}/sqlite3)
get_target_property(SQLITE3_INCLUDE_DIRS sqlite3 INTERFACE_INCLUDE_DIRECTORIES)
# Set a few SQLite options
target_compile_definitions(sqlite3
	PUBLIC SQLITE_ENABLE_COLUMN_METADATA 
	PUBLIC SQLITE_HAS_CODEC SQLITE_TEMP_STORE=2 
)
target_include_directories(${APP_NAME}
	PRIVATE ${SQLITE3_INCLUDE_DIRS}
)

# SQLiteCpp
#set(SQLITE_USE_LEGACY_STRUCT ON CACHE BOOL "Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)" FORCE)
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "Add the internal SQLite3 source to the project." FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/SQLiteCpp ${PROJECT_BINARY_DIR}/SQLiteCpp)
target_include_directories(SQLiteCpp PRIVATE ${SQLITE3_INCLUDE_DIRS})
target_include_directories(cocos2d PRIVATE ${SQLITE3_INCLUDE_DIRS}) #cocos2d lib needs the path too
target_compile_definitions(SQLiteCpp PUBLIC SQLITE_HAS_CODEC)
get_target_property(SQLiteCpp_INCLUDE_DIRS SQLiteCpp INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${APP_NAME}
	PRIVATE ${SQLiteCpp_INCLUDE_DIRS}
)

# The order that these are linked is important
target_link_libraries(${APP_NAME} PRIVATE SQLiteCpp)
target_link_libraries(${APP_NAME} PRIVATE sqlite3)

The SQLite and SQLiteCpp folders are located in [projectname]/external/, for example:
image

SQLite has its own CMakeLists.txt as well:
image

and it contains this:

add_library(sqlite3 STATIC
   sqlite3.c
   sqlite3.h
)
target_include_directories(sqlite3 PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")

if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
    set_target_properties(sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC")
endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))

If you’re not sure what all of this means, or you want specific help with the CMake, then there is plenty of information on the web about it.

1 Like

That sounds great! Thanks for your answer. I will try your code later the day with the codes changes reflrecting to the new library. Just one question. What does it mean or why do you need to link cocos2d as private?

The change was specific for my project, and there is no reason you can’t change it to PUBLIC. The only reason I mentioned it is that once you add a specific keyword (PUBLIC/PRIVATE/INTERFACE), then you need to use a keyword for any future library links (you can’t leave it blank).

For instance, if you have this (the default):
target_link_libraries(${APP_NAME} cocos2d)

Then you can’t use a keyword when you link another library, for example:
target_link_libraries(${APP_NAME} PRIVATE SQLiteCpp)

The only way it will work is if you do this (without the keyword):
target_link_libraries(${APP_NAME} SQLiteCpp)

In this case, since no keyword is used, CMake will decide whether it’s treated as PUBLIC or PRIVATE, based on many factors. If you want to know more about this, then the CMake documentaion may help, and this post will also explain things a lot better than I have.

I understand. Yeah I think I have to digg more into CMake. It seems really like a more or less big questionmark for me. I tried your code and it always says:

Could not find Sqlite3
Call Stack (most recent call first):
external/SQLiteCpp/CMakeLists.txt:235 (find_package)

But the structure of the folders should be fine. Also your code which I inserted. I read through the repo from SqliteCpp and copy their CMake suggestion for my CMake like so:

target_link_libraries(${APP_NAME} cocos2d)
target_include_directories(${APP_NAME}
        PRIVATE Classes
        PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/
)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/SQLiteCpp)

include_directories(
        ${CMAKE_CURRENT_LIST_DIR}/external/SQLiteCpp/include
)

target_link_libraries(${APP_NAME} SQLiteCpp)
target_link_libraries(${APP_NAME} sqlite3)

Or in their example (of course I changed the directories here):

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Add SQLite3 C++ wrapper around sqlite3 library (and sqlite3 itself provided for ease of use)
# Here you can set CMake variables to avoid building Example, as well as cpplint, cppcheck...
# or set them in the cmake command line (see for instance provided build.bat/build.sh scripts)

set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "" FORCE)
set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "" FORCE)
add_subdirectory(SQLiteCpp)

# Add main.cpp example source code to the executable
add_executable(SQLiteCpp_Example src/main.cpp)

# Link SQLiteCpp_example1 with SQLiteCpp
target_link_libraries(SQLiteCpp_Example SQLiteCpp)

But I always get:

Could not find Sqlite3
Call Stack (most recent call first):
external/SQLiteCpp/CMakeLists.txt:235 (find_package)

Is there a cache or what am I doing wrong here?

I just updated to the latest SQLiteCpp, and I’m seeing the same error now. I’ll take a quick look at it to find out why it’s happening.

Replace the SQLiteCpp CMakeLists.txt file with the one attached to this post, and it should work. The current script assumes that if it isn’t using the sqlite3 supplied with SQLiteCpp, then it will be using one installed somewhere on the system, and it’s stopping you from linking your own version.

The only change is that lines 234->279 have been commented out, so compare it with the one from the SQLiteCpp github repo to see exactly what the differences are.

SQLiteCpp_CMakeLists.zip (5.5 KB)

There may be another way to fix it, but for the time being, this works.

Unfortunately I can’t get it to run. I tried different modifications including the example from them but nothing seems to work. I think I understand it now better but it doesn’t make sense why its not working.

I insert your snippet and double checked everything but I got this build error:

 In file included from ../../../../../../external/SQLiteCpp/src/Database.cpp:18:
  ../../../../../../external/sqlite3/sqlite3.h:4244:16: error: typedef 'sqlite3_value' cannot be referenced with a struct specifier
  typedef struct sqlite3_value sqlite3_value;
                 ^
  ../../../../../../external/SQLiteCpp/include/SQLiteCpp/Database.h:25:20: note: declared here
  typedef struct Mem sqlite3_value;
                     ^
  ../../../../../../external/SQLiteCpp/src/Database.cpp:225:25: error: use of undeclared identifier 'sqlite3_key'
          const int ret = sqlite3_key(getHandle(), aKey.c_str(), passLen);
                          ^
  ../../../../../../external/SQLiteCpp/src/Database.cpp:243:25: error: use of undeclared identifier 'sqlite3_rekey'; did you mean 'sqlite3_trace'?
          const int ret = sqlite3_rekey(getHandle(), aNewKey.c_str(), passLen);
                          ^~~~~~~~~~~~~
                          sqlite3_trace
  ../../../../../../external/sqlite3/sqlite3.h:3139:36: note: 'sqlite3_trace' declared here
  SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
                                     ^
  ../../../../../../external/SQLiteCpp/src/Database.cpp:243:52: error: cannot initialize a parameter of type 'void (*)(void *, const char *)' with an rvalue of type 'const std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >::value_type *' (aka 'const char *')
          const int ret = sqlite3_rekey(getHandle(), aNewKey.c_str(), passLen);
                                                     ^~~~~~~~~~~~~~~
  ../../../../../../external/sqlite3/sqlite3.h:3140:10: note: passing argument to parameter 'xTrace' here
     void(*xTrace)(void*,const char*), void*);
           ^
  ../../../../../../external/SQLiteCpp/src/Database.cpp:248:25: error: use of undeclared identifier 'sqlite3_rekey'; did you mean 'sqlite3_trace'?
          const int ret = sqlite3_rekey(getHandle(), nullptr, 0);
                          ^~~~~~~~~~~~~
                          sqlite3_trace
  ../../../../../../external/sqlite3/sqlite3.h:3139:36: note: 'sqlite3_trace' declared here
  SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
                                     ^
  ../../../../../../external/SQLiteCpp/src/Database.cpp:248:19: error: cannot initialize a variable of type 'const int' with an rvalue of type 'void *'
          const int ret = sqlite3_rekey(getHandle(), nullptr, 0);
                    ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6 errors generated.
  [295/671] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/__/extensions/Particle3D/PU/CCPUBehaviourTranslator.cpp.o
  [296/671] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/storage/local-storage/LocalStorage-android.cpp.o
  [297/671] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/__/extensions/Particle3D/PU/CCPUSlaveBehaviour.cpp.o
  [298/671] Building CXX object SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Column.cpp.o
  [299/671] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/__/extensions/Particle3D/PU/CCPUSlaveBehaviourTranslator.cpp.o
  ninja: build stopped: subcommand failed.

And before that on off the first times I got like a endless loop here:

 [0/1] Re-running CMake...
  -- using toolchain file:/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/build/cmake/android.toolchain.cmake
  -- PROJECT_NAME:MyGame
  -- PROJECT_SOURCE_DIR:/Users/yeti/Development/Cocos2dx/mygame/MyGame
  -- COCOS2DX_ROOT_PATH:/Users/yeti/Development/Cocos2dx/mygame/MyGame/cocos2d
  -- CMAKE_MODULE_PATH:/Users/yeti/Development/Cocos2dx/mygame/MyGame/cocos2d/cmake/Modules/
  -- PROJECT_BINARY_DIR:/Users/yeti/Development/Cocos2dx/mygame/MyGame/proj.android/app/.externalNativeBuild/cmake/debug/armeabi-v7a
  -- ENGINE_BINARY_PATH:/Users/yeti/Development/Cocos2dx/mygame/MyGame/proj.android/app/.externalNativeBuild/cmake/debug/armeabi-v7a/engine
  -- CMAKE_GENERATOR: Ninja
  -- CMAKE_BUILD_TYPE: Debug
  -- Using c++ standard c++11
  -- CMake version: 3.10.2
  -- Project version: 3.1.1
  -- Using Stack Protection hardening
  -- CMAKE_CXX_COMPILER '/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++' 'Clang' '9.0'
  -- CMAKE_CXX_FLAGS                '-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -frtti -fexceptions -fsigned-char -Wall -Wextra -Wpedantic -Wswitch-enum -Wshadow -Wno-long-long'
  -- CMAKE_CXX_FLAGS_DEBUG          '-O0 -fno-limit-debug-info '
  -- SQLITECPP_RUN_CPPLINT OFF
  -- SQLITECPP_RUN_CPPCHECK OFF
  -- SQLITECPP_RUN_DOXYGEN OFF
  -- SQLITECPP_BUILD_EXAMPLES OFF
  -- SQLITECPP_BUILD_TESTS OFF
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /Users/yeti/Development/Cocos2dx/mygame/MyGame/proj.android/app/.externalNativeBuild/cmake/debug/armeabi-v7a
  [0/1] Re-running CMake...
  -- using toolchain file:/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/build/cmake/android.toolchain.cmake
  -- PROJECT_NAME:MyGame
  -- PROJECT_SOURCE_DIR:/Users/yeti/Development/Cocos2dx/mygame/MyGame
  -- COCOS2DX_ROOT_PATH:/Users/yeti/Development/Cocos2dx/mygame/MyGame/cocos2d
  -- CMAKE_MODULE_PATH:/Users/yeti/Development/Cocos2dx/mygame/MyGame/cocos2d/cmake/Modules/
  -- PROJECT_BINARY_DIR:/Users/yeti/Development/Cocos2dx/mygame/MyGame/proj.android/app/.externalNativeBuild/cmake/debug/armeabi-v7a
  -- ENGINE_BINARY_PATH:/Users/yeti/Development/Cocos2dx/mygame/MyGame/proj.android/app/.externalNativeBuild/cmake/debug/armeabi-v7a/engine
  -- CMAKE_GENERATOR: Ninja
  -- CMAKE_BUILD_TYPE: Debug
  -- Using c++ standard c++11
  -- CMake version: 3.10.2
  -- Project version: 3.1.1
  -- Using Stack Protection hardening
  -- CMAKE_CXX_COMPILER '/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++' 'Clang' '9.0'
  -- CMAKE_CXX_FLAGS                '-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -frtti -fexceptions -fsigned-char -Wall -Wextra -Wpedantic -Wswitch-enum -Wshadow -Wno-long-long'
  -- CMAKE_CXX_FLAGS_DEBUG          '-O0 -fno-limit-debug-info '
  -- SQLITECPP_RUN_CPPLINT OFF
  -- SQLITECPP_RUN_CPPCHECK OFF
  -- SQLITECPP_RUN_DOXYGEN OFF
  -- SQLITECPP_BUILD_EXAMPLES OFF
  -- SQLITECPP_BUILD_TESTS OFF
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /Users/yeti/Development/Cocos2dx/mygame/MyGame/proj.android/app/.externalNativeBuild/cmake/debug/armeabi-v7a
  ninja: error: manifest 'build.ninja' still dirty after 100 tries

I also had a sqlite.h not found error

I uploaded my external.zip and this is my CMake:

# Updated version of SQLite3 (must disable it in the Cocos2d-x cmake scripts first...)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/sqlite3 ${PROJECT_BINARY_DIR}/sqlite3)
get_target_property(SQLITE3_INCLUDE_DIRS sqlite3 INTERFACE_INCLUDE_DIRECTORIES)
# Set a few SQLite options
target_compile_definitions(sqlite3
        PUBLIC SQLITE_ENABLE_COLUMN_METADATA
        PUBLIC SQLITE_HAS_CODEC SQLITE_TEMP_STORE=2
        )
target_include_directories(${APP_NAME}
        PRIVATE ${SQLITE3_INCLUDE_DIRS}
        )

# SQLiteCpp
#set(SQLITE_USE_LEGACY_STRUCT ON CACHE BOOL "Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)" FORCE)
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "Add the internal SQLite3 source to the project." FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/SQLiteCpp ${PROJECT_BINARY_DIR}/SQLiteCpp)
target_include_directories(SQLiteCpp PRIVATE ${SQLITE3_INCLUDE_DIRS})
target_include_directories(cocos2d PRIVATE ${SQLITE3_INCLUDE_DIRS}) #cocos2d lib needs the path too
target_compile_definitions(SQLiteCpp PUBLIC SQLITE_HAS_CODEC)
get_target_property(SQLiteCpp_INCLUDE_DIRS SQLiteCpp INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${APP_NAME}
        PRIVATE ${SQLiteCpp_INCLUDE_DIRS}
        )

# The order that these are linked is important
target_link_libraries(${APP_NAME} SQLiteCpp)
target_link_libraries(${APP_NAME} sqlite3)

Could you maybe take a look whats wrong? I also tried this without success:

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/SQLiteCpp)

include_directories(
${CMAKE_CURRENT_LIST_DIR}/external/SQLiteCpp/include
)

target_link_libraries(${APP_NAME} SQLiteCpp)
target_link_libraries(${APP_NAME} sqlite3)

external.zip (4.5 MB)

Sorry, that’s my mistake. I use a version of SQLite that has encryption enabled (the SQLITE_HAS_CODEC flag).

In your project CMakeLists.txt, replace this:

target_compile_definitions(sqlite3
        PUBLIC SQLITE_ENABLE_COLUMN_METADATA
        PUBLIC SQLITE_HAS_CODEC SQLITE_TEMP_STORE=2
        )

with this:

target_compile_definitions(sqlite3
        PUBLIC SQLITE_ENABLE_COLUMN_METADATA
        PUBLIC SQLITE_TEMP_STORE=2
        )

and also delete this line:
target_compile_definitions(SQLiteCpp PUBLIC SQLITE_HAS_CODEC)

I tested the source code in the zip file you attached to your post after making these 2 changes, and it compiled successfully.

I still cant get it to run… even when I use the set(SQLITECPP_INTERNAL_SQLITE ON “Add the internal SQLite3 source to the project.” FORCE) I get

-D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -frtti -fexceptions -fsigned-char -Wall -Wextra -Wpedantic -Wswitch-enum -Wshadow -Wno-long-long -O0 -fno-limit-debug-info  -fPIC   -fPIC -fstack-protector -std=gnu++11 -MD -MT external/SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o -MF external/SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o.d -o external/SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o -c ../../../../../../external/SQLiteCpp/src/Database.cpp
  ../../../../../../external/SQLiteCpp/src/Database.cpp:18:10: fatal error: 'sqlite3.h' file not found
  #include <sqlite3.h>
           ^~~~~~~~~~~
  1 error generated.

And with this:

# Updated version of SQLite3 (must disable it in the Cocos2d-x cmake scripts first...)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/sqlite3)
get_target_property(SQLITE3_INCLUDE_DIRS sqlite3 INTERFACE_INCLUDE_DIRECTORIES)
# Set a few SQLite options
target_compile_definitions(sqlite3
        PUBLIC SQLITE_ENABLE_COLUMN_METADATA
        PUBLIC SQLITE_TEMP_STORE=2
        )
target_include_directories(${APP_NAME}
        PRIVATE ${SQLITE3_INCLUDE_DIRS}
        )

# SQLiteCpp
#set(SQLITE_USE_LEGACY_STRUCT ON CACHE BOOL "Fallback to forward declaration of legacy struct sqlite3_value (pre SQLite 3.19)" FORCE)
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "Add the internal SQLite3 source to the project." FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/SQLiteCpp ${PROJECT_BINARY_DIR}/SQLiteCpp)
target_include_directories(SQLiteCpp PRIVATE ${SQLITE3_INCLUDE_DIRS})
target_include_directories(cocos2d PRIVATE ${SQLITE3_INCLUDE_DIRS}) #cocos2d lib needs the path too
get_target_property(SQLiteCpp_INCLUDE_DIRS SQLiteCpp INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${APP_NAME}
        PRIVATE ${SQLiteCpp_INCLUDE_DIRS}
        )

# The order that these are linked is important
target_link_libraries(${APP_NAME} SQLiteCpp)
target_link_libraries(${APP_NAME} sqlite3)

I got:

/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot  -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_USE_LEGACY_STRUCT -I../../../../../../external/SQLiteCpp/include -I../../../../../../external/sqlite3 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -frtti -fexceptions -fsigned-char -Wall -Wextra -Wpedantic -Wswitch-enum -Wshadow -Wno-long-long -O0 -fno-limit-debug-info  -fPIC   -fPIC -fstack-protector -std=gnu++11 -MD -MT SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Backup.cpp.o -MF SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Backup.cpp.o.d -o SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Backup.cpp.o -c ../../../../../../external/SQLiteCpp/src/Backup.cpp
In file included from ../../../../../../external/SQLiteCpp/src/Backup.cpp:16:
../../../../../../external/sqlite3/sqlite3.h:4244:16: error: typedef 'sqlite3_value' cannot be referenced with a struct specifier
typedef struct sqlite3_value sqlite3_value;
               ^
../../../../../../external/SQLiteCpp/include/SQLiteCpp/Database.h:25:20: note: declared here
typedef struct Mem sqlite3_value;
                   ^
1 error generated.
[255/271] Building CXX object SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o
FAILED: SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o 
/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/yeti/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot  -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_USE_LEGACY_STRUCT -I../../../../../../external/SQLiteCpp/include -I../../../../../../external/sqlite3 -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -frtti -fexceptions -fsigned-char -Wall -Wextra -Wpedantic -Wswitch-enum -Wshadow -Wno-long-long -O0 -fno-limit-debug-info  -fPIC   -fPIC -fstack-protector -std=gnu++11 -MD -MT SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o -MF SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o.d -o SQLiteCpp/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o -c ../../../../../../external/SQLiteCpp/src/Database.cpp
In file included from ../../../../../../external/SQLiteCpp/src/Database.cpp:18:
../../../../../../external/sqlite3/sqlite3.h:4244:16: error: typedef 'sqlite3_value' cannot be referenced with a struct specifier
typedef struct sqlite3_value sqlite3_value;
               ^
../../../../../../external/SQLiteCpp/include/SQLiteCpp/Database.h:25:20: note: declared here
typedef struct Mem sqlite3_value;
                   ^
1 error generated.

Seems maybe a problem on my local machine? Man I thought I understand now the CMake file…