3

I'm doing a job that needs linking Sqlite with C++, but I've encountered some troubles doing this.

I've searched many courses already. I've added all the files more than needed sqlite3.dll,sqlite3.def,sqlite3.h.sqlite3.exe,sqlite3.lib

into the project folder but I still failed to do it right.

enter image description here

enter image description here

the result of compiling main.cpp

enter image description here

include "sqlite3.h"

Community
  • 1
  • 1
Ke Chen
  • 31
  • 1
  • 3
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Alan Birtles Jul 05 '19 at 05:57

1 Answers1

1

You just have to 1) add the .h header file to your include path 2) add the .lib library file to your libraries path 3) add a static link to the .lib file in your project properties (both debug and release builds) 4) remove all other references (def, dll, exe) from the project 5) make sure the .dll file is in the same directory as your .exe

  • How to take step 3 in detail?I have no idea.And for the step 5,which directory the .dll file and .exe file should be in? – Ke Chen Jul 05 '19 at 05:37
  • I haven't used the Code edition of VS per se but the main principles should be pretty much the same to standard VS. However, looking around I found enough questions like this in the site that have not been answered. For step 3 you can try entering the line #pragma comment(lib, "sqlite3.lib") after the includes section in your code of main.cpp. For step 5 you should either add sqlite3.dll to a directory in your path or in the Debug and Release output directories of your project. You should also remember to deploy the .dll file together with your .exe. – Manos Anastasiadis Jul 05 '19 at 06:08
  • You can also refer to the first answer in https://stackoverflow.com/questions/38404670/how-do-i-link-the-sfml-libraries-in-visual-studio-code. You can try adding a "-lsqlite3", (including the comma after the quote) line in the end of your "args" section found inside the "tasks" section of your project's tasks.json file. – Manos Anastasiadis Jul 05 '19 at 06:19
  • OK.I'll try it again.Thanks a lot. – Ke Chen Jul 06 '19 at 11:04