我下载了最新版本的Cocos2dx(v3.4)。我之前为Sqlite编写了一个包装器,我想在我的新项目中使用它。但是当我添加与项目目录不同的目录中的文件时,我不能在EasySqlite.h文件中包含sqlite3.h。编译器提供C:\Users\**\Desktop\**Project\Utilities\Backend\EasySqlite.h:3: error: C1083: Cannot open include file: 'sqlite3.h': No such file or directory
这是我的CMakeLists.txt文件的一部分:
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()
当我提供像#include "C:\Users\..\..\sqlite3.h"
这样的sqlite3.h文件的完整路径时,我会收到链接器错误。
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)
当我移动上面提到的文件并将它们移动到cocos2dx项目中的Classes目录时,即使我在AppDelegate.h文件中包含sqlite3.h文件,我仍然不能将它包含在EasySqlite.h中
是否应该将sqlite与Cocos2dx链接?
答案 0 :(得分:0)
谢谢@chale-cs,但我确实找到了解决方案。我没有尝试使用Cococs2dx v3.4附带的sqlite库,我从官方网站下载了sqlite3。我编译并创建了一个.lib文件,然后在PROJECT/CMakeLists.txt
中添加了一个子目录,并将.lib文件链接到项目。
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"
)