4

I am trying to follow some sqlite C++ tutorial to be able to access a database from within C++ code on Linux. sqlite3 is installed and working, but when I try to compile the example code given on the link (Create a Table) I get the following error:

 g++  build/test.o -o bin/test -pthread -L lib 
build/test.o: In function `main':
/home/alexander/Projects/Test/src/test.cpp:22: undefined reference to `sqlite3_open'
/home/alexander/Projects/Test/src/test.cpp:24: undefined reference to `sqlite3_errmsg'
/home/alexander/Projects/Test/src/test.cpp:39: undefined reference to `sqlite3_exec'
/home/alexander/Projects/Test/src/test.cpp:42: undefined reference to `sqlite3_free'
/home/alexander/Projects/Test/src/test.cpp:46: undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status

Do I need to install something else? Or do I need to set some paths?

Alex
  • 41,580
  • 88
  • 260
  • 469
  • 3
    you should link with library. add `-l sqlite3` – radar Nov 23 '14 at 13:35
  • 1
    possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Captain Obvlious Nov 23 '14 at 13:35
  • Thanks RADAR, that was the solution! – Alex Nov 23 '14 at 13:37

1 Answers1

1

I have no practice in compiling straight from the shell. In CodeBlocks it is necessary to point the paths of the “sqlite3.h” header and the “libsqlite3.so” dll. If the dll is not specified in Linker Settings, exactly the mentioned problem occurs.