在MINGW64下编译dhex?

时间:2019-03-07 13:56:33

标签: gcc linker mingw-w64 msys2

我已经从dhex_0.69.tar.gz下载了http://www.dettus.net/dhex/并解压了。自述文件只是说要运行make

当我尝试在Windows 10上的MSYS2 shell中构建它时,编译和链接没有任何问题,我得到了.exe,它可以正常工作:

user@PC MSYS /d/src/dhex_0.69
$ make
gcc buffers.c -c -I. -I/usr/include     -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc configfile.c -c -I. -I/usr/include  -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc correlation.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc gpl.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses -I/usr/local/include/ncurses -O3 -Wall
gcc hexcalc.c -c -I. -I/usr/include     -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc input.c -c -I. -I/usr/include       -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc machine_type.c -c -I. -I/usr/include        -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc main.c -c -I. -I/usr/include        -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc markers.c -c -I. -I/usr/include     -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc menu.c -c -I. -I/usr/include        -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc output.c -c -I. -I/usr/include      -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc search.c -c -I. -I/usr/include      -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc ui.c -c -I. -I/usr/include  -I/usr/local/include    -I/usr/include/ncurses -I/usr/local/include/ncurses -O3 -Wall
gcc -L/usr/lib  -L/usr/local/lib        -L/usr/lib/ncurses      -L/usr/local/lib/ncurses -o dhex buffers.o configfile.o correlation.o gpl.o hexcalc.o input.o machine_type.o main.o markers.o menu.o output.o search.o ui.o -lncurses

但是,当在MSYS Shell之外运行时,此.exe将依赖于msys-ncursesw6.dllmsys-2.0.dll(因此,在命令提示符cmd.exe中运行时,确实会错误-或在Power Shell中,它不会引发错误;程序只是在那里退出)。

因此,我想尝试在MINGW64中进行构建。编译完成,但有警告-由于undefined reference to '_impure_ptr',链接失败:

user@PC MINGW64 /d/src/dhex_0.69
$ make
gcc buffers.c -c -I. -I/usr/include     -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc configfile.c -c -I. -I/usr/include  -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc correlation.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
correlation.c: In function 'find_longestmatch':
correlation.c:41:28: warning: unknown conversion type character 'l' in format [-Wformat=]
   else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1));
                            ^
correlation.c:41:23: warning: too many arguments for format [-Wformat-extra-args]
   else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1));
                       ^~~~~~~~~~
correlation.c: In function 'find_bestmatch':
correlation.c:129:28: warning: unknown conversion type character 'l' in format [-Wformat=]
   else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1));
                            ^
correlation.c:129:23: warning: too many arguments for format [-Wformat-extra-args]
   else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1));
                       ^~~~~~~~~~
correlation.c: In function 'find_mindiff':
correlation.c:210:28: warning: unknown conversion type character 'l' in format [-Wformat=]
   else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1));
                            ^
correlation.c:210:23: warning: too many arguments for format [-Wformat-extra-args]
   else fprintf(stderr,"%16lli\r",((tInt64)buf1->bufsize-pos1));
                       ^~~~~~~~~~
gcc gpl.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses -I/usr/local/include/ncurses -O3 -Wall
gcc hexcalc.c -c -I. -I/usr/include     -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc input.c -c -I. -I/usr/include       -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
input.c: In function 'decinput':
input.c:116:27: warning: unknown conversion type character 'l' in format [-Wformat=]
   snprintf(tmpbuf,21,"%20lli",newval);
                           ^
input.c:116:22: warning: too many arguments for format [-Wformat-extra-args]
   snprintf(tmpbuf,21,"%20lli",newval);
                      ^~~~~~~~
gcc machine_type.c -c -I. -I/usr/include        -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc main.c -c -I. -I/usr/include        -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
main.c: In function 'main':
main.c:765:36: warning: unknown conversion type character 'l' in format [-Wformat=]
   if (gosearch1) fprintf(stderr,"%lli occurances found in %s\n",search1.occurancesfound,buf1->filename);
                                    ^
main.c:765:60: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'tInt64' {aka 'long long int'} [-Wformat=]
   if (gosearch1) fprintf(stderr,"%lli occurances found in %s\n",search1.occurancesfound,buf1->filename);
                                                           ~^    ~~~~~~~~~~~~~~~~~~~~~~~
                                                           %I64d
