Rust Compilation dieselrs sqlite3 Generated-Colums - linux

Background
I need to run a binary in an arm based computer(Jetson Nano) and i was compiling and running it without any problems until my team decided to use Generated Columns in sqlite3 a feature that was implemented in version 3.31.0 but the Ubuntu Image ran by said computer has a previous dev-version and results in the following crash using Dieselrs library
thread 'main' panicked at 'called `Result::unwrap()` on an
`Err` value: DatabaseError(__Unknown, "malformed database schema
(group) - near \"as\": syntax error")', src/common_queries.rs:182:35
(we handle the unwrap but i removed it in order to see the real message)
I know its a version problem since the message shown is similar to what its stated in the sqlite3 documentation
.... If an earlier version of SQLite attempts to read a
database file that contains a generated column in its schema,
then that earlier version will perceive the generated column syntax
as an error and will report that the database schema is corrupt.
and because in an x86 computer with sqlite3 version 3.34 works without a problem.
What has been tried
update libraries
I already tried downloading version 3.36 of SQLite from the official webpage and ran sudo make install but that didn't create the library in /usr/include but somehow it still compiles it and it still shows the same error. (maybe it knows where the new library is but its weird that despite that it still doesn't work).
Change db-schema
the simplest solution that i could come up with was to change the schema and store the generated column as a new column that would be generated with an after update trigger but that would mean that the database would no longer be in a Normal form.
Cross compilation
Since it works in an x86 machine I tried targeting the architecture, following different approaches that resulted in the following message
linking with `aarch64-linux-gnu-ld` failed: exit status: 1
....
....
....
aarch64-linux-gnu-ld: cannot find -lsqlite3
aarch64-linux-gnu-ld: cannot find -lgcc_s
which i guess comes from the fact that neither of them show up in /usr/aarch64-linux-gnu/include/ but installing libsqlite3-dev doesn't fix the issue.
Any ideas on how to fix this problem?

Try adding libsqlite3-sys = { version = "0.22.0", features = ["bundled"]} to your Cargo.toml. This forces libsqlite3 to be build from source for the correct target. This uses the latest version of sqlite.
See the documentation of libsqlite3-sys for details.

Related

Sqlite on Python 3 with Spatialite and full support for spatial indices (i.e. rtree)

