Cross-compiling for Windows: Difference between revisions

From iMath
Jump to navigation Jump to search
 
(139 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Ubuntu, wine, and msys installed into wine ==
== Ubuntu, wine and Microsoft Visual C++ ==
 
I have not been successful with this. If you want to try, get the automated 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 Sourceforge]. Choose the pre-packaged lists, and then run <code>mingw-get update; mingw-get install msys-base mingw32-base</code>, which should update libtool to version 2.4
 
== Ubuntu, mingw32, wine and Microsoft Visual C++ ==


=== General setup ===
=== General setup ===


It seems that an Openoffice extension for Windows must be compiled with MSVC to be compatible. Here is a way to do this from within Ubuntu. Make sure you have mingw32 and wine installed. Then, get Microsoft Visual (Express) C++ 2010 to work under wine. Installing with vcsetup.exe, or installing Visual Studio  is pretty hopeless and an overkill anyway. Instead, try this hack:
It seems that an Office extension for Windows must be compiled with MSVC to be compatible. Here is a way to do this from within Ubuntu. Make sure you have a recent wine installed. By default this will be a 64 bit version. If you need a 32-bit wine, use <code>winearch='win32' winecfg</code>.


* Get a working installation under Windows (the express version is available for free, and works fine)
==== Visual Studio 2017 or 2019 (64 bit compiler, outputting 32 bit or 64 bit code) ====
* After booting into Ubuntu, copy cl.exe, c1xx.dll, c1.dll, c2.dll, lib.exe, link.exe, mspdb100.dll from the Windows Visual Express installation to .wine/drive_c/windows/system32/ or some other location in your PATH
* Get a working Visual Studio installation under Windows (the community version is available for free, and works fine)
* Copy mt.exe from a Windows SDK installation to .wine/drive_c/windows/system32/ or some other location in your PATH
* Set up the following file structure in your <code>.wine/drive_c</code> directory (for 32 bit wine, change <code>Hostx64</code> to <code>Hostx86</code> in the first two lines).
* Get winetricks
  vc/bin/x64 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\bin\Hostx64\x64
* Run winetricks vcrun2010. This will override msvcr100.dll with a Windows native version in the wine configuration
  vc/bin/x86 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\bin\Hostx64\x86
  vc/lib/x64 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\lib\x64
  vc/lib/x86 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\lib\x86
  vc/include from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\include
  vc/sdk/lib/ucrt/x64 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x64
  vc/sdk/lib/ucrt/x86 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x86
  vc/sdk/lib/um/x64 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64
  vc/sdk/lib/um/x86 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x86
  vc/sdk/include/ucrt from C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt
  vc/sdk/include/um from C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um
  vc/sdk/include/shared from C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared
  vc/sdk/include/ucrt/sys/time.h: link to ../time.h
* If you change this structure you must also adapt the .configure calls later
* If you are only targeting x64 or x86 you can omit the other architecture
* Run <code>wine regedit</code> and add to HKEY_CURRENT_USER\Environment the entry PATH:
** 64 bit host, 64 bit target: <code>C:\vc\bin\x64</code>
** 64 bit host, 32 bit target: <code>C:\vc\bin\x86;C:\vc\bin\x64</code>


wine cl, wine link and wine lib should now work from a (Unix) terminal
<code>wine cl</code>, <code>wine link</code> and <code>wine lib</code> should now work.


Install the required libraries and include files somewhere (is there a better/standard location?)
==== Debug build ====
mkdir ~/.wine/drive_c/vc
cp -aR /c/Programme/Microsoft Visual Studio 9/VC/lib/ ~/.wine/drive_c/vc
cp -aR /c/Programme/Microsoft Visual Studio 9/VC/include/ ~/.wine/drive_c/vc
cd ~/.wine/drive_c/vc/include
cp time.h sys
mkdir ~/.wine/drive_c/sdk
cp -aR /c/Programme/Microsoft\ SDKs/Windows/v7.0A/Lib/ ~/.wine/drive_c/sdk
cp -aR /c-ro/Programme/Microsoft\ SDKs/Windows/v7.0A/Include/ ~/.wine/drive_c/sdk


