首页 > 代码库 > 使用Cygwin在Windows下帮助编译众多C/C++库(附make: command not found,以及libtool.m4 and ltmain.sh have a version mismatch问题的解决方案)

使用Cygwin在Windows下帮助编译众多C/C++库(附make: command not found,以及libtool.m4 and ltmain.sh have a version mismatch问题的解决方案)

之前为了使用一个库,都是去下载源码,然后根据开发者提供的README手动用GCC编译,一直不能使用Makefile感觉很蛋痛,比如最近使用的ZThread

还是怪自己以前过于依赖IDE

 

最近发现用Cygwin就可以使用诸如./configure, make这样的命令,感觉灰常欣喜,尝试去编译ZThread库(因为我发现虽然之前我用GCC手动编译了ZThread但是在使用的过程中,ZThread总是往控制台上打印诸多的DEBUG信息,想必是编译选项的问题,我又不知道到哪个头文件中去找#define DEBUG,所以就想使用make,看使用ZThread作者写的configuration文件以及Makefile来编译能不能解决问题)

 

刚刚下载下来Cygwin就等着上去configure+make呢,问题就来了,输入./configure之后,等了一段时间报错(见红色文字):

$ ./configurechecking build system type... i686-pc-cygwinchecking host system type... i686-pc-cygwinchecking target system type... i686-pc-cygwinchecking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for gawk... gawkchecking whether make sets $(MAKE)... yesLoading m4 macros from sharechecking for g++... g++checking for C++ compiler default output file name... a.exechecking whether the C++ compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables... .exechecking for suffix of object files... ochecking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking for style of include used by make... GNUchecking dependency style of g++... gcc3checking for gcc... gccchecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ANSI C... none neededchecking dependency style of gcc... gcc3checking how to run the C preprocessor... gcc -Echecking for egrep... grep -Echecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yeschecking pthread.h usability... nochecking pthread.h presence... nochecking for pthread.h... nochecking for sched_get_priority_max in -lrt... nochecking for sched_yield... nochecking for pthread_yield... nochecking for pthread_key_create... nochecking for pthread_keycreate... nochecking for doxygen... nodetecting for ftime() functionchecking sys/time.h usability... yeschecking sys/time.h presence... yeschecking for sys/time.h... yeschecking for _ftime()... yeschecking how to run the C++ preprocessor... g++ -Echecking for ANSI C header files... (cached) yeschecking errno.h usability... yeschecking errno.h presence... yeschecking for errno.h... yeschecking for target implementation... compile-time guesschecking for sigsetjmp()... nochecking for _beginthreadex()... nochecking for a sed that does not truncate output... /usr/bin/sedchecking for ld used by gcc... d:/mingw/mingw32/bin/ld.exechecking if the linker (d:/mingw/mingw32/bin/ld.exe) is GNU ld... yeschecking for d:/mingw/mingw32/bin/ld.exe option to reload object files... -rchecking for BSD-compatible nm... /cygdrive/d/MinGW/bin/nm -Bchecking whether ln -s works... yeschecking how to recognise dependent libraries... file_magic ^x86 archive import|^x86 DLLchecking dlfcn.h usability... nochecking dlfcn.h presence... nochecking for dlfcn.h... nochecking how to run the C++ preprocessor... g++ -Echecking for g77... nochecking for f77... nochecking for xlf... nochecking for frt... nochecking for pgf77... nochecking for fort77... nochecking for fl32... nochecking for af77... nochecking for f90... nochecking for xlf90... nochecking for pgf90... nochecking for epcf90... nochecking for f95... nochecking for fort... nochecking for xlf95... nochecking for ifc... nochecking for efc... nochecking for pgf95... nochecking for lf95... nochecking for gfortran... nochecking whether we are using the GNU Fortran 77 compiler... nochecking whether  accepts -g... nochecking the maximum length of command line arguments... 8192checking command to parse /cygdrive/d/MinGW/bin/nm -B output from gcc object... okchecking for objdir... .libschecking for ar... archecking for ranlib... ranlibchecking for strip... stripchecking for correct ltmain.sh version... grep: character class syntax is [[:space:]], not [:space:]no*** Gentoo sanity check failed! ****** libtool.m4 and ltmain.sh have a version mismatch! ****** (libtool.m4 = 1.5.10, ltmain.sh = ) ***Please run:  libtoolize --copy --forceif appropriate, please contact the maintainer of thispackage (or your distribution) for help.

输入:libtoolize --copy --force提示libtoolize: command not found

咋办?搜了一下相关的问题,原来是因为安装Cygwin的时候没有安装libtool

重新运行Cygwin-setup(注意,无需卸载,重新运行setup,选择你没有安装的package即可),搜索libtool,勾选并安装,问题解决

 

然后再次运行libtoolize --copy --force,又报错:

$ libtoolize --copy --forcelibtoolize: putting auxiliary files in `.‘.libtoolize: copying file `./ltmain.sh‘libtoolize: You should add the contents of the following files to `aclocal.m4‘:libtoolize:   `/usr/share/aclocal/libtool.m4‘libtoolize:   `/usr/share/aclocal/ltoptions.m4‘libtoolize:   `/usr/share/aclocal/ltversion.m4‘libtoolize:   `/usr/share/aclocal/ltsugar.m4‘libtoolize:   `/usr/share/aclocal/lt~obsolete.m4‘libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])‘ to configure.ac andlibtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.libtoolize: Consider adding `-I m4‘ to ACLOCAL_AMFLAGS in Makefile.am.

又搜了一下,在这篇BLOG说是因为没安装autoconf的原因,再回去安装autoconf,如图

 

再试一次./configure

 

然后输入make install又提示make: command not found

还是同样的套路,把make package给勾选安装就行了

 

使用Cygwin在Windows下帮助编译众多C/C++库(附make: command not found,以及libtool.m4 and ltmain.sh have a version mismatch问题的解决方案)