maxdoom-com / lsqlite

lua sqlite module
MIT License
9 stars 0 forks source link

building with gcc > 8? #1

Closed thchha closed 4 years ago

thchha commented 4 years ago

Hey, thanks for your library - satisfies exactly my needs! :- )

I can't build your library on Debian bullseye AMD64, which only comes with > gcc-8.

After building and referencing the .so, my scripts report an error, same for the provided test.lua:

lua: error loading module 'lsqlite' from file '/home/...../lsqlite.so':
path/repeated/lsqlite.so undefined symbol: sqlite3_exec

So i tried compiling with gcc-8, 9, 10, c99, with lua 5.1 and lua 5.3 (including compat). When compiling with lua 5.3, luaL_open can not be found.

where libsqllite3-dev is the version 3.31.1-5. on ARM64 (using Lua 5.1 || 5.3) version: 3.27.2-3 it is working as expected! :+1:

Before asking, i checked the news on sqlite.org. The function sqlite_exec() is still listed in their API, so I am not able to resolve this on my own :- (

Applications that use SQLite should only interface with SQLite through the officially published APIs. Applications should not depend upon or use the internal data structures of SQLite as those structures might change from one release to another. However, there is a popular application that does depend on the details of the internal layout of data in an internal SQLite data structure, and those details changed in version 3.31.0, breaking the application. This is, technically, a bug in the application, not in SQLite. But it is within the power of SQLite to fix it, by reverting the internal data structure change, and so that is what we have done for the 3.31.1 release.

maxdoom-com commented 4 years ago

Hey @thchha !

I've updated the code. Please pull it an try again.

It seems, the sqlite3_exec wasn't the problem. I was still using the "old lua module system". Starting from 5.2 lua hat a compile time flag LUA_COMPAT_MODULE which made this available. But it seems not to be working anymore... hmpf...

The actual solution works on my debian with your sqlite3-dev version and lua 5.1, 5.2 and 5.3. (See the Makefile.)

Please let me know if this solves it for you.

;-)

maxdoom-com commented 4 years ago

Btw., loading the library has changed:

lsqlite = require("lsqlite")
local db = lsqlite.open("database.db")
-- ...
thchha commented 4 years ago

Thanks @maxdoom-com!!! You solved my problems - The resulting shared libraries work for each version: lua 5.1, lua 5.2 and lua5.3! :tada: :grinning: :muscle:

Nonetheless, the resulting libraries only work when compiled with gcc-8. Version 9 and 10 and c99 do not result in functional libraries.

I am fairly new to C, so I am not able to contribute an patch yet, but I will revisit this issue, once I get more familiar with compilers. c99 also comes with two additional warnings, (without `-Wpedantic). Again, thanks for your very fast fix!!

maxdoom-com commented 4 years ago

:happy:

c99 is a bigger issue. the code is c89 style by intention.

i wrote this library twice, first in a more modern style until i realised that, when i'm using an elder style, where "inline c procedures" (or whatever they are called) the code shrinks very much. this feature was removed with c90 standart and is nowadays only an extension of gcc.

here an example:

int foo(int a, int b)
{
    int bar()
    {
        return a+b;
    }
    return bar();
}

i will try to check the compiler flags of gcc 9/10 how to properly address them.

maxdoom-com commented 4 years ago

hi, again @thchha !

i figured it out. it's some kind of problem between gcc-9/-10 and the sqlite3.so on debian. maybe on other systems as well.

you may compile the library with gcc-9/-10 by including sqlite in the compilation process this way:

the resulting lsqlite.so is much larger, but it works. the reason for the larger size is, that we are not using the sqlite3.so from debian but our own compiled in.

hope this helps ;-)