0

I downloaded the latest version of Cocos2dx (v3.4). I previously wrote a wrapper for Sqlite and I want to use that in my new project. But When I add the files, which are in a different directory than the project directory, I cannot include sqlite3.h in EasySqlite.h file. Compiler gives C:\Users\**\Desktop\**Project\Utilities\Backend\EasySqlite.h:3: error: C1083: Cannot open include file: 'sqlite3.h': No such file or directory

Here's part of my CMakeLists.txt file:

set(UTILITIES_SRC
    ../../Utilities/Backend/CommonVariables.cpp
    ../../Utilities/Backend/EasySqlite.cpp
    ../../Utilities/Backend/GameRecordManager.cpp
    ../../Utilities/Backend/ResourcesDatabaseManager.cpp
    ../../Utilities/Backend/Statistics.cpp
    ../../Utilities/Backend/StudentManager.cpp
   ../../Utilities/Backend/Toolbox.cpp
)

set(UTILITIES_HEADERS
    ../../Utilities/Backend/CommonVariables.h
    ../../Utilities/Backend/EasySqlite.h
    ../../Utilities/Backend/GameRecordManager.h
    ../../Utilities/Backend/ResourcesDatabaseManager.h
    ../../Utilities/Backend/Statistics.h
    ../../Utilities/Backend/StudentManager.h
    ../../Utilities/Backend/Toolbox.h
)

set(GAME_SRC
  Classes/AppDelegate.cpp
  Classes/TitleScreen.cpp
  Classes/SplashScreen.cpp
  Classes/Cocos2dxUtils.cpp
  ${PLATFORM_SPECIFIC_SRC}
  ${UTILITIES_SRC}
)

set(GAME_HEADERS
  Classes/AppDelegate.h
  Classes/TitleScreen.h
  Classes/SplashScreen.h
  Classes/Cocos2dxUtils.h
  ${PLATFORM_SPECIFIC_HEADERS}
  ${UTILITIES_HEADERS}
)

if(GAME_HEADERS)
    add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS})
else()
    add_executable(${APP_NAME} ${GAME_SRC})
endif()

When I give the full path to the sqlite3.h file like #include "C:\Users\..\..\sqlite3.h" I get linker errors.

EasySqlite.cpp.obj:-1: error: LNK2019: unresolved external symbol _sqlite3_close referenced in function "public: struct std::pair<struct sqlite3 *,int> __thiscall EasySqlite::openDatabase(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (?openDatabase@EasySqlite@@QAE?AU?$pair@PAUsqlite3@@H@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@_N@Z)

When I move the mentioned files above and move them to the Classes directory in the cocos2dx project, even though I ca include sqlite3.h file in, say, AppDelegate.h file I still cannot include it in EasySqlite.h

Is'nt sqlite supposed to be linked with Cocos2dx already?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Furkanzmc
  • 104
  • 3
  • 13
  • Easy step-by-step tutorial found here: [link](http://discuss.cocos2d-x.org/t/a-simple-tutorial-how-to-use-sqlite-in-cocos2d-x-tutorial-by-yuye/10677) – Chale CS Feb 03 '15 at 16:30

1 Answers1

0

Thanks @chale-cs but I did found the solution. I didn't try this with the sqlite library that comes with Cococs2dx v3.4, I downloaded sqlite3 from the official web site. I compiled and created a .lib file and then added a sub directory in PROJECT/CMakeLists.txt and I linked the .lib file to the project.

PROJECT/CMakeLists.txt:

add_subdirectory(../../Utilities/sqlite3_custom ${APP_NAME})
target_link_libraries(${APP_NAME} cocos2d sqlite3_custom)

sqlite3_custom/CMakeLists.txt:

set(SQLITE_CUSTOM_SRC
    shell.c
    sqlite3.c
)

add_library(sqlite3_custom STATIC
  ${SQLITE_CUSTOM_SRC}
)

set_target_properties(sqlite3_custom
    PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
Furkanzmc
  • 104
  • 3
  • 13