mitlm / mitlm

MIT Language Modeling Toolkit
BSD 3-Clause "New" or "Revised" License
115 stars 55 forks source link

building mitlm in Cygwin 64 on Win 10 #64

Closed spaniard81 closed 7 years ago

spaniard81 commented 7 years ago

Hi,

Could anyone who has successfully compiled and built mitlm in Cygwin64 environment share their environment configurations and steps for building?

I am getting linking errors during the "make" and they might have to do with "g77" which is no longer available for Cygwin64 and has been replaced by "gfortran". The linking errors refer to fortran files (lbfgs.f) and look like:

libtool: link: g++ -std=gnu++11 -g -O2 -o .libs/evaluate-ngram.exe src/evaluate-ngram.o  ./.libs/libmitlm.a
./.libs/libmitlm.a(lbfgs.o): In function `lb1_':
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:462: undefined reference to `s_wsfe'
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:462:(.text+0xaf): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `s_wsfe'
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:462: undefined reference to `e_wsfe'
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:462:(.text+0xb4): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `e_wsfe'
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:469: undefined reference to `s_wsfe'
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:469:(.text+0xcc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `s_wsfe'
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgs.f:469: undefined reference to `do_fio'...
...
...
./.libs/libmitlm.a(lbfgsb.o): In function `setulb_':
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgsb.f:196: undefined reference to `s_cmp'
./.libs/libmitlm.a(lbfgsb.o): In function `prn1lb_':
/home/spaniard/mitlm-master-mybuild/src/optimize/lbfgsb.f:2652: undefined reference to `e_wsfe'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:915: evaluate-ngram.exe] Fehler 1
make[1]: Verzeichnis „/home/spaniard/mitlm-master-mybuild“ wird verlassen
make: *** [Makefile:1114: all-recursive] Fehler 1

----------------------autogen.sh----------------------------------- The Output for ./autogen.sh looked mostly fine except the status of "g77" and a WARNING on not knowing how to link Information from f77. Google search said, this can be ignored.

checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
**checking for g77... no
checking for xlf... no**
checking for f77... f77
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether f77 accepts -g... yes
checking build system type... x86_64-unknown-cygwin
checking host system type... x86_64-unknown-cygwin
**checking how to get verbose linking output from f77... configure: WARNING: cannot determine how to obtain linking information from f77**
checking for Fortran 77 libraries of f77...
checking for dummy main to link with Fortran 77 libraries... none
checking for Fortran 77 name-mangling scheme... lower case, underscore, extra underscore

My environment details are as follows:

Win 10 , 64 bit
Cygwin64  2.8.2(0.313/5/3)
mitlm 0.4.2
autoconf-2.69-3
automake-1.14/aclocal-1.14
libtool 2.4.6-4
autoconf-archive          2017.03.21-1
gcc-core                                5.4.0-1                
gcc-fortran                             6.3.0-2               
gcc-g++                                 5.4.0-1     

Would appreciate any help with this.

Cheers.

spaniard81 commented 7 years ago

Okay, so I managed to compile it on Win10, cygwin . Here are the complete steps:

Environment settings:

Win 10 , 64 bit
 Cygwin64 2.8.2(0.313/5/3)
 mitlm 0.4.2
 autoconf-2.69-3
 automake-1.14/aclocal-1.14
 libtool 2.4.6-4
 autoconf-archive 2017.03.21-1
 gcc-core 5.4.0-1
 gcc-fortran 6.3.0-2
 gcc-g++ 5.4.0-1

Compilation steps

$ ./autogen.sh

Warning: I am going to run configure' with no arguments. If you wish to pass any to it, please specify them on the ./autogen.sh' command line.

processing . Running libtoolize... libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'. libtoolize: copying file 'build-aux/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/ltsugar.m4' libtoolize: '/usr/share/aclocal/ltversion.m4' libtoolize: '/usr/share/aclocal/lt~obsolete.m4' libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac, libtoolize: and rerunning libtoolize and aclocal. libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am. Running aclocal ... Running automake --gnu ... Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /usr/bin/automake-1.14 line 3930. configure.ac:25: installing 'build-aux/ar-lib' configure.ac:17: installing 'build-aux/compile' configure.ac:21: installing 'build-aux/config.guess' configure.ac:21: installing 'build-aux/config.sub' configure.ac:12: installing 'build-aux/install-sh' configure.ac:12: installing 'build-aux/missing' Makefile.am: installing 'build-aux/depcomp' parallel-tests: installing 'build-aux/test-driver' Running autoconf ... Running ./configure --enable-maintainer-mode ... checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether to enable maintainer-specific portions of Makefiles... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.exe checking for suffix of executables... .exe checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking dependency style of g++... gcc3 checking for g77... no checking for xlf... no checking for f77... f77 checking whether we are using the GNU Fortran 77 compiler... yes checking whether f77 accepts -g... yes checking build system type... x86_64-unknown-cygwin checking host system type... x86_64-unknown-cygwin checking how to get verbose linking output from f77... configure: WARNING: cannot determine how to obtain linking information from f77

checking for Fortran 77 libraries of f77... checking for dummy main to link with Fortran 77 libraries... none checking for Fortran 77 name-mangling scheme... lower case, underscore, extra underscore checking for ar... ar checking the archiver (ar) interface... ar checking for as... as checking for dlltool... dlltool checking for objdump... objdump checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /usr/x86_64-pc-cygwin/bin/ld.exe checking if the linker (/usr/x86_64-pc-cygwin/bin/ld.exe) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 8192 checking how to convert x86_64-unknown-cygwin file names to x86_64-unknown-cygwin format... func_convert_file_noop checking how to convert x86_64-unknown-cygwin file names to toolchain format... func_convert_file_noop checking for /usr/x86_64-pc-cygwin/bin/ld.exe option to reload object files... -r checking for objdump... (cached) objdump checking how to recognize dependent libraries... file_magic ^x86 archive import|^x86 DLL checking for dlltool... (cached) dlltool checking how to associate runtime and link libraries... func_cygming_dll_for_implib checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for sysroot... no checking for a working dd... /usr/bin/dd checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -DDLL_EXPORT -DPIC checking if gcc PIC flag -DDLL_EXPORT -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/x86_64-pc-cygwin/bin/ld.exe) supports shared libraries... yes checking whether -lc should be explicitly linked in... yes checking dynamic linker characteristics... Win32 ld.exe checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking how to run the C++ preprocessor... g++ -E checking for ld used by g++... /usr/x86_64-pc-cygwin/bin/ld.exe checking if the linker (/usr/x86_64-pc-cygwin/bin/ld.exe) is GNU ld... yes checking whether the g++ linker (/usr/x86_64-pc-cygwin/bin/ld.exe) supports shared libraries... yes checking for g++ option to produce PIC... -DDLL_EXPORT -DPIC checking if g++ PIC flag -DDLL_EXPORT -DPIC works... yes checking if g++ static flag -static works... yes checking if g++ supports -c -o file.o... yes checking if g++ supports -c -o file.o... (cached) yes checking whether the g++ linker (/usr/x86_64-pc-cygwin/bin/ld.exe) supports shared libraries... yes checking dynamic linker characteristics... Win32 ld.exe checking how to hardcode library paths into programs... immediate checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking for f77 option to produce PIC... -DDLL_EXPORT checking if f77 PIC flag -DDLL_EXPORT works... yes checking if f77 static flag -static works... yes checking if f77 supports -c -o file.o... yes checking if f77 supports -c -o file.o... (cached) yes checking whether the f77 linker (/usr/x86_64-pc-cygwin/bin/ld.exe) supports shared libraries... yes checking dynamic linker characteristics... Win32 ld.exe checking how to hardcode library paths into programs... immediate checking for string.h... (cached) yes checking math.h usability... yes checking math.h presence... yes checking for math.h... yes checking for ANSI C header files... (cached) yes checking for tr1/unordered_map... yes checking whether g++ supports C++11 features by default... no checking whether g++ supports C++11 features with -std=c++11... yes checking for inline... inline checking wheter we have __builtin_clzl... yes checking wheter we have X86_ASM... no checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating tests/test1.test config.status: executing depfiles commands config.status: executing libtool commands Now type `make' to compile.


In file included from src/NgramModel.h:40:0,
                 from src/NgramLM.cpp:41:
src/util/ZFile.h: In Elementfunktion »FILE* mitlm::ZFile::processOpen(const string&, const char*)«:
src/util/ZFile.h:165:41: Fehler: »popen« wurde in diesem Gültigkeitsbereich nicht definiert
     { return popen(command.c_str(), mode); }
                                         ^
make[1]: *** [Makefile:993: src/NgramLM.lo] Fehler 1
make[1]: Verzeichnis „/home/spaniard/mitlm-master“ wird verlassen
make: *** [Makefile:1112: all-recursive] Fehler 1

To fix this I followed the comments on another issue here https://github.com/mitlm/mitlm/issues/63 and modifed the CXX and CXXCPP vars as follows:

CXX = g++ -std=gnu++11
#CXX = g++ -std=c++11
CXXCPP = g++ -E -std=gnu++11
#CXXCPP = g++ -E -std=c++11

And then make again follwing the clean

$ make clean
$ make
...
...
libtool: link: g++ -std=gnu++11 -g -O2 -o .libs/evaluate-ngram.exe src/evaluate-ngram.o  ./.libs/libmitlm.a
./.libs/libmitlm.a(lbfgs.o): In function `lb1_':
/home/FIXCEIN/mitlm-master-16Aug/src/optimize/lbfgs.f:462: undefined reference to `s_wsfe'
/home/FIXCEIN/mitlm-master-16Aug/src/optimize/lbfgs.f:462:(.text+0xaf): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `s_wsfe'
/home/FIXCEIN/mitlm-master-16Aug/src/optimize/lbfgs.f:462: undefined reference to `e_wsfe'
/home/FIXCEIN/mitlm-master-16Aug/src/optimize/lbfgs.f:462:(.text+0xb4): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `e_wsfe'
/home/FIXCEIN/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `s_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0xcc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `s_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0xe1): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0xf6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0x110): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0x125): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0x13f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `do_fio'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469: undefined reference to `e_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:469:(.text+0x144): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `e_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:483: undefined reference to `s_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:483:(.text+0x172): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `s_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:483: undefined reference to `e_wsfe'
/home/spaniard/mitlm-master-16Aug/src/optimize/lbfgs.f:483:(.text+0x177): additional relocation overflows omitted from the output
/
F77 = gfortran 
FLIBS = -lgfortran
LDFLAGS = -L/usr/lib/gcc/x86_64-pc-cygwin/6.3.0/

