Compiling under Windows: Difference between revisions

From iMath
Jump to navigation Jump to search
mNo edit summary
 
(45 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Preparing the Openoffice SDK with Microsoft Visual C++ ==


To build iMath for Windows, you need the Windows Openoffice SDK.
'''This section has ''not'' been maintained for a long time!
'''
 
== Compiling with Cygwin ==
 
I wasn't able to get a stable build with Cygwin, but here is what I did.
 
=== Preparing the Cygwin environment ===
 
Since LibreOffice for Windows is being built through Cygwin, it is best to set up the environment as described on the [https://wiki.documentfoundation.org/Development/BuildingOnWindows LibreOffice build page]. Of course, you can skip the downloading of the Office source code.
 
For some reason CLN expects time.h to be in the subdirectory sys. Copy it from your Visual Studio Installation directory\VC\include\time.h to sys\time.h in the same directory.
 
Take care not to install the gcc compiler when you install Cygwin, as it takes precedence of MSVC. You can check this by running the Cygwin setup.exe, searching for the packages gcc-core and gcc-g++, and uninstalling them if necessary.
 
Run the Cygwin setup.exe, and include the package gettext-devel.
 
Setup the cygwin.bat (usually found in C:\cygwin) to set the MSVC environment variables before running the Cygwin shell. Insert the following call before the last line:
 
<code>call "%VS120COMNTOOLS%\vsvars32.bat"</code>
 
Note that depending on your version of Visual Studio the 120 might be another number. Run
 
<code>cmd.exe</code>
 
<code>set</code>
 
to see what variable is available on your system.
 
=== Compiling with Microsoft Visual C++ ===
 
==== Compiling CLN ====
 
Get the CLN sourcecode from the [http://www.ginac.de/cln CLN website]. Bring up a Cygwin shell by calling the cygwin.bat file. Change to the source directory. Run <code>autoreconf -i</code> and <code>./configure CPPFLAGS="-MD -DNO_ASM -EHsc" --prefix=/usr</code>. Check in the output of configure that cl.exe is found as the C compiler.
 
Run <code>make</code>. It will probably stop and complain about missing files base/digitseq/cl_asm.obj and polynomial/elem/cl_asm_GF2.obj. Remove the files base/digitseq/cl_asm.lo and polynomial/elem/cl_asm_GF2.lo. Run <code>make base/digitseq/cl_asm.lo</code>. It will fail again but you can see the command that was issued. Copy this command exactly, adding the flag <code>-TC</code> before <code>-c</code> (this will enable MSVC to recognize the extension <code>.S</code> as a valid source file extension). Repeat for cl_asm_GF2.obj. This should create cl_asm.obj and cl_asm_GF2.obj (if not, repeat the procedure).
 
Run <code>make</code> to finish the build, <code>make check</check> do run some tests on the library, and <code>make install</code> to install it.
 
==== Compiling GiNaC ====
 
Get the GiNaC sourcecode from the [http://www.ginac.de GiNaC website]. Run <code>autoreconf -i</code> and <code>./configure CPPFLAGS="-MD -DNO_ASM -EHsc" --prefix=/usr</code>. Add the Cygwin include and library directory to the end of the corresponding paths:
 
<code>
export INCLUDE="$INCLUDE;C:\cygwin\usr\include"
 
export LIB="$LIB;C:\cygwin\lib"
</code>.
 
Run <code>make</code>. Compilation will probably stop in the ginsh subdirectory with a message about isatty. Since we don't need ginsh you can just change to that subdirectoy and run <code>make -t</code>.
 
In the check (and other subdirectories), when linking fails edit the Makefile and add the following to the command starting with CXXLINK: <code>cln.lib</code>. This is necessary because the package config file cln.pc is in Unix format and cl cannot find the library which is specified there by <code>-lcln</code>
 
Run <code>make check</code> and ensure that all checks pass.
 
Run <code>make install</code>.
 
==== Compiling EQC ====
 
Get the EQC sourcecode from Sourceforge. Run <code>autoreconf -i</code> and <code>./configure CPPFLAGS="-MD -EHsc" --prefix=/usr</code>.
 
Run <code>make</code>
 
In the src subdirectory, after linking of eqc.exe fails, edit the Makefile and add the following to the command starting with CXXLINK: <code>cln.lib ginac.lib</code> (if you add it before, creation of the eqc library fails instead...).
 
==== Compiling iMath ====
 
Run setsdkenv_windows.bat from the Office SDK directory to configure your environment. This should create a custom batch file somewhere in your home directory (usually AppData\Roaming\office4.3_sdk). Give it the linux-style paths to the make and zip executables etc. Do NOT give it any paths with spaces - make will choke on them. Use the Windows 8.3 filenames instead. You can see them with dir /x.
Add the setting <code>set OSTYPE=cygwin</code> manually to this file to fix some problems in the make process.
 
Here are example settings that work for me (note that this is only the beginning of the file!):
  set OO_SDK_NAME=libreoffice4.3_sdk
  set OO_SDK_HOME=C:\PROGRA~1\LIBREO~1\sdk
  set OFFICE_HOME=C:\PROGRA~1\LIBREO~1
  set OO_SDK_URE_HOME=C:\PROGRA~1\LIBREO~1\URE
  set OO_SDK_MAKE_HOME=C:\cygwin\opt\lo\bin
  set OO_SDK_ZIP_HOME=/usr/bin
  set OO_SDK_CAT_HOME=/usr/bin
  set OO_SDK_SED_HOME=/usr/bin
  set OO_SDK_CPP_HOME=C:\PROGRA~1\MICROS~1.0\VC\bin
  set CPP_MANIFEST=
  set CPP_WINDOWS_SDK=
  set OO_SDK_CLI_HOME=C:\Windows\Microsoft.NET\Framework\v2.0.50727
  set OO_SDK_JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45
  set OO_SDK_OUT=c:\libreoffice4.3_sdk
  set OSTYPE=cygwin
 
Add this batch file to Cygwin.bat. Here is what my Cygwin.bat looks like:
  @echo off
  C:
  chdir C:\cygwin\bin
  call "C:\Users\User\AppData\Roaming\libreoffice4.3_sdk\setsdkenv_windows.bat"
  set INCLUDE=%INCLUDE%;C:\cygwin\usr\include;%OO_SDK_HOME%\include
  set LIB=%LIB%;C:\cygwin\lib
  bash --login -i
 
Get the iMath sourcecode from Sourceforge. Run <code>autoreconf -i</code> and <code>./configure</code>, then change to the src subdirectory and run <code>make</code>.
 
== Compiling with MinGW ==
 
I haven't tried this method for a long time, but it did work once.
 
=== Preparing the Openoffice SDK with Microsoft Visual C++ ===
 
To build iMath for Windows, you need the Office SDK for Windows.


* Download and install the [http://www.openoffice.org Openoffice SDK]
* Download and install the [http://www.openoffice.org Openoffice SDK]
* The following is explained in detail in "SDK installation directory"\sdk\docs\install.html
* The following is explained in detail in "SDK installation directory"\sdk\docs\install.html
* Install Microsoft Visual C++ (the free express version will do, then you also need to install the Microsoft Visual Studio 2008 Redistributable Package
* Install Microsoft Visual C++ (the free express version will do, then you also need to install the Microsoft Visual Studio 2008 Redistributable Package)
* Install make (e.g. copy C:\MinGW\bin\mingw32-make.exe to WINDOWS\system32 and rename it to make.exe)
* Install make (e.g. copy C:\MinGW\bin\mingw32-make.exe to WINDOWS\system32 and rename it to make.exe)
* Install info-zip (e.g. download from [http://www.j3s.desoftware_2129__Infozip_3.0_Windows_Binaerdistribution_Binaries.htm] and put zip.exe into C:\Windows\system32)
* Install info-zip (e.g. download from [http://www.j3s.desoftware_2129__Infozip_3.0_Windows_Binaerdistribution_Binaries.htm] and put zip.exe into C:\Windows\system32)
Line 12: Line 115:
* I had to edit thecustom batch file and add a correct URE path:
* I had to edit thecustom batch file and add a correct URE path:
<code>set OO_SDK_URE_HOME=C:\Programme\OpenOffice.org 3\URE</code>
<code>set OO_SDK_URE_HOME=C:\Programme\OpenOffice.org 3\URE</code>
* Run vsvars32.bat from the MSVC\Common7\Tools directory
* Now try to build the example by typing make, if this is not successful fix the problems before continuing.
* Now try to build the example by typing make, if this is not successful fix the problems before continuing.
* The next time you want to use the SDK, just run the custom batch file to set the environment variables required
* The next time you want to use the SDK, just run the custom batch file to set the environment variables required


== Preparing MSYS and Mingw ==
=== Preparing MSYS and Mingw ===


* Get the mingw installer from [http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/mingw-get-inst-20100909/mingw-get-inst-20100909.exe/download here]
* Get the mingw installer from [http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/mingw-get-inst-20100909/mingw-get-inst-20100909.exe/download here]
Line 21: Line 125:
* Do mingw-get update and mingw-get install msys-base mingw32-base. This should update libtool to 2.4
* Do mingw-get update and mingw-get install msys-base mingw32-base. This should update libtool to 2.4
* Click on the MSYS icon to start a Bourne shell
* Click on the MSYS icon to start a Bourne shell
* Add .../Microsoft Visual Studio 9.0/Common7/IDE and .../Microsoft Visual Studio 9.0/VC/BIN to PATH (e.g <code>PATH=$PATH:"/c/Programme/Microsoft Visual Studio 9.0/Common7/IDE":"/c/Programme/Microsoft Visual Studio 9.0/VC/bin"</code>). You can find these paths in vsvars32.bat somewhere in the Visual Studio installation directory.
* Add .../Microsoft Visual Studio 10.0/Common7/IDE and .../Microsoft Visual Studio 10.0/VC/BIN to PATH (e.g <code>PATH=$PATH:"/c/Programme/Microsoft Visual Studio 10.0/Common7/IDE":"/c/Programme/Microsoft Visual Studio 10.0/VC/bin"</code>). You can find these paths in vsvars32.bat somewhere in the Visual Studio installation directory.
* If you want to use cl (the Microsoft compiler) to compile something, copy .../Microsoft Visual Studio 9.0/include and lib to msys vc/include and vc/lib (or find a better way to make CPPFLAGS accept path names with spaces)
* If you want to use cl (the Microsoft compiler) to compile something, copy .../Microsoft Visual Studio 10.0/VC/include and lib to msys /vc/include and /vc/lib (or find a better way to make CPPFLAGS accept path names with spaces)
* Copy Microsoft SDKs/Windows/Vxxx/Include and Lib to msys /sdk/include and /sdk/Lib (or find a better way to set the cl.exe LIB path)
* Copy Microsoft SDKs/Windows/Vxxx/Include and Lib to msys /sdk/include and /sdk/Lib (or find a better way to set the cl.exe LIB path)


== Compiling gmp with gcc ==
=== Compiling gmp with gcc ===
 
Note: This is optional. GiNaC comes with its own gmp, which I would recomment to use.


Download and unpack [http://gmplib.org gmp] into your msys home directory.  
Download and unpack [http://gmplib.org gmp] into your msys home directory.  
Line 49: Line 155:
* For a static link, substitute libgmp-3.lib with libgmp.lib
* For a static link, substitute libgmp-3.lib with libgmp.lib


== Compilation with Microsoft Visual C++ ==
=== Compilation with Microsoft Visual C++ ===
 
This is what I tried to get a native MSVC compile (because Openoffice is compiled with MSVC), in spite of being warned that CLN is not compileable with anything except gcc...


=== Preparations ===
==== Preparations ====


* Install [http://www.mingw.org mingw] (the minimal version will do since we will be using the Microsoft compiler)
* Install [http://www.mingw.org mingw] (the minimal version will do since we will be using the Microsoft compiler)
Line 59: Line 163:
* Create the /vc/include/sys directory and put /vc/include/time.h into it
* Create the /vc/include/sys directory and put /vc/include/time.h into it


=== Compiling CLN ===
==== Compiling CLN ====


Download the [http://www.ginac.de/CLN CLN source code] and unpack it into your msys home directory
Download the [http://www.ginac.de/CLN CLN source code] and unpack it into your msys home directory
* Change to the source directory  
* Change to the source directory  
* run <code>./configure CC=cl CXX=cl CCAS=cl CPPFLAGS="-DEBUG -DNO_ASM -EHsc -MD -I/vc/include -I/sdk/include" LIB=/vc/lib:/sdk/lib</code>
* run <code>./configure LD=cl CC=cl CXX=cl CCAS=cl CPPFLAGS="-DEBUG -DNO_ASM -EHsc -MD -I/vc/include -I/sdk/include" LIB=/vc/lib:/sdk/lib</code>
* Run make LIB="/vc/lib;/sdk/lib"
* make will stop and complain about missing files cl_asm.obj and cl_asm_GF2.obj
* make will stop and complain about missing files cl_asm.obj and cl_asm_GF2.obj
** copying cl_asm.o from a gcc compile to cl_asm.obj gives lots of linker errors, don't try that
** copying cl_asm.o from a gcc compile to cl_asm.obj gives lots of linker errors, don't try that
** change to the src subdirectory
** change to the src subdirectory
** Remove cl_asm.lo and cl_asm_GF2.lo
** Remove cl_asm.lo and cl_asm_GF2.lo
** Edit the Makefile and find the lines starting with <code>cl_asm.lo:</code> and <code>cl_asm_GF2.lo:</code>. Remove the comment from the first line below them
** Edit the Makefile and find the lines starting with <code>cl_asm.lo:</code> and <code>cl_asm_GF2.lo:</code>.
** Change cl_asm.S and cl_asm_GF2.S to cl_asm.cc and cl_asm_GF2.cc in the first lines and in the lines you just uncommented (because MSVC doesn't recognize the .S extension). Total of five changes for each.
** Change cl_asm.S and cl_asm_GF2.S to cl_asm_.cc and cl_asm_GF2.cc in these lines (because MSVC doesn't recognize the .S extension). Total of three (six?) changes for each.
** cp base/digitseq/cl_asm.S to base/digitseq/cl_asm.cc. cl_asm_GF2.cc already exists in my distribution and is identical to cl_asm_GF2.S
** run make again in the top-level directory
** run make cl_asm.lo and make cl_asm_GF2.lo. This should create cl_asm.obj and cl_asm_GF2.obj
** If you get a libtool error about not finding cygpath, edit libtool in the cln root directory and find the line reading <code>fix_srcfile_path="\`cygpath -w \"\$srcfile\"\`</code>. Change it to <code>fix_srcfile_path="$srcfile"</code>.
* Run make again


The build will finish with some linker warnings about duplicate definitions and create the library in .libs.  
The build will finish with some linker warnings about duplicate definitions and create the library in .libs.  
Line 86: Line 188:
* same for operator-
* same for operator-


When you try to use the library created, there will be lots of unresolved externals when linking. The reason is that libtool actually
Now try compiling the examples and checks:
does two links when creating the library (why?) and the second link has less files in its list (why?). Therefore, go to the Makefile
* Run <code>make LIB="/vc/lib;/sdk/lib" check</code>
again and edit the following entry (the second and following lines must start with a tab character):
* On my machine, this compiled without a flaw and said "All two tests passed"
libcln.la: $(libcln_la_OBJECTS) $(libcln_la_DEPENDENCIES)
  $(libcln_la_LINK) -rpath $(libdir) $(libcln_la_OBJECTS) $(libcln_la_LIBADD) $(LIBS)
  list='$(libcln_la_OBJECTS)'; \
  libobjects="`echo $$list | sed 's/\\.lo/.obj/g'`"; \
  lib -OUT:.libs/libcln.lib $$libobjects $(libcln_la_LIBADD) $(LIBS)
 
Remove src/.libs/libcln.lib, run touch cl_asm.lo (or any other dependency of the library) and run make again.
 
Now try compiling the examples:
* Change to the examples subdirectory
* Edit the Makefile and change the entry for CXXLINK by adding <code>/vc/lib/msvcrt.lib /vc/lib/msvcprt.lib /vc/lib/oldnames.lib /sdk/lib/Kernel32.lib /sdk/lib/Uuid.lib</code> at the end. If you can figure out how to give the library directories to configure please let me know!
* Also, sometimes the compiler flag <code>-MD</code> given to configure seems to get lost in the examples Makefile. Add it to CXXCOMPILE if you get complaints about a missing libcpmt.lib
 
The linker will fail with some unresolved externals. The reason is the different handling of extern declarations by gcc and MSVC. The errors can be removed by editing the source:
 
# <code>libcln.lib(cl_I_from_digits.obj) : error LNK2019: unresolved external symbol _mulu32_high referenced in function "class cln::cl_I const __cdecl cln::digits_to_I(char const *,unsigned int,unsigned long)" (?digits_to_I@cln@@YA?BVcl_I@1@PBDIK@Z)</code>.
#* cl_low.h defines <code>extern "C" uint32 mulu32_high;</code>
#* Solution: Move this declaration outside of the namespace cln in cl_low.h (e.g. to the beginning of the file)
# The same applies for <code>_divu_32_rest</code> and <code>_divu_16_rest</code>
# <code>libcln.lib(cl_F_dprint.obj) : error LNK2019: unresolved external symbol "struct cln::cl_anything * __cdecl cl_I_constructor_from_UL(unsigned long)" (?cl_I_constructor_from_UL@@YAPAUcl_anything@cln@@K@Z) referenced in function "public: __thiscall cln::cl_I::cl_I(unsigned long)" (??0cl_I@cln@@QAE@K@Z)</code>.
#* cl_I.h declares <code>extern cl_private_thing cl_I_constructor_from_UL (uint32 wert);</code> and <code>extern cl_private_thing cl_I_constructor_from_Q (sint64 wert);</code> somewhere in the file
#* Comment out these declarations
#* Replace them by the following at the beginning of the file:
extern cln::cl_private_thing cl_I_constructor_from_UL (uint32 wert);
extern cln::cl_private_thing cl_I_constructor_from_Q (sint64 wert);
#* Edit cl_I_from_UL.cc and comment out the namespace declaration <code>namespace cln {</code> and <code>}  // namespace cln</code>
#* Add <code>using namespace cln;</code>
#* Do the same for cl_I_from_Q.cc
 
Now pi.exe compiles and links and calculates PI (whether correctly or not, I did not check). If it doesn't, you might have to remove the .lo files which the linker complains about and re-make in the src subdirectory so that the source code modifications find their way into the library.
 
The other examples need more modifications of the source along the same lines to link. Only e.cc presents new problems
* Add <code>#include "../src/float/lfloat/cl_LF.h"</code> to the beginning of the file
* Comment out the <code>extern cl_LF cl_I_to_LF(const cl_I&, uintC);</code> declaration lower down
* Change the call to <code>log(10)</code> to <code>log ((double)10))</code>
* Edit cl_LF.h, comment out <code>extern const cl_LF cl_I_to_LF (const cl_I& x, uintC len);</code> and add <code>extern const cln::cl_LF cl_I_to_LF (const cln::cl_I& x, uintC len);</code> to the beginning of the file, outside the namespace cln
* Edit cl_LF_from_I.cc, remove <code>namespace cln{}</code> and add <code>using namespace cln;</code> instead
 
To ensure that all the files depending on cl_LF.h etc. get recompiled, it is simplest (but takes a while) to do a make clean and then a new make.
 
Try compiling the checks:
* Edit the makefile in the tests subdirectory and manually add the libraries as above
* Run "make check"
* On my compile, this compiled without a flaw and said "All two tests passed"


Install the library and headers
Install the library and headers
* Run <code>LIB=/vc/lib:/sdk/lib make install</code> to put them into /local/lib
* Run <code>make LIB=/vc/lib:/sdk/lib install</code> to put them into /local/lib


If you want to use the gmp library as compiled and modified by objconv above, add <code>--with-gmp=/usr/local LDFLAGS=/usr/local/lib/libgmp.lib</code> to the configure invocation. You might have to create a copy of libgmp.lib named libgmp.a in /usr/local/lib because make will link to both of them.
If you want to use the gmp library as compiled and modified by objconv above, add <code>--with-gmp=/usr/local LDFLAGS=/usr/local/lib/libgmp.lib</code> to the configure invocation. You might have to create a copy of libgmp.lib named libgmp.a in /usr/local/lib because make will link to both of them.


To get a successful GiNaC compile, more edits of the source code for missing externals are necessary
==== Compiling GiNaC ====
* Edit include/cln/integer_io.h
** Find four lines with <code>extern print_integer</code> and move them to the top of the file, outside of namespace cln
** Find the line with <code>extern cl_print_flags default_print_flags</code> and move it to the top of the file
** Add <code>cln::</code> to all occurences of <code>cl_print_flags</code> and <code>cl_I</code> which you moved out of the namespace
* Edit include/cln/output.h
** Move the line <code>extern cl_print_flags default_print_flags;</code> to the top of the file, outside of namespace cln
** Add <code>cln::</code> before <code>cl_print_flags</code>
* Do the same for float_io.h, lfloat_io.h, dfloat_io.h, sfloat_io.h, ffloat_io.h, complex_io.h, real_io.h and rational_io.h
* Edit cl_I_[a-d]print.cc, remove the <code>namespace cln</code> and add <code>using namespace cln;</code> to the top of the files
* Do the same for cl_I_print.cc
* Edit cl_prin_globals.cc and move <code>cl_print_flags default_print_flags;</code> outside of namespace cln. Add <code>cln::</code> before <code>cl_print_flags</code>
* Do <code>make clean; make</code> to catch all the dependencies
 
Actually, there are lots more header files which would need similar edits, but I have listed only those required to get GiNaC to build.
 
=== Compiling GiNaC ===


Download the Ginac source code from [http://github.com/AlexeiSheplyakov/GiNaC/tree/master.msvc.support git] and unpack it into your msys home directory
Download the Ginac source code from [http://github.com/AlexeiSheplyakov/GiNaC/tree/master.msvc.support git] and unpack it into your msys home directory
* Download pkg-config, gettext and glib2 from the [http://www.gtk.org/download-windows.html GTK project]. Unzip the files and install them under /MinGW/bin
* Download pkg-config, gettext and glib2 from the [http://www.gtk.org/download-windows.html GTK project]. Unzip the files and install them under /MinGW/bin
* Change to the source directory  
* Change to the source directory  
* Run <code>./configure CC=cl CXX=cl CPPFLAGS="-DEBUG -MD -EHsc -I/vc/include -I/sdk/include" LIB=/vc/lib:/sdk/lib PKG_CONFIG_PATH=/usr/local/lib/pkgconfig --disable-shared --enable-static</code>
* Run <code>./configure CPPFLAGS="-DEBUG -MD -EHsc -I/vc/include -I/sdk/include" LIB=/vc/lib:/sdk/lib PKG_CONFIG_PATH=/usr/local/lib/pkgconfig --disable-shared --enable-static</code>
* If configure chokes, find pkg.m4 on the web and put it in MinGW/share/aclocal
* If configure chokes, find pkg.m4 on the web and put it in MinGW/share/aclocal
* If you have not installed libreadline, then configure will give a warning. You can ignore this if you do not plan to build the ginsh.
* If you have not installed libreadline, then configure will give a warning. You can ignore this if you do not plan to build the ginsh.
* run make
* run make LIB="/vc/lib:/sdk/lib"
* The linker complains about "no public symbols existing" in registrar.obj, which seems to be OK since the source file has no code.  
* The linker complains about "no public symbols existing" in registrar.obj, which seems to be OK since the source file has no code.  
* Make will fail in the ginsh subdirectory if you have not installed libreadline. Run make -t in this directory to ignore the problem.  
* Make will fail in the ginsh subdirectory if you have not installed libreadline. Run make -t in this directory to ignore the problem.  
* Running <code>LIB=/vc/lib:/sdk/lib make check</code> passes all 58 tests successfully
* Running <code>make LIB=/vc/lib:/sdk/lib check</code> passes all 58 tests successfully
* Run <code>LIB=/vc/lib:/sdk/lib make install</code> to put the library into /local/lib
* Run <code>make LIB=/vc/lib:/sdk/lib install</code> to put the library into /local/lib


=== Compiling EQC ===
==== Compiling EQC ====


Download the EQC source code and unpack it into your msys home directory
Download the EQC source code and unpack it into your msys home directory
* Don't forget to set the Visual C++ paths as described above
* Don't forget to set the Visual C++ paths as described above
* Edit src/Makefile.am and comment out the line <code>CXX := /usr/bin/ccache $(CXX)</code> if you don't have ccache installed
* Run <code>autoreconf -i</code> to get the newest libtool files
* Run <code>autoreconf -i</code> to get the newest libtool files
* Run <code>./configure CC=cl CXX=cl LIB=/vc/lib:/sdk/lib CPPFLAGS="-DEBUG -MD -EHsc -I/vc/include -I/sdk/include" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig</code>
* Run <code>./configure LIB=/vc/lib:/sdk/lib CPPFLAGS="-DEBUG -MD -EHsc -I/vc/include -I/sdk/include" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig</code>
* Run <code>LIB=/vc/lib:/sdk/lib make</code>
* Run <code>make LIB="/vc/lib:/sdk/lib"</code>
* Ignore the failure to compile lt-eqc.c and use .libs/eqc.exe instead. Run <code>touch eqc.exe</code> in the src directory to satisfy make
* You need to run <code>make LIB="/vc/lib:/sdk/lib" install</code> to install library and headers correctly. If you have not installed the tools required to build the files in the doc directory, edit Makefile.am there and remove all lines except the first two.
* You need to run <code>LIB=/vc/lib:/sdk/lib make install</code> to install library and headers correctly. If you have not installed the tools required to build the files in the doc directory, edit Makefile.am there and remove all lines except the first two.
* On my system eqc.pc did not get installed into /local/lib/pkgconfig, so I copied it there manually


=== Compiling iMath===
==== Compiling iMath====


Hack the Openoffice.org SDK (after installing it as described above)
Make sure you have the Microsoft Visual C++ 2010 Redistributable package installed (search for vcredist on the Microsoft website)
* Edit settings\settings.mk and add the following lines:
** Before the line beginning with <code>CCFLAGS=</code>: <code>BASE=..\..\..\..</code>
** In the line <code>CC_INCLUDES=</code> add: <code>-I$(BASE)\local\include</code>


Download the iMath source code and unpack it into your msys home directory in an msys shell
Download the iMath source code and unpack it into your msys home directory in an msys shell
* Go to /local/lib and copy eqc.lib to libeqc.lib, and ginac.lib to libginac.lib
* Run <code>autoreconf -i</code> to get the newest libtool files
* Run <code>autoreconf -i</code> to get the newest libtool files
* Run <code>./configure LIB=/vc/lib:/sdk/lib CPPFLAGS="-I/vc/include -I/sdk/include" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig</code>
* Run <code>./configure LIB=/vc/lib:/sdk/lib CPPFLAGS="-I/vc/include -I/sdk/include" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig</code>


Now change to a DOS shell prepared for the OpenOffice SDK as described above
Now change to a DOS shell prepared for the OpenOffice SDK as described above
* Go to the src subdirectory
* Edit the Makefile and adapt the OS and MINGW settings at the beginning
* Edit the Makefile and adapt the OS and MINGW settings at the beginning
* Go to the src directory and run make
* If your office installation path has a space in it, you need to set the PRJ manually in the Makefile, prepending every space with a backslash
* run make
* If cppumaker chokes, just run the identical command manually without the -O flag. Move the generated type directory ./com to ./inc/com
* In my opinion, there is an error in the sdk/settings/settings.mk file. The CC_FLAGS must not have -MT, instead they should have -MD. Change this if you get linker errors when creating the DLL
* If make chokes on the manifest, just run make again to ignore the error
* After make was successful, run make deploy to install the extension
* After make was successful, run make deploy to install the extension

Latest revision as of 15:16, 14 May 2019

This section has not been maintained for a long time!

Compiling with Cygwin

I wasn't able to get a stable build with Cygwin, but here is what I did.

Preparing the Cygwin environment

Since LibreOffice for Windows is being built through Cygwin, it is best to set up the environment as described on the LibreOffice build page. Of course, you can skip the downloading of the Office source code.

For some reason CLN expects time.h to be in the subdirectory sys. Copy it from your Visual Studio Installation directory\VC\include\time.h to sys\time.h in the same directory.

Take care not to install the gcc compiler when you install Cygwin, as it takes precedence of MSVC. You can check this by running the Cygwin setup.exe, searching for the packages gcc-core and gcc-g++, and uninstalling them if necessary.

Run the Cygwin setup.exe, and include the package gettext-devel.

Setup the cygwin.bat (usually found in C:\cygwin) to set the MSVC environment variables before running the Cygwin shell. Insert the following call before the last line:

call "%VS120COMNTOOLS%\vsvars32.bat"

Note that depending on your version of Visual Studio the 120 might be another number. Run

cmd.exe

set

to see what variable is available on your system.

Compiling with Microsoft Visual C++

Compiling CLN

Get the CLN sourcecode from the CLN website. Bring up a Cygwin shell by calling the cygwin.bat file. Change to the source directory. Run autoreconf -i and ./configure CPPFLAGS="-MD -DNO_ASM -EHsc" --prefix=/usr. Check in the output of configure that cl.exe is found as the C compiler.

Run make. It will probably stop and complain about missing files base/digitseq/cl_asm.obj and polynomial/elem/cl_asm_GF2.obj. Remove the files base/digitseq/cl_asm.lo and polynomial/elem/cl_asm_GF2.lo. Run make base/digitseq/cl_asm.lo. It will fail again but you can see the command that was issued. Copy this command exactly, adding the flag -TC before -c (this will enable MSVC to recognize the extension .S as a valid source file extension). Repeat for cl_asm_GF2.obj. This should create cl_asm.obj and cl_asm_GF2.obj (if not, repeat the procedure).

Run make to finish the build, make check</check> do run some tests on the library, and make install to install it.

Compiling GiNaC

Get the GiNaC sourcecode from the GiNaC website. Run autoreconf -i and ./configure CPPFLAGS="-MD -DNO_ASM -EHsc" --prefix=/usr. Add the Cygwin include and library directory to the end of the corresponding paths:

export INCLUDE="$INCLUDE;C:\cygwin\usr\include"

export LIB="$LIB;C:\cygwin\lib" .

Run make. Compilation will probably stop in the ginsh subdirectory with a message about isatty. Since we don't need ginsh you can just change to that subdirectoy and run make -t.

In the check (and other subdirectories), when linking fails edit the Makefile and add the following to the command starting with CXXLINK: cln.lib. This is necessary because the package config file cln.pc is in Unix format and cl cannot find the library which is specified there by -lcln

Run make check and ensure that all checks pass.

Run make install.

Compiling EQC

Get the EQC sourcecode from Sourceforge. Run autoreconf -i and ./configure CPPFLAGS="-MD -EHsc" --prefix=/usr.

Run make

In the src subdirectory, after linking of eqc.exe fails, edit the Makefile and add the following to the command starting with CXXLINK: cln.lib ginac.lib (if you add it before, creation of the eqc library fails instead...).

Compiling iMath

Run setsdkenv_windows.bat from the Office SDK directory to configure your environment. This should create a custom batch file somewhere in your home directory (usually AppData\Roaming\office4.3_sdk). Give it the linux-style paths to the make and zip executables etc. Do NOT give it any paths with spaces - make will choke on them. Use the Windows 8.3 filenames instead. You can see them with dir /x. Add the setting set OSTYPE=cygwin manually to this file to fix some problems in the make process.

Here are example settings that work for me (note that this is only the beginning of the file!):

 set OO_SDK_NAME=libreoffice4.3_sdk
 set OO_SDK_HOME=C:\PROGRA~1\LIBREO~1\sdk
 set OFFICE_HOME=C:\PROGRA~1\LIBREO~1
 set OO_SDK_URE_HOME=C:\PROGRA~1\LIBREO~1\URE
 set OO_SDK_MAKE_HOME=C:\cygwin\opt\lo\bin
 set OO_SDK_ZIP_HOME=/usr/bin
 set OO_SDK_CAT_HOME=/usr/bin
 set OO_SDK_SED_HOME=/usr/bin
 set OO_SDK_CPP_HOME=C:\PROGRA~1\MICROS~1.0\VC\bin
 set CPP_MANIFEST=
 set CPP_WINDOWS_SDK=
 set OO_SDK_CLI_HOME=C:\Windows\Microsoft.NET\Framework\v2.0.50727
 set OO_SDK_JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45
 set OO_SDK_OUT=c:\libreoffice4.3_sdk
 set OSTYPE=cygwin

Add this batch file to Cygwin.bat. Here is what my Cygwin.bat looks like:

 @echo off
 C:
 chdir C:\cygwin\bin
 call "C:\Users\User\AppData\Roaming\libreoffice4.3_sdk\setsdkenv_windows.bat"
 set INCLUDE=%INCLUDE%;C:\cygwin\usr\include;%OO_SDK_HOME%\include
 set LIB=%LIB%;C:\cygwin\lib
 bash --login -i

Get the iMath sourcecode from Sourceforge. Run autoreconf -i and ./configure, then change to the src subdirectory and run make.

Compiling with MinGW

I haven't tried this method for a long time, but it did work once.

Preparing the Openoffice SDK with Microsoft Visual C++

To build iMath for Windows, you need the Office SDK for Windows.

  • Download and install the Openoffice SDK
  • The following is explained in detail in "SDK installation directory"\sdk\docs\install.html
  • Install Microsoft Visual C++ (the free express version will do, then you also need to install the Microsoft Visual Studio 2008 Redistributable Package)
  • Install make (e.g. copy C:\MinGW\bin\mingw32-make.exe to WINDOWS\system32 and rename it to make.exe)
  • Install info-zip (e.g. download from [1] and put zip.exe into C:\Windows\system32)
  • To test the SDK installation, open a command prompt and cd to the ...\sdk\examples\cpp\DocumentLoader directory.
  • Run ...\sdk\setsdkenv_windows.bat to configure your environment. This should create a custom batch file somewhere in your home directory (usually Application Data\Openoffice\...). Give it the correct paths to the make and zip executables
  • I had to edit thecustom batch file and add a correct URE path:

set OO_SDK_URE_HOME=C:\Programme\OpenOffice.org 3\URE

  • Run vsvars32.bat from the MSVC\Common7\Tools directory
  • Now try to build the example by typing make, if this is not successful fix the problems before continuing.
  • The next time you want to use the SDK, just run the custom batch file to set the environment variables required

Preparing MSYS and Mingw

  • Get the mingw installer from here
  • Use the pre-packaged lists for the first install
  • Do mingw-get update and mingw-get install msys-base mingw32-base. This should update libtool to 2.4
  • Click on the MSYS icon to start a Bourne shell
  • Add .../Microsoft Visual Studio 10.0/Common7/IDE and .../Microsoft Visual Studio 10.0/VC/BIN to PATH (e.g PATH=$PATH:"/c/Programme/Microsoft Visual Studio 10.0/Common7/IDE":"/c/Programme/Microsoft Visual Studio 10.0/VC/bin"). You can find these paths in vsvars32.bat somewhere in the Visual Studio installation directory.
  • If you want to use cl (the Microsoft compiler) to compile something, copy .../Microsoft Visual Studio 10.0/VC/include and lib to msys /vc/include and /vc/lib (or find a better way to make CPPFLAGS accept path names with spaces)
  • Copy Microsoft SDKs/Windows/Vxxx/Include and Lib to msys /sdk/include and /sdk/Lib (or find a better way to set the cl.exe LIB path)

Compiling gmp with gcc

Note: This is optional. GiNaC comes with its own gmp, which I would recomment to use.

Download and unpack gmp into your msys home directory.

  • Change into the new directory.
  • For a shared library build, run configure with --disable-static --enable-shared. Then do make, make check and make install
  • Change into the .libs subdirectory
  • Make sure the MSVC binaries are in your path and run lib /def:libgmp-3.dll.def /out:libgmp-3.lib
  • Copy libgmp-3.exp, libgmp-3.dll.def and libgmp-3.lib into /usr/local/lib.
  • Do make distclean
  • For a static library build, run configure with --enable-static --disable- shared (note that it is not possible to build both static and shared libraries in one compilation run).
  • Do make, make check and make install
  • Note that make install overwrites the libgmp.la for dynamic linking in /usr/local/lib.
  • Download objconv objconv and put the executable somewhere into your msys path.
  • Change into the .libs subdirectory
  • Run objconv -fcoff -nr:___chkstk:__chkstk libgmp.a libgmp.lib to make the symbols compatible with MSVC
  • Copy the new libgmp.lib into /usr/local/lib

To compile a test program with MSVC

  • Open a DOS command shell and go to the gmp directory.
  • You can find some example files in the demos subdirectory of gmp.
  • For a dynamically linked program, run cl /MD -I \vc\include -I \sdk\include -I \local\include isprime.c /link /LIBPATH: \vc\lib /LIBPATH: \sdk\lib LIBPATH: \local\lib libgmp-3.lib
  • For a static link, substitute libgmp-3.lib with libgmp.lib

Compilation with Microsoft Visual C++

Preparations

  • Install mingw (the minimal version will do since we will be using the Microsoft compiler)
  • Set your PATH as described above in the gcc compile section and create the msys /vc and /sdk directories
  • Create the /vc/include/sys directory and put /vc/include/time.h into it

Compiling CLN

Download the CLN source code and unpack it into your msys home directory

  • Change to the source directory
  • run ./configure LD=cl CC=cl CXX=cl CCAS=cl CPPFLAGS="-DEBUG -DNO_ASM -EHsc -MD -I/vc/include -I/sdk/include" LIB=/vc/lib:/sdk/lib
  • Run make LIB="/vc/lib;/sdk/lib"
  • make will stop and complain about missing files cl_asm.obj and cl_asm_GF2.obj
    • copying cl_asm.o from a gcc compile to cl_asm.obj gives lots of linker errors, don't try that
    • change to the src subdirectory
    • Remove cl_asm.lo and cl_asm_GF2.lo
    • Edit the Makefile and find the lines starting with cl_asm.lo: and cl_asm_GF2.lo:.
    • Change cl_asm.S and cl_asm_GF2.S to cl_asm_.cc and cl_asm_GF2.cc in these lines (because MSVC doesn't recognize the .S extension). Total of three (six?) changes for each.
    • run make again in the top-level directory

The build will finish with some linker warnings about duplicate definitions and create the library in .libs. The linker errors are (hopefully) all harmless and have to do with different handling of inlined functions by gcc and MSVC

  • bool zerop(const cl_RA&): As soon as more than one file includes cl_RA.h, inline bool zerop(..) is defined twice and produces a linker warning
  • cl_I numerator (const cl_RA&): same as above
  • bool CL_FLATTEN minusp (const cl_RA&): same as above
  • const cl_I denominator (const cl_RA&): same as above
  • bool zerop (const cl_I&): As soon as more than one file includes cl_I.h, inline bool zerop(..) is defined twice and produces a linker warning
  • bool minusp (const cl_I&): Same as zerop
  • const cl_LF operator+ (const cl_LF&, const cl_LF&): Defined in cl_LF_2plus.cc and as an inline version in cl_LF.h, these clash when cl_R_mul.cc includes cl_LF.h
  • same for operator-

Now try compiling the examples and checks:

  • Run make LIB="/vc/lib;/sdk/lib" check
  • On my machine, this compiled without a flaw and said "All two tests passed"

Install the library and headers

  • Run make LIB=/vc/lib:/sdk/lib install to put them into /local/lib

If you want to use the gmp library as compiled and modified by objconv above, add --with-gmp=/usr/local LDFLAGS=/usr/local/lib/libgmp.lib to the configure invocation. You might have to create a copy of libgmp.lib named libgmp.a in /usr/local/lib because make will link to both of them.

Compiling GiNaC

Download the Ginac source code from git and unpack it into your msys home directory

  • Download pkg-config, gettext and glib2 from the GTK project. Unzip the files and install them under /MinGW/bin
  • Change to the source directory
  • Run ./configure CPPFLAGS="-DEBUG -MD -EHsc -I/vc/include -I/sdk/include" LIB=/vc/lib:/sdk/lib PKG_CONFIG_PATH=/usr/local/lib/pkgconfig --disable-shared --enable-static
  • If configure chokes, find pkg.m4 on the web and put it in MinGW/share/aclocal
  • If you have not installed libreadline, then configure will give a warning. You can ignore this if you do not plan to build the ginsh.
  • run make LIB="/vc/lib:/sdk/lib"
  • The linker complains about "no public symbols existing" in registrar.obj, which seems to be OK since the source file has no code.
  • Make will fail in the ginsh subdirectory if you have not installed libreadline. Run make -t in this directory to ignore the problem.
  • Running make LIB=/vc/lib:/sdk/lib check passes all 58 tests successfully
  • Run make LIB=/vc/lib:/sdk/lib install to put the library into /local/lib

Compiling EQC

Download the EQC source code and unpack it into your msys home directory

  • Don't forget to set the Visual C++ paths as described above
  • Run autoreconf -i to get the newest libtool files
  • Run ./configure LIB=/vc/lib:/sdk/lib CPPFLAGS="-DEBUG -MD -EHsc -I/vc/include -I/sdk/include" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
  • Run make LIB="/vc/lib:/sdk/lib"
  • You need to run make LIB="/vc/lib:/sdk/lib" install to install library and headers correctly. If you have not installed the tools required to build the files in the doc directory, edit Makefile.am there and remove all lines except the first two.
  • On my system eqc.pc did not get installed into /local/lib/pkgconfig, so I copied it there manually

Compiling iMath

Make sure you have the Microsoft Visual C++ 2010 Redistributable package installed (search for vcredist on the Microsoft website)

Download the iMath source code and unpack it into your msys home directory in an msys shell

  • Run autoreconf -i to get the newest libtool files
  • Run ./configure LIB=/vc/lib:/sdk/lib CPPFLAGS="-I/vc/include -I/sdk/include" PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Now change to a DOS shell prepared for the OpenOffice SDK as described above

  • Go to the src subdirectory
  • Edit the Makefile and adapt the OS and MINGW settings at the beginning
  • If your office installation path has a space in it, you need to set the PRJ manually in the Makefile, prepending every space with a backslash
  • run make
  • If cppumaker chokes, just run the identical command manually without the -O flag. Move the generated type directory ./com to ./inc/com
  • In my opinion, there is an error in the sdk/settings/settings.mk file. The CC_FLAGS must not have -MT, instead they should have -MD. Change this if you get linker errors when creating the DLL
  • If make chokes on the manifest, just run make again to ignore the error
  • After make was successful, run make deploy to install the extension