SQLite3

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
breacsealgaire
Posts: 5
Joined: Aug 27, 2022 7:27

SQLite3

Post by breacsealgaire »

With retirement looming from 50 years of being a software engineer, I wanted to continue as a retirement hobby. I plan on using SQLite3 as the data container for anything I do. I used Microsoft Visual Studio to compile the SQLite3 amalgamation (I'm avoiding DLL's) using:

cl /c /EHsc /O2 /TC sqlite3.c
lib sqlite3.obj

So now, I'm trying to understand the next step to get FB to use either the Lib or Obj files created. How do I do that?

breacsealgaire
breacsealgaire
Posts: 5
Joined: Aug 27, 2022 7:27

Re: SQLite3

Post by breacsealgaire »

After going through forum history, I did the following:

cl /c /EHsc /O2 /TC sqlite3.c
ar rcs -o libsqlite3.a sqlite3.obj

a quick console program:

#Define UNICODE
#Include Once "windows.bi"

#Inclib "libsqlite3"

#ifdef __FB_WIN32__
extern "Windows"
#else
extern "C"
#endif

Function sqlite3_libversion() AS CONST ZSTRING PTR
end function

end Extern

DIM psz as const ZSTRING PTR = sqlite3_libversion()

Print *psz
Print "Press any key..."
Sleep

Compiles fine and linker always fails libsqlite3 not found. I have it both the ..lib folder and with my .bas program.

What am I doing wrong?
breacsealgaire
Posts: 5
Joined: Aug 27, 2022 7:27

Re: SQLite3

Post by breacsealgaire »

breacsealgaire wrote: Aug 28, 2022 4:09 #Inclib "libsqlite3"
Ok, ok changed to inclib "sqlite3' and now the linker tells me

skipping incompatible ./libsqlite3.a when searching for -lsqlite3
paul doe
Moderator
Posts: 1745
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: SQLite3

Post by paul doe »

breacsealgaire wrote: Aug 28, 2022 6:38
breacsealgaire wrote: Aug 28, 2022 4:09 #Inclib "libsqlite3"
Ok, ok changed to inclib "sqlite3' and now the linker tells me

skipping incompatible ./libsqlite3.a when searching for -lsqlite3
Check the bitness of the library. That error means that you're trying to compile a 64-bit program linking against a 32-bit lib (or vice-versa).
dodicat
Posts: 7996
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: SQLite3

Post by dodicat »

My attempt
files in download
shell.c
sqlite3.c
sqlite3.h
sqlite3ext.h

My commands (64 bit gcc)

gcc -c *.c
(got the .o files)
ar rcs -o libsqlite3.a *.o
(got libsqlite3.a)
Test code (in win 10)

Code: Select all

#inclib "sqlite3"
extern "windows"
declare Function sqlite3_libversion  alias "sqlite3_libversion"() AS CONST ZSTRING PTR
end Extern

DIM psz as const ZSTRING PTR = sqlite3_libversion()

Print *psz
Print "Press any key..."
Sleep
 
result

Code: Select all

3.39.2
Press any key... 
You can use nm libsqlite.a to track down the functions available.
Not so handy as a dll .def file. but you can double check sqlite3.bi if the occasion arises.
Happy hunting.
breacsealgaire
Posts: 5
Joined: Aug 27, 2022 7:27

Re: SQLite3

Post by breacsealgaire »

paul doe wrote: Aug 28, 2022 13:09 Check the bitness of the library. That error means that you're trying to compile a 64-bit program linking against a 32-bit lib (or vice-versa).
Thanks! Oversight on the compile not including the 64 bit switch due to delayed intelligence.

Now to figure out why the call to sqlite3_libversion is returning a 0 zstring pointer.
breacsealgaire
Posts: 5
Joined: Aug 27, 2022 7:27

Re: SQLite3

Post by breacsealgaire »

dodicat wrote: Aug 28, 2022 21:36 gcc -c *.c
(got the .o files)
ar rcs -o libsqlite3.a *.o
(got libsqlite3.a)
Test code (in win 10)

Code: Select all

#inclib "sqlite3"
extern "windows"
declare Function sqlite3_libversion  alias "sqlite3_libversion"() AS CONST ZSTRING PTR
end Extern

DIM psz as const ZSTRING PTR = sqlite3_libversion()

Print *psz
Print "Press any key..."
Sleep
 
result

Code: Select all

3.39.2
Press any key... 
You can use nm libsqlite.a to track down the functions available.
Not so handy as a dll .def file. but you can double check sqlite3.bi if the occasion arises.
Happy hunting.
I was using MS C++ compiler and LIB. Using your declare Function is get undefined reference sqlite3_libversion@0. We'll look into that.

Trying out gcc -c *.c get lots of missing headers. I'll look at the command line options.
dodicat
Posts: 7996
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: SQLite3

Post by dodicat »

You only need the declaration, not the body.

declare Function sqlite3_libversion() AS CONST ZSTRING PTR

Code: Select all

#inclib "sqlite3"
extern "windows"
declare Function sqlite3_libversion() AS CONST ZSTRING PTR
end Extern

DIM psz as const ZSTRING PTR = sqlite3_libversion()

Print *psz
Print "Press any key..."
Sleep
 
OR using the .bi file and you have libsqlite3.a in the same folder as your code, or in the lib folder of the distribution.

Code: Select all


#include "sqlite3.bi"

DIM psz as const ZSTRING PTR = sqlite3_libversion()

Print *psz
Print "Press any key..."
Sleep
 
Sorry, I missed your last post.
In my download there were only the four files, two .c and two .h (as shown above).
gcc didn't even give a warning, it went like clockwork.
I have :
gcc version 12.1.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders

Here was my download site:
https://www.sqlite.org/download.html
I used the first .zip on the page.
Post Reply