main.c:765:33: warning: too many arguments for format [-Wformat-extra-args]
   if (gosearch1) fprintf(stderr,"%lli occurances found in %s\n",search1.occurancesfound,buf1->filename);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:766:36: warning: unknown conversion type character 'l' in format [-Wformat=]
   if (gosearch2) fprintf(stderr,"%lli occurances found in %s\n",search2.occurancesfound,buf2->filename);
                                    ^
main.c:766:60: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'tInt64' {aka 'long long int'} [-Wformat=]
   if (gosearch2) fprintf(stderr,"%lli occurances found in %s\n",search2.occurancesfound,buf2->filename);
                                                           ~^    ~~~~~~~~~~~~~~~~~~~~~~~
                                                           %I64d
main.c:766:33: warning: too many arguments for format [-Wformat-extra-args]
   if (gosearch2) fprintf(stderr,"%lli occurances found in %s\n",search2.occurancesfound,buf2->filename);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc markers.c -c -I. -I/usr/include     -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
markers.c: In function 'writemarkerfile':
markers.c:94:21: warning: unknown conversion type character 'l' in format [-Wformat=]
   fprintf(f,"%c%016llX\n",markers->relative[i],markers->cursorpos[i]);
                     ^
markers.c:94:13: warning: too many arguments for format [-Wformat-extra-args]
   fprintf(f,"%c%016llX\n",markers->relative[i],markers->cursorpos[i]);
             ^~~~~~~~~~~~~
markers.c: In function 'gotomask':
markers.c:170:25: warning: unknown conversion type character 'l' in format [-Wformat=]
    snprintf(buf,17,"%c%llx",markers->relative[i],markers->cursorpos[i]);
                         ^
markers.c:170:20: warning: too many arguments for format [-Wformat-extra-args]
    snprintf(buf,17,"%c%llx",markers->relative[i],markers->cursorpos[i]);
                    ^~~~~~~~
gcc menu.c -c -I. -I/usr/include        -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc output.c -c -I. -I/usr/include      -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
gcc search.c -c -I. -I/usr/include      -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall
search.c: In function 'searchfor':
search.c:128:52: warning: unknown conversion type character 'l' in format [-Wformat=]
    if (search->writesearchlog) fprintf(fwlog,"%016llx\n",(tUInt64)actcursorpos+buf->baseaddr); else done=1;
                                                    ^
search.c:128:46: warning: too many arguments for format [-Wformat-extra-args]
    if (search->writesearchlog) fprintf(fwlog,"%016llx\n",(tUInt64)actcursorpos+buf->baseaddr); else done=1;
                                              ^~~~~~~~~~~
gcc ui.c -c -I. -I/usr/include  -I/usr/local/include    -I/usr/include/ncurses -I/usr/local/include/ncurses -O3 -Wall
gcc -L/usr/lib  -L/usr/local/lib        -L/usr/lib/ncurses      -L/usr/local/lib/ncurses -o dhex buffers.o configfile.o correlation.o gpl.o hexcalc.o input.o machine_type.o main.o markers.o menu.o output.o search.o ui.o -lncurses
correlation.o:correlation.c:(.rdata$.refptr._impure_ptr[.refptr._impure_ptr]+0x0): undefined reference to `_impure_ptr'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:27: dhex] Error 1

为了在MINGW64下编译dhex(所以它不再依赖MSYS dll了),有人知道我需要做什么吗?

1 个答案:

答案 0 :(得分:0)

我下载了该软件包,并弄清楚了如何使用MSYS2提供的MinGW-w64 64位工具链进行编译。

首先,安装相关的开发工具和库:

options['continuation']

接下来,您需要编辑软件包随附的Makefile。 LDFLAGS,CPPFLAGS和CFLAGS值必须修改为以下值:

'x-ms-continuation'

一些解释:Makefile在LDFLAGS和CPPFLAGS中具有硬编码的路径是非常糟糕的,因为如果要使用这些路径,则将使用来自另一个工具链(基于msys-2.0.dll的工具链)中的文件。因此,我们需要摆脱这些。另外,要摆脱有关printf格式的所有警告,我们必须提供pacman -S base-devel mingw-w64-x86_64-{ncurses,toolchain} 参数。

然后,只需运行LDFLAGS= CPPFLAGS= -I$(MINGW_PREFIX)/include/ncurses CFLAGS= -D__USE_MINGW_ANSI_STDIO=1 -O3 -Wall