NO

Author Topic: Trouble including sqlite3 with a project  (Read 318 times)

Offline CplEthane

  • Member
  • *
  • Posts: 6
Trouble including sqlite3 with a project
« on: August 24, 2020, 07:06:44 pm »
I'm attempting to fit Sqlite3 into my project, and I'm working from the tutorial at http://zetcode.com/db/sqlitec/ .

I've already done a search for sqlite on this forum to see if my problem has already been addressed there, and attempted the suggestions offered within those threads but I'm still having problems.

Anyway, here's the code I'm working from the Zetcode tutorial:

Code: [Select]
#include <stdio.h>
#include "sqlite3.h"

int main(void) {
   
    printf("%s\n", sqlite3_libversion());
   
    return 0;
}

This is set up as a console application, std is set to c99, sqlite.dll/sqlite.c/sqliteh etc are all in the same folder and are included as files within the project.  Here are the error(s) I receive upon attempting to compile:

Quote
Building sqltest.exe.
POLINK: error: Unresolved external symbol 'sqlite3_column_database_name' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_column_database_name16' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_column_origin_name' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_column_origin_name16' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_column_table_name' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_column_table_name16' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_deserialize' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_fts3_may_be_corrupt' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_fts5_may_be_corrupt' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_rtree_geometry_callback' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_rtree_query_callback' - referenced from '<common>'.
POLINK: error: Unresolved external symbol 'sqlite3_serialize' - referenced from '<common>'.
POLINK: error: Unresolved external symbol '__endthreadex' - referenced from 'C:\...\Documents\PellesCProjects\sqltest\output\sqlite3.obj'.
POLINK: error: Unresolved external symbol '__beginthreadex' - referenced from 'C:\...\Documents\PellesCProjects\sqltest\output\sqlite3.obj'.
POLINK: fatal error: 14 unresolved external(s).
*** Error code: 1 ***
Done.

I've attempted to look up the reason for this problem and probably overlooked it but for the life of me I can't find it.

Thanks!

Offline algernon_77

  • Member
  • *
  • Posts: 10
Re: Trouble including sqlite3 with a project
« Reply #1 on: August 24, 2020, 09:13:17 pm »
Hello there!

You'll also need the import library for the program to compile and sqlite3.dll for your program to start.
Please see the links below, one is for the 64 bit version, the other is for x86 (32 bit).

x86:
https://drive.google.com/file/d/1IwSp5s9R3TfEcMQhKl2tJ75_GGe21ibq/view?usp=sharing

x64:
https://drive.google.com/file/d/1FpDV0_NeRtIHdcK2YzLwcDVihYPWrgki/view?usp=sharing

- for 64 bit: put sqlite3.lib from the 64bit archive in \PellesC\Lib\Win64
- for 32 bit: put sqlite3.lib from the 32bit archive in \PellesC\Lib\Win
- put sqlite3.h in \PellesC\Include\Win

On your project, #include <sqlite3.h> in the source and on "project options->linker->library and obj. files" add sqlite3.lib to the list.
Put sqlite3.dll in the project folder (the one form the 32bit archive for 32bit projects, the one from the 64bit archive for 64 bit projects).

Hope it helps (it works for me).
« Last Edit: August 24, 2020, 09:35:02 pm by algernon_77 »

Offline CplEthane

  • Member
  • *
  • Posts: 6
Re: Trouble including sqlite3 with a project
« Reply #2 on: August 24, 2020, 10:13:45 pm »
That worked!  Thanks for your help!

Offline algernon_77

  • Member
  • *
  • Posts: 10
Re: Trouble including sqlite3 with a project
« Reply #3 on: August 25, 2020, 06:05:52 am »
You're welcome. Good luck!

Offline John Z

  • Member
  • *
  • Posts: 95
Re: Trouble including sqlite3 with a project
« Reply #4 on: August 25, 2020, 12:54:00 pm »
If you are going to distribute your application wouldn't it be easier to use the C source code amalgamation rather than the dll and lib?  As I read it (I'm just starting to learn sqlite3) you can just include one C source file and one .h file into your code base.  No need for the dll or lib.   

BTW Is there a windows ODBC driver for sqlite3 ?

John Z

Offline algernon_77

  • Member
  • *
  • Posts: 10
Re: Trouble including sqlite3 with a project
« Reply #5 on: August 25, 2020, 02:08:54 pm »
I don't see any impediment in using the amalgamation file, I imagine Pelle would compile it with no fuss, but in all honesty, I haven't tried it personally.
It would just make your executable bigger, but nowadays, I don't see how that would be much of a problem :)

