0

I am working on my coursework for my university. It consists on making a database in c++. I have those errors from Monday and I can not solve them.

Can anyone help me to fix this issue, please?

I am working in VSCode and I am a beginner in c++, thank you.

code:

#include <stdio.h>
#include <D:\SSD\Desctop\barethika\sqlite3.h> 

int main(int argc, char* argv[]) {
   sqlite3 *db;
   char *zErrMsg = 0;
   int rc;

   rc = sqlite3_open("test.db", &db);

   if( rc ) {
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      return(0);
   } else {
      fprintf(stderr, "Opened database successfully\n");
   }
   sqlite3_close(db);
}

ERRORS:

c:\users\name\AppData\Local\Temp\ccguCZxk.o:tempCodeRunnerFile.cpp(.text+00xa4) undefined reference to 'sqlite3_open' c:\users\name\AppData\Local\Temp\ccguCZxk.o:tempCodeRunnerFile.cpp(.text+00xa4) undefined reference to 'sqlite3_errmsg' c:\users\name\AppData\Local\Temp\ccguCZxk.o:tempCodeRunnerFile.cpp(.text+00xa4) undefined reference to 'sqlite3_close' collect2.exe:error: ld returned 1 exit status

nassim
  • 1,547
  • 1
  • 14
  • 26
Albert
  • 1
  • Does this answer your question? [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) – ChrisMM Jun 10 '21 at 02:20
  • Normally in VSCode you edit your `tasks.json` to add the link commands but I am not sure how this is handled when using the code runner extension. The basic problem is you are not linking to the sqlite library. – drescherjm Jun 10 '21 at 02:43

1 Answers1

0

Try to set the absolute path of the library. This kind of problem is usually the wrong path of the library

  • may you explain a little bit more, please? – Albert Jun 10 '21 at 02:36
  • hello, If you want to use sqlite,you need to include sqlite header file and library file,The question is usually posed by library file path is not matching.You need to make sure that the path is correct, so you can use the absolute path first,Notice the debug and release modes,And the number of bits of the library(32 or 64) – pole night Jun 10 '21 at 06:14