wxSQLite3, how to build SQLite without dll? Topic is solved

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

wxSQLite3, how to build SQLite without dll?

Post by Mojo » Sat Jun 13, 2009 3:48 pm

Hi all.

I use wxSQLite3 successfully, perfect wrapper, but my executables requires sqlite.dll every time.... I read Readme.txt that explains how to use statically linked SQLite library on Windows, but it unclearly should I download sqlite-amalgamation-3_6_11.zip or sqlite-source-3_6_11.zip and how to compile and build wxSQLite3 step by step including Visual C++ 2008 EE compiler-linker settings.....

Is there anyone who did it before?

Thanks in advance.
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Sat Jun 13, 2009 4:26 pm

You only need to add sqlite3.c/h (from amalgamation) to your project and build. No extra config or anything. I've tested this on Mac (10.5) and Win32 (VS 2005).

regards.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post by Mojo » Sat Jun 13, 2009 6:25 pm

Thank you protocol for your response.

Of course I did it, but my exe-file still requires sqlite.dll

I guess something goes wrong with compiler and linker settings...
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post by Mojo » Sat Jun 13, 2009 6:42 pm

Now I compiled both sqlite3.c and sqlite3.h separately of my application, then I copied sqlite3.lib into \sqlite3\lib of my application catalog, rebuilded my solution and get 2 errors:

Code: Select all

Linking...
wxcode_msw28u_wxsqlite3.lib(wxsqlite3.obj) : error LNK2001: unresolved external symbol _sqlite3_rekey
wxcode_msw28u_wxsqlite3.lib(wxsqlite3.obj) : error LNK2001: unresolved external symbol _sqlite3_key
C:\Projects\PhoneBookLast\PhoneBookLast\Release\PhoneBookLast.exe : fatal error LNK1120: 2 unresolved externals
because of my code uses wxSQLite3 encryption I can't use "standard" sqlite3.dll and I can assume can't use standard sqlite3.lib too...
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Sat Jun 13, 2009 8:04 pm

Mojo wrote:Now I compiled both sqlite3.c and sqlite3.h separately of my application, then I copied sqlite3.lib into \sqlite3\lib of my application catalog, rebuilded my solution and get 2 errors:

Code: Select all

Linking...
wxcode_msw28u_wxsqlite3.lib(wxsqlite3.obj) : error LNK2001: unresolved external symbol _sqlite3_rekey
wxcode_msw28u_wxsqlite3.lib(wxsqlite3.obj) : error LNK2001: unresolved external symbol _sqlite3_key
C:\Projects\PhoneBookLast\PhoneBookLast\Release\PhoneBookLast.exe : fatal error LNK1120: 2 unresolved externals
because of my code uses wxSQLite3 encryption I can't use "standard" sqlite3.dll and I can assume can't use standard sqlite3.lib too...
If you want to use the encryption extension included in the wxSQLite3 release you can't use the SQLite amalgamation unfortunately since the encryption extension is written in C++ while SQLite itself is written in C. Follow the instructions in the wxSQLite3 readme file to create a static SQLite library and and link wxSQLite3 against the resulting .lib file.

Regards,

Ulrich

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Sat Jun 13, 2009 8:06 pm

No need to compile them separately, at least I never do.

Those two symbols are for sqlite encryption, if you don't need it you can disable wxsqlite encryption.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Sun Jun 14, 2009 6:53 am

protocol wrote:No need to compile them separately, at least I never do.

Those two symbols are for sqlite encryption, if you don't need it you can disable wxsqlite encryption.
As Mojo said his code uses wxSQLite3 encryption so he needs to compile SQLite with encryption support.

BTW, when I compile SQLite including my encryption extension I use the following SQLite relevant preprocessor defines:

THREADSAFE=1
SQLITE_SOUNDEX
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_HAS_CODEC
SQLITE_SECURE_DELETE
SQLITE_ENABLE_FTS3
SQLITE_ENABLE_FTS3_PARENTHESIS
SQLITE_ENABLE_RTREE
SQLITE_CORE

If FTS3 and/or RTREE support is not needed the associated defines may be dropped from the list.

Regards,

Ulrich

Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post by Mojo » Sun Jun 14, 2009 3:11 pm

Thank you Ulrich, thank you protocol.

I tried to go several ways, but my app still takes sqlite3.dll, can't get what do I do wrong.....

I went this steps:

1. I downloaded sqlite-source-3_6_11.zip, it has a lot of *.c and *.h files, then I build all them as one static lib (except for shell.c and tclsqlite.c), I got SQLite3.lib (big file about 4.55Mb).

2. I copied that big file (SQLite3.lib) into wxSQLite3 \sqlite3\lib folder, then I rebuild wxSQLite3 as static lib, all went OK and I got wxcode_msw28u_wxsqlite3.lib (the size of 4.22 Mb).

3. Then I copied new wxcode_msw28u_wxsqlite3.lib into \lib\vc_lib catalog of my project and rebuided my project, all went OK, but when I launch my app..... it requires sqlite3.dll :( awful disappointment :( I got lost :(

What do I do wrong? I read Readme.txt and did all as it said...
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Sun Jun 14, 2009 9:42 pm

Mojo wrote:I went this steps:

1. I downloaded sqlite-source-3_6_11.zip, it has a lot of *.c and *.h files, then I build all them as one static lib (except for shell.c and tclsqlite.c), I got SQLite3.lib (big file about 4.55Mb).
The size seems to be quite big. I get about 900 kb in release mode and about 2.5Mb in debug mode when using VC++ 2008 EE. So you seem to use different compiler/linker settings. Please compare the compiler command prompt displayable in the project properties dialog to the following:

Code: Select all

/I "..\src" /I "..\src\ext\fts3" /D "WIN32" /D "NDEBUG" /D "_LIB" /D "THREADSAFE=1" /D "SQLITE_SOUNDEX" /D "SQLITE_ENABLE_COLUMN_METADATA" /D "SQLITE_HAS_CODEC" /D "SQLITE_SECURE_DELETE" /D "SQLITE_ENABLE_FTS3" /D "SQLITE_ENABLE_FTS3_PARENTHESIS" /D "SQLITE_ENABLE_RTREE" /D "SQLITE_CORE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /FD /EHsc /MD /Fp".\Release/sqlite3lib.pch" /Fo".\Release/" /Fd".\Release/" /W3 /nologo /c /TP /errorReport:prompt
Do you see differences? If so, which?
Mojo wrote:2. I copied that big file (SQLite3.lib) into wxSQLite3 \sqlite3\lib folder, then I rebuild wxSQLite3 as static lib, all went OK and I got wxcode_msw28u_wxsqlite3.lib (the size of 4.22 Mb).
This should produce a library not requiring the SQLite DLL - if you didn't change the default setting of the precompiler define wxUSE_DYNAMIC_SQLITE3_LOAD (which should be set to 0).
Mojo wrote:3. Then I copied new wxcode_msw28u_wxsqlite3.lib into \lib\vc_lib catalog of my project and rebuided my project, all went OK, but when I launch my app..... it requires sqlite3.dll :( awful disappointment :( I got lost :(

What do I do wrong? I read Readme.txt and did all as it said...
It seems that the linker references the wrong library either when building wxSQLite3 or your own application. Please post the command prompts of the compiler and the linker. This should give a hint what's going wrong.

Regards,

Ulrich

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Mon Jun 15, 2009 2:33 am

I agree with utelle, in that you need to review your linker settings.

But again, I don't have any issues building, and my config is much simpler.

Do you have to build external libs?
Attachments
vs-proj-tree.png
I add the wxsqlite and sqlite3 files to the proj directly, no need for static libs to configure.
vs-proj-tree.png (7.08 KiB) Viewed 9082 times
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post by Mojo » Mon Jun 15, 2009 6:34 pm

Thank you Ulrich, thank you protocol.

Ulrich's post very helped me
utelle wrote:..... Please compare the compiler command prompt displayable in the project properties dialog to the following:

Code: Select all

/I "..\src" /I "..\src\ext\fts3" /D "WIN32" /D "NDEBUG" /D "_LIB" /D "THREADSAFE=1" /D "SQLITE_SOUNDEX" /D "SQLITE_ENABLE_COLUMN_METADATA" /D "SQLITE_HAS_CODEC" /D "SQLITE_SECURE_DELETE" /D "SQLITE_ENABLE_FTS3" /D "SQLITE_ENABLE_FTS3_PARENTHESIS" /D "SQLITE_ENABLE_RTREE" /D "SQLITE_CORE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /FD /EHsc /MD /Fp".\Release/sqlite3lib.pch" /Fo".\Release/" /Fd".\Release/" /W3 /nologo /c /TP /errorReport:prompt
Do you see differences? If so, which? ...........
I set all my compiler and linker settings as Ulrich kindly provided above.

My compiler settings are:

Code: Select all

/I "include" /D "WIN32" /D "NDEBUG" /D "_LIB" /D "THREADSAFE=1" /D "SQLITE_SOUNDEX" /D "SQLITE_ENABLE_COLUMN_METADATA" /D "SQLITE_HAS_CODEC" /D "SQLITE_SECURE_DELETE" /D "SQLITE_CORE" /FD /EHsc /MD /Fo"Release\" /Fd"Release\vc90.pdb" /W3 /nologo /c /TP /errorReport:prompt
My linker settings are:

Code: Select all

/OUT:"C:\Projects\SQLite3\SQLite3\Release\SQLite3.lib" /NOLOGO /LTCG

Now I got SQLite3.lib that has size of 379 Kb, this is normally as I guess.

But I assume I have to tie somehow wxSQLite3 encryption feature and SQLite3.lib ...
I added to SQLite3.lib proj codec-folder from wxSQLite3 archive and tried to rebuild SQLite3.lib with encryption support, but I got error:

Code: Select all

Compiling...
pager_secure.c
.\codec\pager_secure.c(1) : fatal error C1083: Cannot open include file: 'pager.c': No such file or directory
While 'pager.c' is linked OK, cause I builded SQLite3.lib without encryption feature successfully.

I guess it takes somehow particular compiler and linker settings for encryption support....

I am not sure how to choose right way, I added codec-folder into C/C++ ->General->Additional Include Directories, and there I added before include-folder with SQLite3 header-files (I divided SQLite3 into two catalogs 'include' and 'src').

What settings do I lack else?

Thanks in advance.
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post by Mojo » Mon Jun 15, 2009 7:01 pm

Now I got another error:

Code: Select all

Generating Code...
Compiling...
codecext.cpp
c:\projects\sqlite3\sqlite3\codec\codec.h(24) : fatal error C1083: Cannot open include file: '../sqliteInt.h': No such file or directory
codec.cpp
c:\projects\sqlite3\sqlite3\codec\codec.h(24) : fatal error C1083: Cannot open include file: '../sqliteInt.h': No such file or directory
rijndael.cpp

My compiler command prompt settings are:

Code: Select all

/I "..\src" /I "..\include" /I "include" /I "src" /I "codec" /I "..\codec" /D "WIN32" /D "NDEBUG" /D "_LIB" /D "THREADSAFE=1" /D "SQLITE_SOUNDEX" /D "SQLITE_ENABLE_COLUMN_METADATA" /D "SQLITE_HAS_CODEC=1" /D "SQLITE_SECURE_DELETE" /D "SQLITE_CORE" /FD /EHsc /MD /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /nologo /c /TP /errorReport:prompt
Librarian setting still same:

Code: Select all

/OUT:"C:\Projects\SQLite3\SQLite3\Release\SQLite3.lib" /NOLOGO /LTCG
Something goes wrong with encryption ....[/code]
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

Mojo
Super wx Problem Solver
Super wx Problem Solver
Posts: 401
Joined: Wed Sep 21, 2005 8:17 am
Location: Rostov-on-Don, Southern Russia

Post by Mojo » Mon Jun 15, 2009 7:42 pm

:) Bingo! I did it :)

I placed codec folder into include (the catalog of SQLite3 header files) all compiled OK, just some warnings:

Code: Select all

Compiling...
codecext.cpp
c:\projects\sqlite3\sqlite3\include\codec\codec.h(33) : warning C4005: 'PAGER_MJ_PGNO' : macro redefinition
        c:\projects\sqlite3\sqlite3\include\pager.h(55) : see previous definition of 'PAGER_MJ_PGNO'
codec.cpp
c:\projects\sqlite3\sqlite3\include\codec\codec.h(33) : warning C4005: 'PAGER_MJ_PGNO' : macro redefinition
        c:\projects\sqlite3\sqlite3\include\pager.h(55) : see previous definition of 'PAGER_MJ_PGNO'
rijndael.cpp
Generating Code...
Creating library...
pager.obj : warning LNK4006: _sqlite3PagerSetCachesize already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSetSafetyLevel already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSetBusyhandler already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSetReiniter already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSetPagesize already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerTempSpace already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerMaxPageCount already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerReadFileheader already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerPagecount already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerTruncateImage already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerClose already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerRef already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerOpen already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerAcquire already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerLookup already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerUnref already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerBegin already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerWrite already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerDontWrite already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSync already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerCommitPhaseOne already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerCommitPhaseTwo already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerRollback already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerIsreadonly already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerRefcount already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerPageRefcount already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerIsMemdb already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerOpenSavepoint already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSavepoint already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerFilename already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerVfs already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerFile already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerJournalname already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerNosync already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerSetCodec already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerMovepage already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerGetData already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerGetExtra already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerLockingMode already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerJournalMode already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerJournalSizeLimit already defined in pager_secure.obj; second definition ignored
pager.obj : warning LNK4006: _sqlite3PagerBackupPtr already defined in pager_secure.obj; second definition ignored
Build log was saved at "file://c:\Projects\SQLite3\SQLite3\Release\BuildLog.htm"
SQLite3 - 0 error(s), 44 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
But SQLite3.lib works OK, my app doesn't take sqlite3.dll any more and encryption works OK :)

Good bye Builder C++, good bye MFC, I am fan of wxWidgets now :))


Thank you Ulrich and protocol, wxSQLite3 is splendid! :))
Win XP HE SP3, Vista
Xubuntu 12.04 LTS
wxWidgets-2.9.5
wxWidgets-3.0.0

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Mon Jun 15, 2009 8:08 pm

