参考博客:移植libzdb3.2.2到arm_configure: error: no available database found or s_酣楼驻海的博客-CSDN博客
编译时间 2023-08-23
源码访问如下:
https://bitbucket.org/tildeslash/libzdb/src/master/
git 下载链接
git clone https://bitbucket.org/tildeslash/libzdb.git
我将其同步到了 gitee,然后从 gitee 上下载的;
使用 ubuntu 18.04 版本;
在以下链接下载了 arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-linux-gnueabihf 交叉编译器;
https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
1.源码下载后文件内容如下:
user:libzdb$ls
AUTHORS bootstrap CHANGES config configure.ac COPYING doc libzdb.xcodeproj Makefile.am README src test tools zdb.pc.in
2.执行 bootstrap 生成 configure 文件
user:libzdb$./bootstrap
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config'.
libtoolize: linking file 'config/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: linking file 'm4/libtool.m4'
libtoolize: linking file 'm4/ltoptions.m4'
libtoolize: linking file 'm4/ltsugar.m4'
libtoolize: linking file 'm4/ltversion.m4'
libtoolize: linking file 'm4/lt~obsolete.m4'
configure.ac:46: installing 'config/compile'
configure.ac:103: installing 'config/config.guess'
configure.ac:103: installing 'config/config.sub'
configure.ac:8: installing 'config/install-sh'
configure.ac:8: installing 'config/missing'
Success
user:libzdb$ls
aclocal.m4 autom4te.cache CHANGES configure COPYING libzdb.xcodeproj Makefile.am README test zdb.pc.in
AUTHORS bootstrap config configure.ac doc m4 Makefile.in src tools
3.使用 configure 来生成 Makefile
遇到问题1:configure: error: cross-compiling: please set 'libzdb_cv_setjmp_available=yes|no'
user:libzdb$./configure --host=arm-none-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-linux-gnueabihf-strip... arm-none-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
......................
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking setjmp is available... configure: error: cross-compiling: please set 'libzdb_cv_setjmp_available=yes|no'
使用如下代码来判断是否支持 setjmp;交叉编译后在目标平台上执行,如果两个 printf 都打印就支持;
#include
#include
jmp_buf jump_buffer;
void test_jump() {
longjmp(jump_buffer, 1);
}
int main() {
if (setjmp(jump_buffer) == 0) {
printf("Calling test_jump()\n");
test_jump();
} else {
printf("Back from test_jump()\n");
}
return 0;
}
4.使用新的命令编译,遇到问题2
libzdb_cv_setjmp_available=yes ./configure --host=arm-none-linux-gnueabihf
问题2:configure: error: cross-compiling: please set 'libzdb_cv_vsnprintf_c11_conformant=yes|no'
user:libzdb$libzdb_cv_setjmp_available=yes ./configure --host=arm-none-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-linux-gnueabihf-strip... arm-none-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
................
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking setjmp is available... (cached) yes
checking vsnprintf is c11 conformant... configure: error: cross-compiling: please set 'libzdb_cv_vsnprintf_c11_conformant=yes|no'
使用如下代码来判断是否支持 vsnprintf;交叉编译后在目标平台上执行,如果正常打印就支持;
#include
#include
void custom_printf(const char *format, ...) {
char buffer[100];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
printf("%s", buffer);
}
int main() {
custom_printf("Hello %s, you have %d messages.\n", "Alice", 5);
return 0;
}
5.使用新的命令编译,遇到问题3
libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf
问题3:configure: error: No available database found or selected. Try configure --help
user:libzdb$libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-linux-gnueabihf-strip... arm-none-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
...............................
checking for SQLite3... yes
checking for library containing sqlite3_open... no
checking for mysql... yes
checking for mysql_config... no
configure: WARNING: mysql_config is required to build libzdb with mysql
checking for oracle... checking if Oracle support is enabled... no
configure: error: No available database found or selected. Try configure --help
需要指定数据库,使用了 --with-sqlite
6.使用新的命令编译,遇到问题4
libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf --with-sqlite
问题4:configure: error: cannot check for file existence when cross compiling
user:libzdb$libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf --with-sqlite
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-linux-gnueabihf-strip... arm-none-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables
...............................
checking for timegm... yes
checking for library containing pthread_create... none required
checking for postgresql... yes
checking for pg_config... no
configure: WARNING: pg_config is required to build libzdb with postgresql
checking for SQLite3... yes
checking for yes... configure: error: cannot check for file existence when cross compiling
修改 configure 文件,将含有 "cannot check for file existence when cross compiling" 的行给注释掉,我一共注释了三行;
7.继续编译,遇到问题5
libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf --with-sqlite
问题5:configure: error: No available database found or selected. Try configure --help
user:libzdb$libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf --with-sqlite
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-linux-gnueabihf-strip... arm-none-linux-gnueabihf-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
...............................
configure: WARNING: pg_config is required to build libzdb with postgresql
checking for SQLite3... yes
checking for yes... no
checking for library containing sqlite3_open... no
checking for mysql... yes
checking for mysql_config... no
configure: WARNING: mysql_config is required to build libzdb with mysql
checking for oracle... checking if Oracle support is enabled... no
configure: error: No available database found or selected. Try configure --help
需要指定 sqlite3 库的路径,文件放置如下:
user:sqlite3_bin$tree
.
├── include
│ └── sqlite3.h
└── lib
├── libsqlite3.so -> libsqlite3.so.0.8.6
├── libsqlite3.so.0 -> libsqlite3.so.0.8.6
└── libsqlite3.so.0.8.6
修改 --with-sqlite 为 --with-sqlite=/opt/liangtao/libs/sqlite3_bin/
8. 使用新命令编译,配置成功
libzdb_cv_setjmp_available=yes libzdb_cv_vsnprintf_c11_conformant=yes ./configure --host=arm-none-linux-gnueabihf --with-sqlite=/opt/liangtao/libs/sqlite3_bin/
9. 直接 make 遇到问题 6
问题6:./tools/bin/filterh < src/zdb.h > zdb/zdb.h || exit 1
user:libzdb$make
./tools/bin/filterh < src/zdb.h > zdb/zdb.h || exit 1
/lib/ld-linux-armhf.so.3: No such file or directory
Makefile:1248: recipe for target 'zdb/zdb.h' failed
make: *** [zdb/zdb.h] Error 1
user:libzdb$
由于 filterh 是 arm 格式的,所以遇到该问题;
解决方法:重新下载一份源码,在源码顶层目录,直接运行以下命令,报错不用处理;
./bootstrap && ./configure
将 x86 的 ./tools/bin/filterh 替换交叉编译器相同的目录下的 filterh 文件;
user:libtmp$ls -al ./tools/bin/filterh
-rwxrwxr-x 1 vmuser vmuser 23568 Aug 23 16:15 ./tools/bin/filterh
user:libtmp$file ./tools/bin/filterh
./tools/bin/filterh: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=27cebe5d15f6c87b477fb1e0f69e283428cc4288, not stripped
10. 继续编译遇到问题 7
问题7:re2c: error: line 201, column 22: unrecognized configuration 'eof'
user:libzdb$make
./tools/bin/filterh < src/zdb.h > zdb/zdb.h || exit 1
./tools/bin/filterh < src/zdbpp.h > zdb/zdbpp.h || exit 1
./tools/bin/filterh < src/db/ConnectionPool.h > zdb/ConnectionPool.h || exit 1
./tools/bin/filterh < src/db/Connection.h > zdb/Connection.h || exit 1
./tools/bin/filterh < src/db/ResultSet.h > zdb/ResultSet.h || exit 1
./tools/bin/filterh < src/net/URL.h > zdb/URL.h || exit 1
./tools/bin/filterh < src/db/PreparedStatement.h > zdb/PreparedStatement.h || exit 1
./tools/bin/filterh < src/exceptions/SQLException.h > zdb/SQLException.h || exit 1
./tools/bin/filterh < src/exceptions/Exception.h > zdb/Exception.h || exit 1
.................
ystem/System.c -o src/system/System.o >/dev/null 2>&1
/usr/bin/re2c -i src/system/Time.re > src/system/Time.c
re2c: error: line 201, column 22: unrecognized configuration 'eof'
Makefile:1261: recipe for target 'src/system/Time.c' failed
make[2]: *** [src/system/Time.c] Error 1
.................
Makefile:505: recipe for target 'all' failed
make: *** [all] Error 2
将文件 src/system/Time.re line 201 删除
11.继续编译遇到问题 8
user:libzdb$make
make all-recursive
make[1]: Entering directory '/opt/liangtao/libs/libzdb'
Making all in .
make[2]: Entering directory '/opt/liangtao/libs/libzdb'
/usr/bin/re2c -i src/system/Time.re > src/system/Time.c
re2c: error: line 211, column 17: unexpected character: '$'
接着将报错的行删除;
总的修改后 src/system/Time.re 文件如下:
diff --git a/src/system/Time.re b/src/system/Time.re
index 5b092e4..7b355ac 100644
--- a/src/system/Time.re
+++ b/src/system/Time.re
@@ -198,7 +198,6 @@ struct tm *Time_toDateTime(const char *s, struct tm *t) {
re2c:define:YYLIMIT = limit;
re2c:define:YYMARKER = marker;
re2c:yyfill:enable = 0;
- re2c:eof = 0;
re2c:flags:case-insensitive = 1;
any = [\000-\377];
@@ -209,10 +208,6 @@ struct tm *Time_toDateTime(const char *s, struct tm *t) {
frac = [.,][0-9]+;
mmm = ("jan"|"feb"|"mar"|"apr"|"may"|"jun"|"jul"|"aug"|"sep"|"oct"|"nov"|"dec");
- $
- { // EOF
- THROW(SQLException, "Invalid date or time");
- }
yyyy x dd x dd
{ // Date: YYYY-MM-DD
12. 继续编译,后面遇到链接报错,没有在意,因为库文件已经编出;
user:libzdb$ls -a ./.libs/
. .. libzdb.a libzdb.la libzdb.lai libzdb.so libzdb.so.13 libzdb.so.13.1.0
user:libzdb$file ./.libs/libzdb.so.13.1.0
./.libs/libzdb.so.13.1.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped
注:删除的代码带来的影响不知;