Cross-compiling for Windows: Difference between revisions

From iMath
Jump to navigation Jump to search
Line 62: Line 62:


* 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>)
* 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>)
* 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>.  
* Run <code>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>.  
* Find two lines with <code>...lib -OUT...</code> in libtool and change them to <code>...wine lib -OUT...</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).
* To get EQC to link successfully, you need to edit the src/Makefile and add the following to the command starting with CXXLINK: <code>libcln.lib libginac.lib</code>.
* Run make
* Run <code>make LIB="C:/vc/lib;C:/sdk/lib;C:/local/lib"</code>
* 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>
* Link manually with <code>wine link -NODEFAULTLIB -LIBPATH:C:/vc/lib -LIBPATH:C:/sdk/lib -LIBPATH:C:/local/lib -OUT:.libs/eqc.exe ltxfileparse.obj ltxfilelex.obj main.obj libcmt.lib msvcrt.lib libcpmt.lib msvcprt.lib libcln.lib libginac.lib ./.libs/libeqc.lib</code> ????


=== Preparing the OOo SDK ===
=== Preparing the OOo SDK ===

Revision as of 12:01, 14 December 2011

Ubuntu, wine, and msys installed into wine

I have not been successful with this. If you want to try, get the automated MinGW installer from Sourceforge. Choose the pre-packaged lists, and then run mingw-get update; mingw-get install msys-base mingw32-base, which should update libtool to version 2.4

Ubuntu, mingw32, wine and Microsoft Visual C++

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:

  • Get a working installation under Windows (the express version is available for free, and works fine)
  • After booting into Ubuntu, copy cl.exe, c1xx.dll, c1.dll, c2.dll, lib.exe, link.exe, mspdb100.dll and clui.dll from the Windows Visual Express installation to .wine/drive_c/windows/system32/ or some other location in your PATH
  • Copy mt.exe from a Windows SDK installation to .wine/drive_c/windows/system32/ or some other location in your PATH
  • Get winetricks
  • Run winetricks vcrun2010. This will override msvcr100.dll with a Windows native version in the wine configuration

wine cl, wine link and wine lib should now work from a (Unix) terminal

Install the required libraries and include files somewhere (is there a better/standard location?)

mkdir ~/.wine/drive_c/vc
cp -aR /c/Programme/Microsoft Visual Studio 10/VC/lib/ ~/.wine/drive_c/vc
cp -aR /c/Programme/Microsoft Visual Studio 10/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.

Compiling CLN

The latest CLN has patches applied so that it will compile with MSVC

  • Run ./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
  • Edit libtool and find the two lines containing -OUT. Replace lib with wine lib
  • 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 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 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
  • Run make LIB="C:/vc/lib;C:/sdk/lib" to finish the compile
  • Run make LIB="C:/vc/lib;C:/sdk/lib" check, all tests should pass successfully

Compiling GiNaC

  • Copy libcln.lib into ~/.wine/drive_c/local/lib and the CLN headers into ~/.wine/drive_c/local/include/cln
  • Get the source code from GiNaC MSVC support branch using the download button on the web page.
  • Unpack and run autoreconf -i in the new directory that was created
  • You can now run ./configure CC="wine cl" CXX="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 -IC:/local/include" --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!
  • In the check (and other subdirectories), when linking fails edit the Makefile and add the following to the command starting with CXXLINK: libcln.lib
  • Run make LIB="C:/vc/lib;C:/sdk/lib;C:/local/lib"
  • GiNaC now compiles and all 58 tests pass successfully with make LIB="C:/vc/lib;C:/sdk/lib;C:/local/lib" check

Compiling EQC

Copy libginac.lib into ~/.wine/drive_c/local/lib and the GiNaC headers into ~/.wine/drive_c/local/include/ginac

  • Before starting, be sure to run make distclean 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. CC="ccache wine cl")
  • Run autoreconf -i and ./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.
  • Find two lines with ...lib -OUT... in libtool and change them to ...wine lib -OUT...
  • To get EQC to link successfully, you need to edit the src/Makefile and add the following to the command starting with CXXLINK: libcln.lib libginac.lib.
  • Run make LIB="C:/vc/lib;C:/sdk/lib;C:/local/lib"
  • Link manually with wine link -NODEFAULTLIB -LIBPATH:C:/vc/lib -LIBPATH:C:/sdk/lib -LIBPATH:C:/local/lib -OUT:.libs/eqc.exe ltxfileparse.obj ltxfilelex.obj main.obj libcmt.lib msvcrt.lib libcpmt.lib msvcprt.lib libcln.lib libginac.lib ./.libs/libeqc.lib ????

Preparing the OOo SDK

  • 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.
  • In the SDK base directory (e.g. ~/.wine/drive_c/Program Files/OpenOffice.org 3/Basis/sdk), put a file config.guessecho wine; exit 0 and make it executable.
  • Edit settings/settings.mk and add a section for wine:
###########################################################################
#
# Wine specific settings
#
###########################################################################
ifeq "$(PLATFORM)" "wine"
# 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 LD_LIBRARY_PATH=/usr/lib/ure/lib /usr/lib/openoffice/basis3.2/sdk/bin/cppumaker.bin "$@"
  • Go to URE/bin and do ln -s /usr/lib/ure/bin/regmerge ..
  • 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

  • Copy libeqc.lib into ~/.wine/drive_c/local/lib and the headers into ~/.wine/drive_c/local/include/libeqc
  • Edit config.wine BASE= to match your wine installation directory
  • Source the config.wine 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 env LIBTOOLIZE=/usr/local/bin/libtoolize autoreconf -i
  • Run ./configure CC="wine cl" CXX="wine cl" LD="wine cl" --host=i586-mingw32msvc --build=i686-pc-linux-gnu
  • 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