Mojo wrote:But I assume I have to tie somehow wxSQLite3 encryption feature and SQLite3.lib ...
Right. Of course you have to add the files in the sqlite3/src/codec subdirectory to the project for building SQLite.
Mojo wrote:I added to SQLite3.lib proj codec-folder from wxSQLite3 archive and tried to rebuild SQLite3.lib with encryption support, but I got error:

Code: Select all

Compiling...
pager_secure.c
.\codec\pager_secure.c(1) : fatal error C1083: Cannot open include file: 'pager.c': No such file or directory
While 'pager.c' is linked OK, cause I builded SQLite3.lib without encryption feature successfully.
Well, I quote the relevant sentence from the readme file coming with wxSQLite3:
... Instead of compiling pager.c you need to compile the wrapper file pager_secure.c which includes the original unmodified file pager.c using a #include directive. Add the sources in subdirectory codec to the SQLite makefile, replace the reference to pager.c in the
makefile to pager_secure.c ...
Mojo wrote:I guess it takes somehow particular compiler and linker settings for encryption support....

I am not sure how to choose right way, I added codec-folder into C/C++ ->General->Additional Include Directories, and there I added before include-folder with SQLite3 header-files (I divided SQLite3 into two catalogs 'include' and 'src').

What settings do I lack else?
The directory where all SQLite sources and headers reside has to be added as an additional include directory, too.

