Since the content we are introducing is based on the WIN32 platform developed under Microsoft Visual Studio, below we describe the settings for the SQLite database development environment under Visual Studio. Specifically, there are two ways in which you can use the SQLite database in Visual Studio: using SQLite source code files and using the library files provided by Cocos2d-x.
1. Using SQLite source code files
SQLite is an open source database written by C, which we can http://www.sqlite.org/ download.html URL Download the latest SQLite source code, such as I downloaded the Sqlite-amalgamation-3080401.zip file, unzip the file after the content includes: SHELL.C, SQLITE3.C, Sqlite3.h and Sqlite3ext.h. We generally only need to sqlite3.c and sqlite3.h two files on it.
We need to add these two files to the project, the process is to copy them to the project classes directory, open the solution, right click on the HelloWorld project classes directory, in the right-click menu, select "Add" → "existing Item". Then, in the Pop-up dialog box, select the Sqlite3.c and sqlite3.h files to add to the project.
Add sqlite3.c and Sqlite3.h files to the project
2. Using library files provided by cocos2d-x
Since the Cocos2d-x engine already has the library required to access SQLite for Win32, the SQLite library file in Cocos2d-x 3.x is located in the < Engineering catalog >\cocos2d\external\sqlite3\ In the Libraries\win32 directory, the header file is in the < catalog >\cocos2d\external\sqlite3\include directory. We can use it directly.
The advantage of this approach is that you can directly use the Cocos2d-x engine to compile library files for developers, and version compatibility is good. The disadvantage is that the configuration development environment is cumbersome and Win32 library files are not available when porting to other platforms, and we need to reconfigure the environment. Let's look at this in more detail here.
First, we need to configure the header file search path, select the HelloWorld Project, open the menu "project" → "properties" pop-up project Properties dialog box, as shown, select "Configuration Properties" → "C + +" → "General", in the right "additional Include directory" add $ (engineroot) External\sqlite3\include, note that you need to separate the configuration items with semicolons.
Configure header File Search path
Next we also need to configure the SQLite3 library file to the linked environment, select "Configuration Properties" → "linker" → "input", as shown, add $ $ (engineroot) to the right "additional dependencies" external\sqlite3\libraries\ Win32\sqlite3.lib, note that you need to separate the configuration items with semicolons.
Configuring the linked environment
Next we need to copy the SQLite3 library files to the running environment, the simplest way is to manually < the project catalog >\cocos2d\external\sqlite3\libraries\ The Sqlite3.dll and Sqlite3.lib files in the Win32 directory are copied to the directory where the executable is located, such as the:< project directory >\proj.win32\debug.win32 directory. Then, compile the project, but if we clear the Debug.win32 directory, the two files will be lost. To prevent this, we can set the compile event when the project is compiled, and we can define the copy process in this event. Open the Project Properties dialog box, as shown in, select "Configuration Properties" → "generate events" → "Pre-link Events" to modify the "command line" in the right window, with the following contents:
If not exist "$ (OutDir)" mkdir "$ (OutDir)"
xcopy/y/q "$ (engineroot) external\websockets\prebuilt\win32\*.*" "$ (OutDir)"
xcopy/y/q "$ (engineroot) external\sqlite3\libraries\win32\*.*" "$ (OutDir)"
One of the following is our addition, the original project template only set the copy WebSockets. This will copy all the files under the $ (engineroot) external\sqlite3\libraries\win32\ directory to the output directory when we compile the project, where $ (ENGINEROOT) macro represents the < Engineering catalog >\ The cocos2d\ directory, the $ (OUTDIR) macro is the executable file's build directory, which represents the < catalog >\proj.win32\debug.win32 directory.
Configuring compilation Events
Let's try compiling the project or rebuilding the solution to see if the library files Sqlite3.dll and Sqlite3.lib files are included in the executable's build directory.
For more information, please pay attention to the first Cocos2d-x 3.2 Edition book "Cocos2d-x: C + + volume" book Exchange Discussion website: http://www.cocoagame.net
For more exciting video courses, please follow the Cocos class: Http://v.51work6.com Welcome to join the COCOS2D-X Technical Discussion group: 257760386 Welcome to the Luxgen iOS classroom public Platform
Visual Studio SQLite database development environment settings