我想在我的linux架构系统上构建一个Windows应用程序(.exe
)。
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
#include <stdlib.h>
#include <regex.h>
int main()
{
//regcomp()...
//regexec()...
//regfree()...
}
$i686-w64-mingw32-gcc nc.c-o nc.exe(这不起作用)
nc.c:7:10: fatal error: regex.h: No such file or directory
#include <regex.h>
^~~~~~~~~
compilation terminated.
$gcc nc.c-o nc(这是工作)
无法用
.exe
生成i686-w64-mingw32-gcc
,这将显示关于#include <regex.h>
的错误。但是可以用'gcc'编译linux。
如何解决
i686-w64-mingw32-gcc
的问题?我还下载了
mingw-libgnurx-2.5.1-src.tar.gz
$./configure--host=x86_64-w64-mingw32
configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
checking for x86_64-w64-mingw32-gcc... x86_64-w64-mingw32-gcc
checking for C compiler default output file name... a.exe
checking whether the C compiler works... yes
checking whether we are cross compiling... yes
checking for suffix of executables... .exe
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether x86_64-w64-mingw32-gcc accepts -g... yes
checking for x86_64-w64-mingw32-gcc option to accept ANSI C... none needed
checking whether x86_64-w64-mingw32-gcc accepts the -mthreads option... yes
checking whether x86_64-w64-mingw32-gcc accepts the -mtune=pentium3 option... no
checking for x86_64-w64-mingw32-lib... no
checking for lib... no
configure: creating ./config.status
config.status: creating Makefile
$制造
x86_64-w64-mingw32-gcc -mthreads -g -O2 -I . -c -o regex.o regex.c
In file included from regex.c:61:0:
regex_internal.h:424:0: warning: "alloca" redefined
# define alloca(size) __builtin_alloca (size)
In file included from /usr/x86_64-w64-mingw32/include/stdlib.h:695:0,
from regex_internal.h:27,
from regex.c:61:
/usr/x86_64-w64-mingw32/include/malloc.h:183:0: note: this is the location of the previous definition
#define alloca(x) __builtin_alloca((x))
In file included from regex.c:64:0:
regcomp.c: In function ‘parse_dup_op’:
regcomp.c:2513:39: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx);
^
regcomp.c: In function ‘mark_opt_subexp’:
regcomp.c:3725:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
int idx = (int) (long) extra;
^
x86_64-w64-mingw32-gcc -mthreads -g -O2 -I . -shared -o libgnurx-0.dll -Wl,--enable-auto-image-base -Wl,--out-implib,libgnurx.dll.a regex.o
cp -p libgnurx.dll.a libregex.a
安装PCRE:
$sudo pacman-S个人电脑
warning: pcre-8.41-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
Packages (1) pcre-8.41-1
Total Installed Size: 3.38 MiB
Net Upgrade Size: 0.00 MiB
:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring [######################] 100%
(1/1) checking package integrity [######################] 100%
(1/1) loading package files [######################] 100%
(1/1) checking for file conflicts [######################] 100%
(1/1) checking available disk space [######################] 100%
:: Processing package changes...
(1/1) reinstalling pcre [######################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
$sudo pacman-第2版
warning: pcre2-10.23-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
Packages (1) pcre2-10.23-1
Total Installed Size: 3.22 MiB
Net Upgrade Size: 0.00 MiB
:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring [######################] 100%
(1/1) checking package integrity [######################] 100%
(1/1) loading package files [######################] 100%
(1/1) checking for file conflicts [######################] 100%
(1/1) checking available disk space [######################] 100%
:: Processing package changes...
(1/1) reinstalling pcre2 [######################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
最佳答案
您可以检查gnulib,看看它是否提供了与Windows兼容的<regex.h>
。PCRE已经被移植到Windows上,并且它提供了一个<regex.h>
replacement。PCRE还被打包用于Arch Linux的mingw-w64交叉编译,在mingw-w64-pcre2包中(因为您似乎正在使用archlinux)。
远离mingw-libgnurx-2.5.1-src.tar.gz
。警告显示它与x86-64不兼容,因为64位Windows上的long
仅为32位,正如警告所示,库作者显然没有预料到这一点。