And make again

$ make clean
$ make
 ...
 ...
 /bin/sh ./libtool  --tag=CXX   --mode=link g++ -std=gnu++11  -g -O2  -L/usr/lib/gcc/x86_64-pc-cygwin/6.3.0/  -o interpolate-ngram.exe src/interpolate-ngram.o libmitlm.la -lgfortran
libtool: link: g++ -std=gnu++11 -g -O2 -o .libs/interpolate-ngram.exe src/interpolate-ngram.o  -L/usr/lib/gcc/x86_64-pc-cygwin/6.3.0/ ./.libs/libmitlm.a -lgfortran

Yeah! libmitlm.a build successful.

$ ls .libs/
estimate-ngram.exe          evaluate-ngram_ltshwrapper     libmitlm.a    lt-estimate-ngram.c
estimate-ngram_ltshwrapper  interpolate-ngram.exe          libmitlm.la   lt-evaluate-ngram.c
evaluate-ngram.exe          interpolate-ngram_ltshwrapper  libmitlm.lai  lt-interpolate-ngram.c

Test mitlm executables.

MSDOS$ estimate-ngram.exe -text Test_MITLM.txt -write-lm Test_MITLM.lm
0.000   Loading corpus Test_MITLM.txt...
0.000   Smoothing[1] = ModKN
0.000   Smoothing[2] = ModKN
0.000   Smoothing[3] = ModKN
0.000   Set smoothing algorithms...
0.000   Y 8.333333e-01
0.000   Y 1.000000e+00
0.000   Y 1.000000e+00
0.000   Estimating full n-gram model...
0.000   Saving LM to Test_MITLM.lm...

-------------Done---------------------------------