在FreeBSD下,sqlite 3.7.17编译错误



StackOverflow的许多用户建议我迁移到SQlite,所以,我正在尝试,但不能,在FreeBSD下编译sqlite3源代码。出现以下错误:

sqlite3.c:23527: error: 'fchmod' undeclared here (not in a function)

系统:

FreeBSD 8.2-RELEASEgcc 4.2.1

有谁能提供建议吗?

注:我不能更新系统,因为它是一个工作的服务器。

man fchmod显示:

NAME
     chmod, fchmod, lchmod — change mode of file
LIBRARY
     Standard C Library (libc, -lc)
SYNOPSIS
     #include <sys/stat.h>

因此,您至少需要将#include <sys/stat.h>添加到失败文件(sqlite3.c)的顶部。可能有一个更好的头文件来包含它。您甚至可能发现它已经在那里了,但是被#ifdef隔离了。

Yasir是正确的,因为您应该使用您需要的所有已经移植的软件的移植。如果您不是自己管理服务器,您应该能够要求管理员为您安装数据库/sqlite3端口。

回到你实际的问题,很难知道为什么在你的情况下没有声明fchmod——它在<sys/stat.h>中声明。也许,您正在使用在一个平台(Linux?)上生成的Makefile在另一个平台(FreeBSD)上构建sqlite ?你不应该这样做——configure需要在本地运行。

SCO OpenServer 5.0.7上解决了sqlite3 3.33.0的相同构建错误(不同的行号)之后,修复所涉及的代码片段在提到fchmod() on OpenBSD的注释附近。假设FreeBSD可能类似于OpenBSD,也许这个问题的修复可能是因为_XOPEN_SOURCE没有定义。

/*
** We need to define _XOPEN_SOURCE as follows in order to enable
** recursive mutexes on most Unix systems and fchmod() on OpenBSD.
** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit
** it.
*/
#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__)
#  define _XOPEN_SOURCE 600
#endif

在合并源中,代码在sqliteInt.h中,

之间
/************** End of sqliteLimit.h *****************************************/
/************** Continuing where we left off in sqliteInt.h ******************/

/************** Include hash.h in the middle of sqliteInt.h ******************/
/************** Begin file hash.h ********************************************/

使用OpenBSD源代码的建议是有效的,因为这些源代码将被修补以解决特定于平台的构建问题。这个答案提供了一个可能的根本原因的潜在链接,因为这个问题出现在一个涉及解决几乎与问题中相同的错误消息的搜索中。

SCO OpenServer 5.0.7的情况下,与这个问题无关,但由于它在这个答案中被提到,并且可能出现在其他人的搜索结果中,在我的情况下的问题是相反的情况,其中_XOPEN_SOURCE导致了错误,需要一个补丁,如:

$ diff -u sqlite3.c.orig sqlite3.c
--- sqlite3.c.orig      2020-08-14 08:42:52.000000000 -0500
+++ sqlite3.c   2020-10-25 13:38:01.000000000 -0500
@@ -13633,10 +13633,11 @@
 /*
 ** We need to define _XOPEN_SOURCE as follows in order to enable
 ** recursive mutexes on most Unix systems and fchmod() on OpenBSD.
-** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit
-** it.
+** But _XOPEN_SOURCE define causes problems for Mac OS X, and for
+** SCO OpenServer 5.0.7, so omit it.
 */
-#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__)
+#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) 
+ && !defined(_SCO_DS)
 #  define _XOPEN_SOURCE 600
 #endif

编辑:对#include <sys/stat.h>的建议很可能是这个版本sqlite的最佳修复。对错误消息进行详细搜索,寻找在此问题的原始时间框架内的活动,发现许多其他用户有相同的问题,并得到相同的建议,即在sqlite3.c合并文件中合并更高的include语句。

最新更新