Libtool version 2.4 claims to be able to deal with MSVC so use that version if you can.
* To get a debug build, use the flags <code>-MDd -D_DEBUG</code> for libraries
* You will need to copy the debug versions of the standard libraries into the paths


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


CLN still needs a lot of fixes to compile with MSVC.
You must use a recent [https://www.ginac.de/CLN/ CLN] (>1.3.6)
 
* Run <code>./configure CC="wine cl" CXX="wine cl" CCAS="wine cl" LD="wine link" MANIFEST_TOOL="wine mt" LIB="C:/vc/lib;C:/sdk/lib" CPPFLAGS="-DNO_ASM -EHsc -IC:/vc/include -IC:/sdk/include" --host=i586-mingw32msvc</code>
* Edit libtool and find the two lines containing <code>-OUT</code>. Replace <code>lib</code> with <code>wine lib</code>
* Run make LIB="C:/vc/lib;C:/sdk/lib"
* make will stop and complain about missing files cl_asm.obj and cl_asm_GF2.obj
** change to the src subdirectory
** 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
** 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.
** run make cl_asm.lo and make cl_asm_GF2.lo. This should create cl_asm.obj and cl_asm_GF2.obj
 
=== Compiling GiNaC ===


Copy libcln.lib into ~/.wine/drive_c/local/lib and the CLN headers into ~/.wine/drive_c/local/include/cln
If the linker reports undefined symbols, try to remove the inlined methods <code>cl_string::cl_string (const char * s)</code> and <code>cl_string& cl_string::operator= (const char * s)</code> from <code>include/cln/string.h</code> and instead defining them in <code>src/base/string/cl_st_make2.cc</code>. The extern definitions can be removed from these two methods.


Get the source code from [http://github.com/AlexeiSheplyakov/GiNaC/tree/master.msvc.support GiNaC MSVC support branch] using the download button on the web page.
If compilation fails on the two assembler files, remove the following lines from <code>src/Makefile.am</code>:
  nodist_libcln_la_SOURCES = \
  base/digitseq/cl_asm.S \
  polynomial/elem/cl_asm_GF2.S


You can now run <code>./configure CC="wine cl" CXX="wine cl" LD="wine link" LIBTOOL=/usr/local/bin/libtool CPPFLAGS="-DEBUG -MD -EHsc -IC:/vc/include -IC:/sdk/Include -IC:/local/include" LIB="C:/vc/lib;C:/sdk/lib;C:/local/lib" --host=i586-mingw32msvc</code> (assuming that you are using the libtool installed into /usr/local). There are still a lot of libtool issues, though, which need to be hacked by editing libtool:
==== Visual Studio 2017 and 2019 ====


* The line starting with <code>old_archive_cmds</code> must read <code>"wine lib -OUT:\$oldlib\$oldobjs\$old_deplibs"</code>. Note that this line occurs twice in the file!
* Run <code>autoreconf -i</code>
* The line starting with LTCFLAGS must read <code>LTCFLAGS="-g -IC:/vc/VC/include -IC:/cl/SDK/Include"</code>
* Configure the build
* Find the line containing <code>$cwrapper $cwrappersource</code> and add <code>C:/cl/VC/lib/libcmt.lib C:/cl/VC/lib/oldnames.lib C:/cl/SDK/lib/Kernel32.lib</code> to the end of it
** 64 bit build: <code>./configure CC="wine cl" CXX="wine cl" CCAS="wine cl" LD="wine link" LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" CPPFLAGS="-MD -DNO_ASM -EHsc -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/vc/sdk/include/shared" --host=amd64-mingw64msvc</code>
* In the check (and other subdirectories), when linking fails edit the Makefile and add the following to the command starting with CXXLINK: <code>C:/vc/lib/msvcrt.lib C:/vc/lib/msvcprt.lib C:/vc/lib/oldnames.lib C:/sdk/lib/Kernel32.lib C:/sdk/lib/Uuid.lib C:/local/lib/libcln.lib</code>
** 32 bit build: <code>./configure CC="wine cl" CXX="wine cl" CCAS="wine cl" LD="wine link" LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" CPPFLAGS="-MD -DNO_ASM -EHsc -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/vc/sdk/include/shared" --host=i586-mingw32msvc</code>
* After compilation, the wrapper created in the source directory does not work, but the .exe created in .libs does. Do <code>cp .libs/* .</code> before running <code>make check</code> again.
* Edit libtool and find the two lines containing <code>-OUT</code>. Replace <code>lib</code> with <code>wine lib</code>
* Make one of these changes (depending on what source version you have only one is possible)
** Edit the src/Makefile and find the line starting with <code>.S.lo</code> and add the switch <code>-TC</code> before <code>-c -o</code>
** Remove the definition of <code>nodist_libcln_la_SOURCES</code> from src/Makefile.am (total three lines) and re-run configure
* Build
** 64 bit build: <code>make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64"</code>
** 32 bit build: <code>make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86"</code>
* Check
** 64 bit build: <code>make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" check</code>
** 32 bit build: <code>make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" check</code>
* All tests should pass successfully (note that on a 64-bit wine, the 32-bit tests will not execute). If they do not, you might need to install the package wine-binfmt


After hacking away the libtool problems, GiNaC compiles and all 58 tests pass successfully.
=== Compiling GiNaC ===


=== Compiling EQC ===
For a 64 bit build, you need a recent version of [https://www.ginac.de GiNaC] (>1.7.8).


Copy libginac.lib into ~/.wine/drive_c/local/lib and the GiNaC headers into ~/.wine/drive_c/local/include/ginac
If compilation fails with reference to a missing C++20 compiler, edit the <code>configure.ac</code> and change the compiler prerequisite <code>AX_CXX_COMPILE_STDCXX</code> to version 20.


* Before starting, be sure to run <code>make distclean</code> and also remove the ccache line in src/Makefile.am (if you want to use ccache then add it to the configure invocation, e.g. <code>CC="ccache wine cl"</code>)
==== Visual Studio 2017 and 2019 ====
* Run <code>env LIBTOOLIZE=/usr/local/bin/libtoolize autoreconf -i</code> and <code>./configure CC="wine cl" CXX="wine cl" LD="wine link" LIB="C:/vc/lib;c:/sdk/lib" CPPFLAGS="-DEBUG -MD -EHsc -IC:/vc/include -IC:/sdk/include -IC:/local/include" --host=i586-mingw32msvc</code>.
* To get EQC to link successfully, you need to edit the src/Makefile and add the following to the command starting with CXXLINK <code>C:/vc/lib/msvcrt.lib C:/vc/lib/msvcprt.lib C:/vc/lib/oldnames.lib C:/sdk/lib/Kernel32.lib C:/sdk/lib/Uuid.lib C:/local/lib/libcln.lib C:/local/lib/libginac.lib</code>.
* If the Makefile has no such line, edit libeqc.la instead and change the line reading <code>dependency_libs</code> to have these libraries (instead of the ones listed).
* Run make
* If you get an error <code>lib: command not found</code>, find two lines with <code>...lib -OUT...</code> in libtool and change them to <code>...wine lib -OUT...</code>


=== Preparing the OOo SDK ===
* Copy src/.libs/libcln.lib into ~/.wine/drive_c/local/lib/x64 (or x86) and the CLN headers in the include directory into ~/.wine/drive_c/local/include/x64/cln (or x86/cln)
* Get a recent GiNaC (>= 1.8.2)
* Run <code>autoreconf -i</code> in the source directory
* Configure
** 64 bit: <code>./configure CC="wine cl" CXX="wine cl" LD="wine link" CLN_CFLAGS=-IC:/local/include/x64 CLN_LIBS=C:/local/lib/x64/libcln.lib LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" CPPFLAGS="-MD -EHsc -Zc:__cplusplus -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/local/include" --disable-shared --enable-static --host=amd64-mingw64msvc</code>
** 32 bit: <code>./configure CC="wine cl" CXX="wine cl" LD="wine link" CLN_CFLAGS=-IC:/local/include/x86 CLN_LIBS=C:/local/lib/x86/libcln.lib LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" CPPFLAGS="-MD -EHsc -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/local/include" --disable-shared --enable-static --host=i586-mingw32msvc</code>
* Edit the libtool created by configure:
** The line starting with <code>old_archive_cmds</code> must read <code>"wine lib -OUT:\$oldlib\$oldobjs\$old_deplibs"</code>. Note that this line occurs twice in the file!
* Build
** 64 bit: <code>make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64"</code>
** 32 bit: <code>make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86"</code>
* On Windows compilation will fail in the ginsh subdirectory. Simply cd to this directory and run <code>make -t</code> (since we won't be needing ginsh)
* Change to the toplevel directory again and finish the build with the same make command as before
* Check
** 64 bit: <code>make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" check</code>
** 32 bit: <code>make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" check</code>
* All tests should pass successfully (note that on 64 bit wine the 32 bit tests will not execute)


* Install Openoffice.org and the Openoffice SDK into wine using the standard Windows installation files. Try to run ~/.wine/drive_c/Program Files/OpenOffice.org 3/program/soffice.exe, if this doesn't start (cannot determine user interface language), then install it into a clean wine.
=== Preparing the Office SDK ===
* In the SDK base directory (e.g. ~/.wine/drive_c/Program Files/OpenOffice.org 3/Basis/sdk), put a file config.guess<code>echo wine; exit 0</code> and make it executable.
* Edit settings/settings.mk and add a section for wine:


###########################################################################
* Install Office and the Office SDK into wine using the standard Windows installation files. Try to run ~/.wine/drive_c/Program Files/<YOUR_OFFICE>/program/soffice.exe, if this doesn't start, then install it into a clean wine.
#
* Remember to install 64-bit versions of the Office and SDK if you set up a 64-bit Visual C++ environment
# Wine specific settings
* In the SDK base directory (e.g. ~/.wine/drive_c/Program Files/<YOUR_OFFICE>/sdk), edit settings/dk.mk and change the platform <code>PLATFORM=wine</code> (for Apache OpenOffice, create a file called config.guess in the sdk subdirectory with contents <code>echo wine; exit 0</code>)
#
* Edit settings/settings.mk and add a section for wine. The iMath source subdirectory src/wine-sdk-config contains a sample that works for me, but keep in mind that the settings.mk file varies between SDK versions.
###########################################################################
* Go to sdk/bin and create an executable called cppumaker with content <code>wine "$OO_SDK_HOME/bin/cppumaker.exe" "$@"</code>
ifeq "$(PLATFORM)" "wine"
* Install the Office DLLs where wine can find them (e.g. symlink into the sdk/bin directory) but not into ~/.wine/drive_c/windows/system32, because this will confuse the office. This is required for cppumaker.exe to run
# Settings for Wine cross-compilation using Microsoft compiler/linker
#
OS=WINE
PS=/
ICL=$$
CC=wine cl
LINK=wine link
BUILDLIB=wine lib
echo=echo
MKDIR=mkdir -p
MV=mv
CAT=cat
OBJ_EXT=obj
EXE_EXT=.exe
COPY=cp
SHAREDLIB_EXT=dll
SHAREDLIB_OUT=$(OUT_BIN)
PACKAGE_LIB_DIR=windows.plt
UNOPKG_PLATFORM=Windows
#
OSEP=\<
CSEP=\>
QUOTE=
QM=\"
SQM=
ECHOLINE=echo.
P2BG=
#
DEL=rm
DELRECURSIVE=rm -r
URLPREFIX=file:///
#
SALLIB=isal.lib
CPPULIB=icppu.lib
CPPUHELPERLIB=icppuhelper.lib
SALHELPERLIB=isalhelper.lib
REGLIB=ireg.lib
STORELIB=istore.lib
STLPORTLIB=stlport_vc71$(STLDEBUG).lib
#
BLANK=
EMPTYSTRING=
PATH_SEPARATOR=;
# use this for release version
CC_FLAGS=-c -MT -Zm500 -Zc:forScope,wchar_t- -wd4251 -wd4275 -wd4290 -wd4675 -wd4786 -wd4800 -Zc:forScope -GR -EHa
ifeq "$(CPP_MANIFEST)" "true"
LINK_MANIFEST=mt -manifest $@.manifest "-outputresource:$@;2"
else
LINK_MANIFEST=
endif
ifeq "$(DEBUG)" "yes"
CC_FLAGS+=-Zi
endif
CC_INCLUDES=-I. -I$(OUT_INC) -I$(PRJ)/include -I"$(CPP_WINDOWS_VC)/include" -I"$(BASE)/local/include"
#STL_INCLUDES=-I"$(OO_SDK_HOME)/include/stl"
SDK_JAVA_INCLUDES = -I"$(OO_SDK_JAVA_HOME)/include" -I"$(OO_SDK_JAVA_HOME)/include/win32"
#
# define for used compiler necessary for UNO
# -DCPPU_ENV=msci -- windows msvc 4.x - 7.x
#
CC_DEFINES=-DWIN32 -DWNT -D_DLL -DCPPU_ENV=msci
CC_OUTPUT_SWITCH=-Fo
#
LIBRARY_LINK_FLAGS=/NODEFAULTLIB /DLL /DEBUGTYPE:cv
COMP_LINK_FLAGS=$(LIBRARY_LINK_FLAGS) /DEF:$(PRJ)/settings/component.uno.def
EXE_LINK_FLAGS=/MAP /OPT:NOREF /SUBSYSTEM:CONSOLE /BASE:0x1b000000 /DEBUGTYPE:cv /NODEFAULTLIB  msvcrt.lib kernel32.lib
ifeq "$(DEBUG)" "yes"
LIBRARY_LINK_FLAGS+=/DEBUG
EXE_LINK_FLAGS+=/DEBUG
endif
endif
* Go to sdk/bin and create an executable cppumaker <code>LD_LIBRARY_PATH=/usr/lib/ure/lib /usr/lib/openoffice/basis3.2/sdk/bin/cppumaker.bin "$@"</code>
* Go to URE/bin and do <code>ln -s /usr/lib/ure/bin/regmerge .</code>.
* We probably don't want to use regcomp, but anyway
ln -s /usr/lib/ure/bin/regcomp .
ln -s /usr/lib/ure/bin/regcomp.bin .
* Install the OOo DLLs where wine can find them, but not into ~/.wine/drive_c/windows/system32, because this will confuse openoffice ("Cannot determine user interface language" error)


=== Compiling iMath ===
=== Compiling iMath ===
Copy libginac.lib into ~/.wine/drive_c/local/lib/x64 (or x86) and the GiNaC headers (also from the parser subdirectory) into ~/.wine/drive_c/local/include/x64/ginac (or x86/ginac)


* Copy libeqc.lib into ~/.wine/drive_c/local/lib and the headers into ~/.wine/drive_c/local/include/libeqc
* Because GNU make has problems with spaces in paths, it is strongly advisable to create a symlink to ~/.wine/drive_c/Program\ Files and any other directory that has spaces (e.g. LibreOffice\ 5)
* Edit config.wine <code>BASE=</code> to match your wine installation directory
* Edit the config.wine file matching your Office installation in the directory src/wine-sdk-config. Set <code>BASE=</code> to match your wine installation directory. Edit the relevant entries at the top of the file using the symlinked directory names without spaces
* Source the config.wine file
* Source this config.wine.xxx file
* Edit src/Makefile.in and change the line starting with PRJ to match your installation (spaces must be escaped - therefore using $(...) doesn't work. Can someone tell me how to get it to work?)
* Run <code>autoreconf -i</code>
* Run <code>env LIBTOOLIZE=/usr/local/bin/libtoolize autoreconf -i</code>
* 32 bit build: Run <code>./configure CC="wine cl" CXX="wine cl" LD="wine cl" --host=i586-mingw32msvc</code>
* Run <code>./configure CC="wine cl" CXX="wine cl" LD="wine cl" --host=i586-mingw32msvc --build=i686-pc-linux-gnu</code>
* 64 bit build: Run <code>./configure CC="wine cl" CXX="wine cl" LD="wine cl" --host=amd64-mingw64msvc</code>
* Change into the source directory
* Change into the source directory
* Run make. This will produce an error about mt.exe at the end of the process. Just run make again and the extension is created in the iMathout directory
* Run make. This will produce an error about mt.exe at the end of the process. Just run make again and the extension is created in the iMathout directory

Latest revision as of 17:56, 24 September 2023

Ubuntu, wine and Microsoft Visual C++

General setup

It seems that an Office extension for Windows must be compiled with MSVC to be compatible. Here is a way to do this from within Ubuntu. Make sure you have a recent wine installed. By default this will be a 64 bit version. If you need a 32-bit wine, use winearch='win32' winecfg.

Visual Studio 2017 or 2019 (64 bit compiler, outputting 32 bit or 64 bit code)

  • Get a working Visual Studio installation under Windows (the community version is available for free, and works fine)
  • Set up the following file structure in your .wine/drive_c directory (for 32 bit wine, change Hostx64 to Hostx86 in the first two lines).
 vc/bin/x64 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\bin\Hostx64\x64
 vc/bin/x86 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\bin\Hostx64\x86
 vc/lib/x64 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\lib\x64
 vc/lib/x86 from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\lib\x86
 vc/include from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\XX.YY.ZZZZZ\include
 vc/sdk/lib/ucrt/x64 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x64
 vc/sdk/lib/ucrt/x86 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x86
 vc/sdk/lib/um/x64 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64
 vc/sdk/lib/um/x86 from C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x86
 vc/sdk/include/ucrt from C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt
 vc/sdk/include/um from C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um
 vc/sdk/include/shared from C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared
 vc/sdk/include/ucrt/sys/time.h: link to ../time.h
  • If you change this structure you must also adapt the .configure calls later
  • If you are only targeting x64 or x86 you can omit the other architecture
  • Run wine regedit and add to HKEY_CURRENT_USER\Environment the entry PATH:
    • 64 bit host, 64 bit target: C:\vc\bin\x64
    • 64 bit host, 32 bit target: C:\vc\bin\x86;C:\vc\bin\x64

wine cl, wine link and wine lib should now work.

Debug build

  • To get a debug build, use the flags -MDd -D_DEBUG for libraries
  • You will need to copy the debug versions of the standard libraries into the paths

Compiling CLN

You must use a recent CLN (>1.3.6)

If the linker reports undefined symbols, try to remove the inlined methods cl_string::cl_string (const char * s) and cl_string& cl_string::operator= (const char * s) from include/cln/string.h and instead defining them in src/base/string/cl_st_make2.cc. The extern definitions can be removed from these two methods.

If compilation fails on the two assembler files, remove the following lines from src/Makefile.am:

 nodist_libcln_la_SOURCES = \
 base/digitseq/cl_asm.S \
 polynomial/elem/cl_asm_GF2.S

Visual Studio 2017 and 2019

  • Run autoreconf -i
  • Configure the build
    • 64 bit build: ./configure CC="wine cl" CXX="wine cl" CCAS="wine cl" LD="wine link" LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" CPPFLAGS="-MD -DNO_ASM -EHsc -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/vc/sdk/include/shared" --host=amd64-mingw64msvc
    • 32 bit build: ./configure CC="wine cl" CXX="wine cl" CCAS="wine cl" LD="wine link" LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" CPPFLAGS="-MD -DNO_ASM -EHsc -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/vc/sdk/include/shared" --host=i586-mingw32msvc
  • Edit libtool and find the two lines containing -OUT. Replace lib with wine lib
  • Make one of these changes (depending on what source version you have only one is possible)
    • Edit the src/Makefile and find the line starting with .S.lo and add the switch -TC before -c -o
    • Remove the definition of nodist_libcln_la_SOURCES from src/Makefile.am (total three lines) and re-run configure
  • Build
    • 64 bit build: make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64"
    • 32 bit build: make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86"
  • Check
    • 64 bit build: make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" check
    • 32 bit build: make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" check
  • All tests should pass successfully (note that on a 64-bit wine, the 32-bit tests will not execute). If they do not, you might need to install the package wine-binfmt

Compiling GiNaC

For a 64 bit build, you need a recent version of GiNaC (>1.7.8).

If compilation fails with reference to a missing C++20 compiler, edit the configure.ac and change the compiler prerequisite AX_CXX_COMPILE_STDCXX to version 20.

Visual Studio 2017 and 2019

  • Copy src/.libs/libcln.lib into ~/.wine/drive_c/local/lib/x64 (or x86) and the CLN headers in the include directory into ~/.wine/drive_c/local/include/x64/cln (or x86/cln)
  • Get a recent GiNaC (>= 1.8.2)
  • Run autoreconf -i in the source directory
  • Configure
    • 64 bit: ./configure CC="wine cl" CXX="wine cl" LD="wine link" CLN_CFLAGS=-IC:/local/include/x64 CLN_LIBS=C:/local/lib/x64/libcln.lib LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" CPPFLAGS="-MD -EHsc -Zc:__cplusplus -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/local/include" --disable-shared --enable-static --host=amd64-mingw64msvc
    • 32 bit: ./configure CC="wine cl" CXX="wine cl" LD="wine link" CLN_CFLAGS=-IC:/local/include/x86 CLN_LIBS=C:/local/lib/x86/libcln.lib LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" CPPFLAGS="-MD -EHsc -IC:/vc/include -IC:/vc/sdk/include/um -IC:/vc/sdk/include/ucrt -IC:/local/include" --disable-shared --enable-static --host=i586-mingw32msvc
  • Edit the libtool created by configure:
    • The line starting with old_archive_cmds must read "wine lib -OUT:\$oldlib\$oldobjs\$old_deplibs". Note that this line occurs twice in the file!
  • Build
    • 64 bit: make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64"
    • 32 bit: make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86"
  • On Windows compilation will fail in the ginsh subdirectory. Simply cd to this directory and run make -t (since we won't be needing ginsh)
  • Change to the toplevel directory again and finish the build with the same make command as before
  • Check
    • 64 bit: make LIB="C:/vc/lib/x64;C:/vc/sdk/lib/um/x64;C:/vc/sdk/lib/ucrt/x64" check
    • 32 bit: make LIB="C:/vc/lib/x86;C:/vc/sdk/lib/um/x86;C:/vc/sdk/lib/ucrt/x86" check
  • All tests should pass successfully (note that on 64 bit wine the 32 bit tests will not execute)

Preparing the Office SDK

  • Install Office and the Office SDK into wine using the standard Windows installation files. Try to run ~/.wine/drive_c/Program Files/<YOUR_OFFICE>/program/soffice.exe, if this doesn't start, then install it into a clean wine.
  • Remember to install 64-bit versions of the Office and SDK if you set up a 64-bit Visual C++ environment
  • In the SDK base directory (e.g. ~/.wine/drive_c/Program Files/<YOUR_OFFICE>/sdk), edit settings/dk.mk and change the platform PLATFORM=wine (for Apache OpenOffice, create a file called config.guess in the sdk subdirectory with contents echo wine; exit 0)
  • Edit settings/settings.mk and add a section for wine. The iMath source subdirectory src/wine-sdk-config contains a sample that works for me, but keep in mind that the settings.mk file varies between SDK versions.
  • Go to sdk/bin and create an executable called cppumaker with content wine "$OO_SDK_HOME/bin/cppumaker.exe" "$@"
  • Install the Office DLLs where wine can find them (e.g. symlink into the sdk/bin directory) but not into ~/.wine/drive_c/windows/system32, because this will confuse the office. This is required for cppumaker.exe to run

Compiling iMath

Copy libginac.lib into ~/.wine/drive_c/local/lib/x64 (or x86) and the GiNaC headers (also from the parser subdirectory) into ~/.wine/drive_c/local/include/x64/ginac (or x86/ginac)

  • Because GNU make has problems with spaces in paths, it is strongly advisable to create a symlink to ~/.wine/drive_c/Program\ Files and any other directory that has spaces (e.g. LibreOffice\ 5)
  • Edit the config.wine file matching your Office installation in the directory src/wine-sdk-config. Set BASE= to match your wine installation directory. Edit the relevant entries at the top of the file using the symlinked directory names without spaces
  • Source this config.wine.xxx file
  • Run autoreconf -i
  • 32 bit build: Run ./configure CC="wine cl" CXX="wine cl" LD="wine cl" --host=i586-mingw32msvc
  • 64 bit build: Run ./configure CC="wine cl" CXX="wine cl" LD="wine cl" --host=amd64-mingw64msvc
  • Change into the source directory
  • Run make. This will produce an error about mt.exe at the end of the process. Just run make again and the extension is created in the iMathout directory