Regards,

Ulrich

utelle
Moderator
Moderator
Posts: 949
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Post by utelle » Mon Jun 15, 2009 8:35 pm

Mojo wrote:I placed codec folder into include (the catalog of SQLite3 header files) all compiled OK, just some warnings:

Code: Select all

Compiling...
codecext.cpp
c:\projects\sqlite3\sqlite3\include\codec\codec.h(33) : warning C4005: 'PAGER_MJ_PGNO' : macro redefinition
        c:\projects\sqlite3\sqlite3\include\pager.h(55) : see previous definition of 'PAGER_MJ_PGNO'
codec.cpp
c:\projects\sqlite3\sqlite3\include\codec\codec.h(33) : warning C4005: 'PAGER_MJ_PGNO' : macro redefinition
        c:\projects\sqlite3\sqlite3\include\pager.h(55) : see previous definition of 'PAGER_MJ_PGNO'
rijndael.cpp
Generating Code...
Creating library...
pager.obj : warning LNK4006: _sqlite3PagerSetCachesize already defined in pager_secure.obj; second definition ignored
...
SQLite3 - 0 error(s), 44 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
The reason for all those warnings is that you included both, pager_secure.c and pager.c, in your project. Drop pager.c from your project (as it is included by pager_sevure.c) and the warnings will vanish.
Mojo wrote:But SQLite3.lib works OK, my app doesn't take sqlite3.dll any more and encryption works OK :)
Although it works you should nevertheless follow the above recommendation.

Regards,

Ulrich

Post Reply