我需要这个项目的Windows可执行文件: https://github.com/ashkang/jcal
我尝试将所有.h和带有main
的.c文件添加到Qt Creator中的单个控制台非qt C ++项目中,但它会发出很多错误,例如:\jdate\jdate.c:-1 error: undefined reference to jlocaltime_r'
。
我还在项目中添加了jasctime_r.3
这样的未知文件。
如何在Windows中编译此项目?
答案 0 :(得分:0)
好吧,它确实有用,如果你使用它的GNU构建系统,但你做需要一些代码更改来解决Windows上缺少的功能。
localtime_r()
和gmtime_r()
可以替换为localtime_s()
和gmtime_s()
并且参数交换。strptime()
,您需要提供一个实施,如果您修复了#includes
并添加了#define TM_YEAR_BASE 1900
,则可以使用open source one。将固定的strptime.c
放在sources/libjalali
目录中并应用以下补丁:
diff --git a/sources/configure.ac b/sources/configure.ac
index e623ec9..409d9e7 100644
--- a/sources/configure.ac
+++ b/sources/configure.ac
@@ -66,4 +66,9 @@ if test $installpyjalali = "yes"; then
fi
AM_CONDITIONAL([WANT_PYJALALI], [test $installpyjalali = "yes"])
+case $host in
+ *mingw*) targetismingw=yes ;;
+esac
+AM_CONDITIONAL([MINGW], [test x$targetismingw = xyes])
+
AC_OUTPUT
diff --git a/sources/libjalali/Makefile.am b/sources/libjalali/Makefile.am
index 078c68a..64ef85d 100644
--- a/sources/libjalali/Makefile.am
+++ b/sources/libjalali/Makefile.am
@@ -5,6 +5,9 @@
lib_LTLIBRARIES = libjalali.la
libjalali_la_SOURCES = jalali.c jtime.c
+if MINGW
+libjalali_la_SOURCES += strptime.c
+endif
# 0:0:0
# 0 -> interface version, changes whenever you change the API
diff --git a/sources/libjalali/jalali.c b/sources/libjalali/jalali.c
index 49fc43f..6e3bdd9 100644
--- a/sources/libjalali/jalali.c
+++ b/sources/libjalali/jalali.c
@@ -28,6 +28,10 @@
#include "jalali.h"
#include "jconfig.h"
+#ifdef _WIN32
+#define localtime_r(timep, result) localtime_s((result), (timep))
+#endif
+
/*
* Assuming *factor* numbers of *lo* make one *hi*, cluster *lo*s and change
* *hi* appropriately. In the end:
@@ -49,7 +53,9 @@ const int jalali_month_len[] = { 31, 31, 31, 31, 31, 31, 30, 30, 30, 30,
const int accumulated_jalali_month_len[] = { 0, 31, 62, 93, 124, 155, 186,
216, 246, 276, 306, 336 };
+#ifndef _WIN32
extern char* tzname[2];
+#endif
/*
* Jalali leap year indication function. The algorithm used here
diff --git a/sources/libjalali/jtime.c b/sources/libjalali/jtime.c
index 319dbdd..ba8ec1a 100644
--- a/sources/libjalali/jtime.c
+++ b/sources/libjalali/jtime.c
@@ -27,6 +27,11 @@
#include "jalali.h"
#include "jtime.h"
+#ifdef _WIN32
+#define localtime_r(timep, result) localtime_s((result), (timep))
+#define gmtime_r(timep, result) gmtime_s((result), (timep))
+#endif
+
const char* GMT_ZONE = "UTC";
const char* GMT_ZONE_fa = "گرینویچ";
const char* jalali_months[] = { "Farvardin", "Ordibehesht", "Khordaad",
@@ -65,7 +70,9 @@ const char* tzname_fa[2] = { "زمان زمستانی", "زمان تابستان
static char in_buf[MAX_BUF_SIZE] = {0};
static struct jtm in_jtm;
+#ifndef _WIN32
extern char* tzname[2];
+#endif
extern const int jalali_month_len[];
void in_jasctime(const struct jtm* jtm, char* buf)
diff --git a/sources/libjalali/jtime.h b/sources/libjalali/jtime.h
index fd658f1..48b4d9a 100644
--- a/sources/libjalali/jtime.h
+++ b/sources/libjalali/jtime.h
@@ -56,6 +56,10 @@ extern struct jtm* jlocaltime_r(const time_t* timep, struct jtm* result);
extern int jalali_to_farsi(char* buf, size_t n, int padding, char* pad, int d);
+#ifdef _WIN32
+extern char *strptime(const char *buf, const char *fmt, struct tm *tm);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/sources/src/jdate.c b/sources/src/jdate.c
index 8a47e19..cae0329 100644
--- a/sources/src/jdate.c
+++ b/sources/src/jdate.c
@@ -34,6 +34,11 @@
#include "../libjalali/jtime.h"
#include "jdate.h"
+#ifdef _WIN32
+#define localtime_r(timep, result) localtime_s((result), (timep))
+#define gmtime_r(timep, result) gmtime_s((result), (timep))
+#endif
+
extern char* optarg;
/*
然后,获取msys2
,启动它的shell并安装包:
pacman -S mingw32/mingw-w64-i686-gcc msys/autoconf msys/automake msys/libtool
这应该足够了。
现在,您可以使用sources
目录中的以下命令来构建它:
autoreconf -i
./configure
make