This is the scenario:
I am using Python 3 (3.6 through 3.8 on Windows 10, using Pipenv and vanilla Python) to create an SQLite file with Spatial support and several triggers based on Spatial Indices.
Creating the database and adding records works just fine after loading Spatialite
conn.enable_load_extension(True)
conn.load_extension("mod_spatialite")
However, adding spatial links with code such as below
SELECT CreateSpatialIndex( 'nodes' , 'geometry' );"""
returns the following error
updateTableTriggers: "no such module: rtree"
I tried compiling the rtree extension following some recommendation from
Compiling SQLite RTREE in MSVC?
and using VS 2016 (16.4.2).
But I get all sorts of errors when trying to load that in SQL (Might not be compiling it properly, but I tried multiple things and nothing worked). My best attempt was a successful compilation using pretty much the instructions I referred to above, but when I attempted
p.conn.load_extension("libSqliteRtree.dll")
I got
sqlite3.OperationalError: The specified procedure could not be found.
I am really at loss here, as there seems to be very little discussion on this topic everywhere I looked. A few questions that come to mind are:
Are the specific compilation instructions/tricks/compiler versions that I should be using?
Is it even possible to compile and load rtree in Python 3 using the standard sqlite3 library?
Is this particular to Windows?
Are there alternative SQLite Python packages that could do the job (I didn't find any on PyPI)?
It is critical, however, that the solution works across different platforms.
I was just having the exact same problem, with Python 3.8 x64. I believe the problem was that the sqlite3.dll file inside my Python's installation DLLs folder had been compiled without RTREE enabled (https://sqlite.org/rtree.html).
To resolve this I visited the SQLite website, downloaded the .zip with the latest sqlite3.dll for Windows x64 (hoping RTREE would be enabled on that version, because I tried compiling it on my own and it didn't work), and swapped the old DLL in the DLLs folder with the newly downloaded DLL from the website. The RTREE error was gone! Detailed steps below:
Access https://sqlite.org/download.html and choose the "Precompiled Binaries for Windows" of your system. Mine was x64 because I was running Python x64. Download the .zip and unzip it.
Find your Python's installation folder (the folder which contains the python.exe you're running), and open the DLLs folder. You'll see there is a file there called sqlite3.dll. That's the one that comes with the Python installation.
Copy the sqlite3.dll from the unzipped folder in step 1 and paste into the DLLs folder, click Yes to substitute the file in the DLLs folder for the new one. That should solve the problem.

Vulkan.hpp compiling on one system but not another

I have the following generic function:
template <typename U>
auto CastVkArray(std::vector<U> &unique_handles)
{
std::vector<typename U::element_type> handles;
for(auto &u_handle : unique_handles) handles.push_back(*u_handle);
return handles;
}
The problem is/was that although I thought I instructed premake5 to use the version under a local directory in my project, it was using the system's installed version instead. The version mismatch meant that I was using an old vulkan.hpp header rather than the one I need.
Which I am temporarily using to convert unique handle arrays to non unique arrays. This code compiles just fine on my desktop (arch linux), however on my laptop (ubuntu) I get the error:
error: no type named ‘element_type’ in ‘class vk::UniqueHandle<vk::CommandBuffer>’
std::vector<typename U::element_type> handles;
I use premake 5 to generate my build environment and the script hasn't changed between the 2 systems. I checked that all the libraries I am using are the same version, in particualr, I made sure that the vulkan sdk is the same between the 2 computers.
I deleted and rebuilt my code multiple times to test for potential race conditions in compilation (just to see if anything changed), the error is always the same.
The one difference that I have found is that the reported version of premake in arch is 5.0.0-dev but on ubuntu it is 5.0.0-alpha14
But I have not been able to find the dev version on the official github repository of premake.

how to handle "undefined symbol" errors for mismatched shared objects

I developed an application using a recent Glade, so I need it to load the UI from XML at runtime, using the GtkBuilder. If I try to run this on a distro which has too old a Gtk (e.g. RHEL 5), it will fail like this
undefined symbol: gtk_builder_new
which is normal and expected. But I wonder if there is a way to catch that error and instead display a GUI error dialog saying something like "your version of Gtk is not new enough"? This is an error that happens before my main() starts, so really the question is, is there a way to handle runtime linking errors? While googling, I found a mention of the concept of a linker plugin but I didn't find details about that yet. It sounds like something which would have to exist outside my application anyway, so maybe that's going a bit far.
I could use dlopen() to load Gtk, but that's ridiculous because I'd have to give the full path to it, and then I'd have to call dlsym() a lot to link every function that I need. ld-linux.so does the search for me. Is there a way I can use ld-linux.so to tell me the path to libgtk without actually loading it, then I check whether the version is new enough (or just whether gtk_builder_new exists), then finish the runtime linking if it's OK?
Well, it doesn't work that way on a Linux distro. What you're basically doing is bypassing the package manager.
The good way is to build your software on the target distro. At configuration time (call to ./configure) you will see that the requirements to use your software are not met. Or if you have no configure script, the compiler will yell at link time.
Then, it's the packager's job to fill in the requirement of the package. If in the .spec file of your RPM package you require gtk >= 2.16, then at installation time, the user will be shown the dialog telling him that some dependencies are missing, and he will see that his GTK version is too old.
You seem to be talking about the situation where you have compiled against headers with a recent enough version, but are running on a system where your library is not recent enough.
GTK provides a facility for checking that you have linked against a new enough version of the library. For example, if you need at least GTK 2.12 (which is the version in which GtkBuilder was introduced) you can use this code which will even display a nice GUI error dialog:
if (gtk_major_version < 2 || gtk_minor_version < 12) {
GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"Your version of GTK is too old to run this program.");
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"You need at least version 2.12.0; your version is %d.%d.%d.",
gtk_major_version, gtk_minor_version, gtk_micro_version);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
exit(-1);
}
Here is a workaround which might help: Rename your exe and create a bash script which calls it.
Now you can do this:
EXE=...name-of-your-real-executable...
LOG=logfile
$EXE > "$LOG" 2>&1 || {
if grep "undefined symbol: gtk_builder_new" "$LOG" ; then
... show error message ...
fi
}
[EDIT] Alternatively, you can create a really small test program which just contains a call to gtk_builder_new and run that during installation or in the test script.
That way, you don't need to check for a specific error message (which might get translated on non-English systems). If this small test program fails, you can be sure it's because of this missing symbol and nothing else.

fatal error C1084: Cannot read type library file: 'Smegui.tlb': Error loading type library/DLL

I am trying to build an old version of an application which consists of VC++ projects that were written in Visual Studio 2003.
My OS is Windows 7 Enterprise (64-bit).
When I try and build the solution I get the following errors:
error C4772: #import referenced a type from a missing type library; '__missing_type__' used as a placeholder
fatal error C1084: Cannot read type library file: 'Smegui.tlb': Error loading type library/DLL.
They both complain about the following import statement:
#import "Smegui.tlb" no_implementation
This is not a case of the file path being incorrect as renaming the Smegui.tlb file causes the compiler to throw another error saying it cannot find the library.
Smegui is from another application that this one depends on. I thought perhaps I was missing a dll but there is no such thing as Smegui.dll.
All I know about .tlb files is that they are a type library and you can create them from an assembly using tlbexp.exe or regasm.exe (the later also registers the assembly with COM)
There is also an Apache Ant build script which uses a custom task to invoke devenv.com to build the projects. This is the same script that the build server originally used to build the application. It gives me the same errors when I try and run it.
The strangest thing about this is that I knew it ought to work seeing as it is all freshly checked out from subversion. I tried many different combinations of admin vs user elevation, VS vs Ant build, cleaning, release.
I have got it to build successfully about 5 times but the build seems to be non-deterministic.
If anyone can shed some light on how this tlb stuff even works or what this error might mean I would greatly appreciate it.
I found a far more reliable solution: open the tlb with oleview.exe and then close it.
Not sure what this actually does but it works every time.
I think oleview is actually one of the samples included with Visual Studio but I haven't had the time to debug it and see what it is doing.
I ran into this error because one type library was trying to load a dependent type library, which it could not find. Even though the dependent type library was in the same directory, and even though that directory was in the searchable path, the compiler would error loading the first type library, but not mention the dependent type library in the error.
To find the pseudo-missing type library, I ran Process Monitor (procman64.exe) during the compile. This showed that after the reported type library had successfully loaded, a dependent type library could not be found. It even showed all of the places that it was looking for the dependent type library, none of which were where it should have been looking (e.g.: ).
The fix was to add a <PreBuildEvent> to the project to copy the dependent .tlb file to one of the directories that was actually being searched.
<PreBuildEvent>
<Command>copy /Y ..\Lib\Interop\CWSpeechRecLib.tlb .\</Command>
</PreBuildEvent>
http://msdn.microsoft.com/en-us/library/sce74ah7%28VS.71%29.aspx
smegui.tlb is referencing some other tlb that the compiler can't find. If you have the .idl for smegui you might be able to figure out what the other is. I suspect the missing tlb is something that original build machine had registered but that your machine doesn't have registered.
A type library is a binary description of a set of interfaces, coclasses and enums. They're usually generated for COM components, in the case of tlbexp and regasm the tlb is created from the assembly metadata. For native COM components they are usually generated from an idl (Interface Description Language) file by the midl tool.
Edit:
I just noticed you're on x64 Windows. Are you building the project with a new version of Visual Studio? If so, are you targeting x86 or x64? If the latter, it may simply be a 32bit component that the compiler can't find (or less likely, a x64 component the x86 compiler can't find if you are targeting x86), for WOW64 the registry is virtualized for x86 vs. x64 applications.
Well I finally found out why I managed to get it to build sometimes and not others... sort of.
So long as I ran the build script with elevated administrator permissions and let that get as far as it could until that error occurred, then run the build script again as a protected administrator succeeded. Those steps must be done in that exact order with no other steps in between. If I try build in Visual Studio it does not work (although I did get it to succeed once). Probably some kind of virtualisation issue although it still doesn't quite make sense.
Well I don't need help on this any more and I know it's probably impossible to fully answer this question without knowing exactly what the build is doing. However if anyone does have any more thoughts I would happily receive them.
Cheers,
Steiny

Failure to register .dll with regsvr32 - only in Release build

I'm having a weird problem when trying to register the .dll i created using regsvr32.
During development everything went fine, the debug version registers and works fine. Now i wanted to create a Release version, but that Version does not register anymore.
regsvr32 comes up with the following error:
The module "mpegsplitter.dll" failed to load.
Make sure the binary is stored at the specified path or
debug it to check for problems with the binary or
dependent .DLL files.
The specified procedure could not be found.
Some research brought me to the dependency walker, which does tell me this
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
It also does show a dependency on "crtdll.dll" that the debug version does not have (The function view shows soem functions that normally should be in ole32.dll), which is colored red'ish.
So far so good, i guess its somehow related to what the dependency walker shows there.
But where do i go from here? How do i fix it?
Any help would be greatly appreciated, that has been keeping me busy for several hours already.
Thanks!
I have the same problem. When I compared the different between "Command Line" (in Project Properties -> Linker) of Release and Debug mode, I found out that the "Optimization" options (in Project Properties -> Linker) of Release mode was turned on while ion Debug not.
Turning of Optimization for linker in Release mode solved the problem
Is it possible that the debug version is compiled with _ATL_MIN_CRT but the release version isn't? You can set this with the Minimize CRT Use in ATL project property as well.
I fixed it. It was actually being caused by the order of some mingw libraries i included to link against ffmpeg. Oh well, how weird.
In my case, the difference was in Module Definition File entry between DEBUG and RELEASE. The DEBUG version was pointing to the .DEF file where as the RELEASE had it empty.

Resources