Building SQLite Fails Due to Incorrect Makefile Configuration and 32/64-bit Mismatch
Issue Overview: Makefile Misconfiguration and 32/64-bit Compatibility
The core issue revolves around a failure during the make
process of SQLite, specifically due to a misconfigured Makefile. The error message make: *** No rule to make target '@PKG_OBJECTS@', needed by '@PKG_LIB_FILE@'. Stop.
indicates that the Makefile is referencing undefined or improperly substituted variables. This problem is compounded by a secondary issue where the compiled SQLite binary is still 32-bit, despite the user’s intention to build a 64-bit version. The 32/64-bit mismatch manifests when attempting to load 64-bit shared libraries (ELFCLASS64
) into what appears to be a 32-bit SQLite binary, leading to runtime errors.
The root cause of the Makefile issue lies in the incorrect extraction of the SQLite source distribution. The user initially unpacked the source files using a GUI tool, which flattened the directory structure, causing critical files like Makefile.in
to be overwritten or misplaced. This misstep led to the generation of a faulty Makefile during the configure
step, which in turn caused the make
process to fail. The 32/64-bit issue, on the other hand, stems from either an incomplete cleanup of previous installations or an incorrect configuration during the build process.
Possible Causes: Incorrect Source Extraction and Build Configuration
The primary cause of the Makefile misconfiguration is the improper extraction of the SQLite source distribution. The SQLite source code is organized into multiple directories, each containing specific files necessary for the build process. When the user extracted the archive using a GUI tool, the directory structure was flattened, leading to the overwriting of critical files. Specifically, the tea/Makefile.in
file overwrote the top-level Makefile.in
, which is essential for generating a valid Makefile during the configure
step. This resulted in a Makefile that contained unresolved variables like @PKG_OBJECTS@
and @PKG_LIB_FILE@
, causing the make
process to fail.
The secondary issue of the 32/64-bit mismatch is likely due to one of two reasons. First, the user may have inadvertently used a 32-bit version of the SQLite source code or dependencies, leading to a 32-bit binary. Second, the build environment might still be referencing a previously installed 32-bit version of SQLite, even after attempting to build a 64-bit version. This could happen if the system’s library paths or environment variables were not properly updated to reflect the new 64-bit build.
Additionally, the user’s build script included several custom CFLAGS
and LIBS
settings, which may have interfered with the configure
script’s ability to correctly detect and configure the build environment. For example, the flag -DSQLITE_ENABLE_JSON1
is obsolete and unnecessary, as JSON support is enabled by default in recent versions of SQLite. Similarly, the repeated invocation of the configure
script with different flags could have led to inconsistent or incomplete configuration.
Troubleshooting Steps, Solutions & Fixes: Correcting the Build Process and Ensuring 64-bit Compatibility
To resolve the Makefile misconfiguration, the user must first ensure that the SQLite source distribution is extracted correctly. This can be achieved by using the command line to unpack the archive, preserving the directory structure. The following steps outline the correct process:
Delete the Existing Source Directory: Start by removing the incorrectly extracted source directory to avoid any residual files that might interfere with the new extraction.
rm -rf sqlite
Re-download and Extract the Source Distribution: Use the command line to download and extract the SQLite source distribution. For example:
wget https://www.sqlite.org/2023/sqlite-autoconf-3410100.tar.gz tar -xzf sqlite-autoconf-3410100.tar.gz cd sqlite-autoconf-3410100
Run the Configure Script with Correct Flags: Invoke the
configure
script with the appropriate flags to enable the desired features. For example:./configure --enable-shared --prefix=/usr/local --enable-fts5 --enable-rtree
Build and Install SQLite: Proceed with the
make
andmake install
commands to build and install SQLite:make sudo make install
To address the 32/64-bit compatibility issue, the user must ensure that the build environment is correctly configured for a 64-bit build. This involves verifying the architecture of the compiler and libraries being used. The following steps can help achieve this:
Verify the Compiler Architecture: Ensure that the compiler being used is capable of producing 64-bit binaries. For example, check the output of the following command:
gcc -v
The output should indicate that the compiler is configured for 64-bit targets.
Clean Up Previous Installations: Remove any previously installed versions of SQLite to avoid conflicts. This can be done using the package manager or manually deleting the installation directory:
sudo apt-get remove sqlite3 sudo rm -rf /usr/local/lib/libsqlite3* sudo rm -rf /usr/local/bin/sqlite3
Set Environment Variables for 64-bit Build: Ensure that the environment variables are set correctly for a 64-bit build. For example, set the
CFLAGS
andLDFLAGS
to include-m64
:export CFLAGS="-m64 -O2 -fPIC" export LDFLAGS="-m64"
Rebuild SQLite: Repeat the
configure
,make
, andmake install
steps with the corrected environment variables to ensure a 64-bit build.Verify the Binary Architecture: After installation, verify that the SQLite binary is indeed 64-bit using the
file
command:file /usr/local/bin/sqlite3
The output should indicate that the binary is 64-bit (e.g.,
ELF 64-bit LSB executable
).
By following these steps, the user can resolve the Makefile misconfiguration and ensure that the SQLite binary is built as a 64-bit version, eliminating the runtime errors related to 32/64-bit mismatches.