You can find an ODBC driver here: http://www.ch-werner.de/sqliteodbc/
I haven't tried this either :)

Offline John Z

  • Member
  • *
  • Posts: 95
Re: Trouble including sqlite3 with a project
« Reply #6 on: August 25, 2020, 03:44:44 pm »
Thanks very much.  Just found that link too - thanks for putting it here.

I'll probably try the amalgamation file because it is simpler to deploy a single exe.
The program actually could end up smaller (in total) if only the used functions are
included because the dll by default must include everything I imagine.


Regards,
John Z

Offline algernon_77

  • Member
  • *
  • Posts: 10
Re: Trouble including sqlite3 with a project
« Reply #7 on: August 25, 2020, 04:25:52 pm »
Hi,

Yes, the dll includes everything, but so would your executable - all the code resides in sqlite3.c, which the compiler will transform in sqlite3.obj, which the linker will put together with you code and the resulting exe would be very much like the dll in size, even if you used just a function.

If every function from sqlite3.c would reside in a separate module (*.c file), and then you would compile all the .c files into .objs, you could make a static library from them and link against it every time you would like to use sqlite3. Then, if you would have used function "X", the linker would link just X.obj, and your exe wouldn't contain all the other unused procedures.

I just tried it, (with the above code from OP) and the resulting exe is about 730kb :)
If you want to give it a shot, don't forget to select "multithreaded lib" from proj. options->compiler->code gen.

Regards!

Offline John Z

  • Member
  • *
  • Posts: 95
Re: Trouble including sqlite3 with a project
« Reply #8 on: August 27, 2020, 02:54:30 pm »
Thanks Algernon_77 ;)

Yes I've compiled the amalgamation sqlite3.c into my sources. 

Results of Sqlite3.c incorporation (C99 with multithreaded lib and WIN32)

As an initial item Pelles C can't open the amalgamation file in its editor - too big.  I use Textpad to see what the error causes were.

I created the executable and it add about 500K to my program executable, which almost doubles
my program. This increase is a bit above half of the DLL size which is 954K.

Compile results are a bit concerning to me though ....
468 warnings
Mostly untyped conversions like: 'Conversion from 'long long int' to 'int';' and others - not overly worried about these but I always resolve all errors and warnings under Level2 compile for my own code.

however there are 6 situations of '=' used in a conditional expression.
These can be 'correct' depending exactly how they are written.
ex:     if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;

warning #2261: Loop with no effect removed (any visible side-effects are retained).
warning  #2046: Expression with no effect removed.
warning  #2027: Missing prototype for 'proc', with type 'int __stdcall (*)()'.
warning  #2028: Missing prototype for type 'int __stdcall (*__stdcall (*)(struct HINSTANCE__ *, const char *))()'.

60 warnings  #2214: Address of import .... identity not guaranteed.  (Probably OK)
115 warnings of  #2154: Unreachable code.  (Probably OK depends on conditionals as the code tries to cover many compilers and OS types)

Now to see if it actually works . . . .

Regards,
John Z

Update:  Worked! it created the test CARS db without issues. 
« Last Edit: August 27, 2020, 05:05:53 pm by John Z »

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2076
    • http://www.smorgasbordet.com
Re: Trouble including sqlite3 with a project
« Reply #9 on: August 29, 2020, 04:47:07 pm »
As an initial item Pelles C can't open the amalgamation file in its editor - too big.
There is a setting called "MaxFileSize" you can tweak... (manually, for now, in the Registry or XML file - depending on what you use).
/Pelle

Offline John Z

  • Member
  • *
  • Posts: 95
Re: Trouble including sqlite3 with a project
« Reply #10 on: August 30, 2020, 12:12:52 pm »
Thanks Pelle,

I'm using the Registry.  Tweaked it to allow a 10388608 file, it actually looked big enough before I edited it.
It was, in decimal 8388608 while the c file size is 8,138,666 bytes.  After changing to the about 10 Meg the same error happened so I change it to 20,000,000 and it is all working, including showing the many 100's of procedures in the file.


Thanks,
John Z

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2076
    • http://www.smorgasbordet.com
Re: Trouble including sqlite3 with a project
« Reply #11 on: August 30, 2020, 08:23:09 pm »
It's really for the internal (contiguous) buffer space (UTF-16), but related to the file size. It's a balance between how many, and how large, files to open. I havn't figured out a way to do this "automagically"...

After rearranging the layout of Option pages in v10, there is now better room to add new options/pages. I guess this could go on some "Not terribly interesting or often changed options, but here you go..."-page with an explanation. (possibly with a shorter name ...   ;))
/Pelle