如何在VS2017 C++项目目录中添加sqlite3.h、sqlite3.dll并解决E1696错误
Hey there! Let's walk through how to properly add SQLite3 to your Visual Studio 2017 C++ project and fix that annoying E1696 "cannot open source file 'sqlite3.h'" error. Here's a step-by-step breakdown:
First, you'll need three key files for SQLite3 integration:
sqlite3.h: The header file that defines SQLite's APIsqlite3.lib: The import library needed for linking your project to the dynamic librarysqlite3.dll: The dynamic link library your program will load at runtime
You can get these from SQLite's official precompiled binaries page—just pick the package matching your project's architecture (32-bit or 64-bit).
Keeping your project tidy will save you headaches later:
- Create a subfolder in your project root (e.g.,
libs/sqlite) to store all SQLite files - Copy
sqlite3.h,sqlite3.lib, andsqlite3.dllinto this new folder
This is where we fix the E1696 error and set up proper linking. Open your project's properties by right-clicking the project in Solution Explorer and selecting Properties.
3.1 Tell Visual Studio Where to Find sqlite3.h
- Navigate to
Configuration Properties > C/C++ > General - Find the
Additional Include Directoriesfield, click the dropdown, and select<Edit...> - Add the path to your SQLite folder (e.g.,
$(ProjectDir)libs/sqlite—the$(ProjectDir)variable automatically points to your project's root directory) - Click OK to save this setting
3.2 Add the Library Directory for sqlite3.lib
- Stay in the Properties window, go to
Configuration Properties > Linker > General - In
Additional Library Directories, add the same path to your SQLite folder (e.g.,$(ProjectDir)libs/sqlite) - Save the change
3.3 Link Against sqlite3.lib
- Go to
Configuration Properties > Linker > Input - In the
Additional Dependenciesfield, addsqlite3.lib - Click OK to apply all project settings
sqlite3.dll is Available at Runtime Since we're using a dynamic library, your program needs to find sqlite3.dll when it runs:
- Manually copy
sqlite3.dllinto your project's output directory (e.g.,x64/Debugorx86/Release—this is where your compiled.exelives) - Or set up a post-build event to automate this:
- Go to
Configuration Properties > Build Events > Post-Build Event - In the
Command Linebox, paste:copy "$(ProjectDir)libs/sqlite/sqlite3.dll" "$(OutDir)" - Now the DLL will copy automatically every time you build your project
- Go to
If you still see the error after following the steps:
- Double-check the path in
Additional Include Directories—typos or wrong relative paths are common culprits - Ensure you've edited the settings for the correct configuration (Debug vs Release, x86 vs x64)—settings are per-configuration!
- Verify that
sqlite3.his actually present in the folder you specified - Try closing and reopening Visual Studio—sometimes the IDE needs a refresh to pick up new settings
内容的提问来源于stack exchange,提问作者hannu

