harbour / core

Portable, xBase compatible programming language and environment
https://harbour.github.io/
Other
322 stars 207 forks source link

cross-compiling on Linux to Win32/64 target #281

Open efa opened 1 year ago

efa commented 1 year ago

hi, I downloaded the nightly: harbour-nightly-win.7z | 2022-10-17 and extracted to /home/efa/c/harbour_win32

I'm using this script to cross-build:

if (test "" = "$1") then
   echo ERROR: harbour need a PRG file name
   echo "Syntax: $ harbour <source.prg> [win [32]]|[mac [arm]]"
   exit
fi

deps="hbct.hbc xhb.hbc"
if (test "$2" = "win") then
   # set env vars for mingw ...
   if (test "$3" = "32") then
      echo "Cross-building for Win32 ..."
      export HOST=i686-w64-mingw32
   else
      echo "Cross-building for Win64 ..."
      export HOST=x86_64-w64-mingw32
   fi
   export CROSS=${HOST}-
   export CC=${CROSS}gcc

   # set env vars for harbour ...
   export HB_WITH_CURSES=no
   export HB_BUILD_3RDEXT=no
   export HB_BUILD_CONTRIBS=no
   export HB_BUILD_DYN=no
   export HB_BUILD_NAME=$HOST
   export HB_CCPATH=/usr/bin/
   export HB_CCPREFIX=$CROSS
   export HB_COMPILER=mingw64 # or mingw, clang
   export HB_CPU=x86-64 # or x86
   if (test "$3" = "32") then
      export HB_COMPILER=mingw # or mingw, clang
      export HB_CPU=x86
   fi
   export HB_HOST_BIN=$HOME/c/harbour-core/bin/linux/gcc
   export HB_PLATFORM=win
  #export HB_USER_CFLAGS=--sysroot=%SYSROOT%
   export HB_USER_LDFLAGS="-L$HOME/c/harbour_win32/lib/win/mingw"
fi
echo "Running: $HOME/c/harbour-core/bin/linux/gcc/hbmk2 -workdir=. -inc $1 $deps"
$HOME/c/harbour-core/bin/linux/gcc/hbmk2 -workdir=. -inc $1 $deps

while build to Win32 work:

$ harbour SNATOTAP.PRG win 32
Cross-building for Win32 ...
Running: /home/efa/c/harbour-core/bin/linux/gcc/hbmk2 -workdir=. -inc SNATOTAP.PRG hbct.hbc xhb.hbc
hbmk2: Processing environment options: -plat=win -comp=mingw -cpu=x86
       -build=i686-w64-mingw32
hbmk2: Compiling Harbour sources...
Harbour 3.2.0dev (r-2084736466)
Copyright (c) 1999-2021, https://harbour.github.io/
Compiling 'SNATOTAP.PRG'...
Lines 951, Functions/Procedures 4
Generating C source output to './SNATOTAP.c'... Done.
hbmk2: Compiling...
hbmk2: Linking... SNATOTAP.exe

I got linking error targeting 64 bit Windows:

$ harbour SNATOTAP.PRG win
Cross-building for Win64 ...
Running: /home/efa/c/harbour-core/bin/linux/gcc/hbmk2 -workdir=. -inc SNATOTAP.PRG hbct.hbc xhb.hbc
hbmk2: Processing environment options: -plat=win -comp=mingw64 -cpu=x86-64
       -build=x86_64-w64-mingw32
hbmk2: Compiling Harbour sources...
Harbour 3.2.0dev (r-2084736466)
Copyright (c) 1999-2021, https://harbour.github.io/
Compiling 'SNATOTAP.PRG'...
Lines 951, Functions/Procedures 4
Generating C source output to './SNATOTAP.c'... Done.
hbmk2: Compiling...
hbmk2: Linking... SNATOTAP.exe
/usr/bin/x86_64-w64-mingw32-ld: skipping incompatible /home/efa/c/harbour_win32/lib/win/mingw/libhbct.a when searching for -lhbct
....
/usr/bin/x86_64-w64-mingw32-ld: skipping incompatible /home/efa/c/harbour_win32/lib/win/mingw/libhbmainstd.a when searching for -lhbmainstd
collect2: error: ld returned 1 exit status
hbmk2: Error: Running linker. 1
/usr/bin//x86_64-w64-mingw32-gcc ./SNATOTAP.o ./_hbmkaut_SNATOTAP.o   -L/home/efa/c/harbour_win32/lib/win/mingw -mconsole -Wl,--start-group -lhbct -lxhb -lhbtip -lhbfship -lhbxpp -lhbwin -lpng -lhbextern -lhbdebug -lhbvm -lhbrtl -lhblang -lhbcpage -lgtcgi -lgtpca -lgtstd -lgtwin -lgtwvt -lgtgui -lhbrdd -lhbuddall -lhbusrrdd -lrddntx -lrddcdx -lrddnsx -lrddfpt -lhbrdd -lhbhsx -lhbsix -lhbmacro -lhbcplr -lhbpp -lhbcommon -lhbmainstd -lwinmm -lkernel32 -luser32 -lgdi32 -ladvapi32 -lws2_32 -liphlpapi -lwinspool -lcomctl32 -lcomdlg32 -lshell32 -luuid -lole32 -loleaut32 -lmpr -lmapi32 -limm32 -lmsimg32 -lwininet   -Wl,--end-group -oSNATOTAP.exe  -L/home/efa/c/harbour-core/lib

Is the nightly package 32 bit only?

lailton commented 1 year ago

### Why your command line show it: /home/efa/c/harbour_win32/lib/win/mingw/libhbct.a

Should be: /home/efa/c/harbour_win32/lib/win/mingw64/libhbct.a

Probably something wrong with the path, but I can be wrong.

efa commented 1 year ago

there is no mingw64 directory in the Sourceforge 7zip nightly package:

~/c/harbour_win32/lib$ tree -d
.
└── win
    └── mingw

2 directories

Those links are the right ones: https://sourceforge.net/projects/harbour-project/files/binaries-windows/3.0.0/ https://sourceforge.net/projects/harbour-project/files/binaries-windows/nightly/ ?

lailton commented 1 year ago

In order to build to 64bits you need to have the libraries for 64bits too.

( the way is exactly the same you did to construct the binaries and libraries for 32 ).

efa commented 1 year ago

sorry, I didn't explained me well. I do not have Windows, I'm using Linux and want cross-compile to Windows. For 32 bit I simply downloaded the already built 7zip win package available at: https://sourceforge.net/projects/harbour-project/files/binaries-windows/nightly/ Does exist a 64 bit Win version?

lailton commented 1 year ago

You can build it by yourself.

#!/bin/bash

export HB_PLATFORM="win"
export HB_CCPREFIX="/usr/local/mingw/bin/x86_64-w64-mingw32-"
export HB_INSTALL_PREFIX="/Developer/harbour/"
export HB_HOST_BIN="/Developer/harbour/bin"
export HB_COMPILER="mingw64"
export HB_BUILD_CONTRIBS=

export HB_WITH_PCRE=local
export HB_WITH_ZLIB=local
export HB_WITH_BZIP2=local
export HB_WITH_JPEG=local
export HB_WITH_PNG=local
export HB_WITH_TIFF=local
export HB_WITH_LIBHARU=local
export HB_WITH_SQLITE3=local

PATH=/usr/local/mingw/bin/:$PATH

Long time ago I had used it, adjust to your path and then:

git clone --depth=1 https://github.com/harbour/core.git harbour
cd harbour
make

after that you should have the binaries and libraries for 64bits.

efa commented 1 year ago

does exist a pre-built binaries for Win64?

lailton commented 1 year ago

I don't think so.

lailton commented 1 year ago

Try this one: https://drive.google.com/file/d/1uZzhOoPm8fazSEQfLsJmxl-qEYh_5JM4/view?usp=share_link

efa commented 1 year ago

thank you for the package, I will try that!

fperillo commented 1 year ago

Hi, the nightly build is 32 bit only.

If I remember correctly, the build runs on a 32 bit old windows server 2003...

Il Mar 20 Dic 2022, 04:06 efa @.***> ha scritto:

thank you for the package, I will try that!

— Reply to this email directly, view it on GitHub https://github.com/harbour/core/issues/281#issuecomment-1357969996, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6LSYZH4YV4ESMN2IIFLODWOCIZVANCNFSM6AAAAAAS5Z4BJA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

efa commented 1 year ago

Try this one

work, here the generated 32 and 64 bit binaries: https://drive.google.com/file/d/1IXi96rRz51FGqjM9RZbgG_YEUPXBUAJ6

THANK YOU

efa commented 1 year ago

here attached the final version of the bash script used to cross-build:

#!/bin/sh
# Copyright 2022 Valerio Messina, harbour 1.1.0 2022/12/19
#   harbour is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License ver 3
# this script (cross)compile a PRG file with harbour
# Syntax: $ harbour <source.prg> [win [32]]|[mac [arm]]

if (test "" = "$1") then
   echo ERROR: harbour need a PRG file name
   echo "Syntax: $ harbour <source.prg> [win [32]]|[mac [arm]]"
   exit
fi
rm *.o *.c 2> /dev/null
deps="hbct.hbc xhb.hbc"
#deps=""

if (test "$2" = "win") then
   # set env vars for mingw ...
   if (test "$3" = "32") then
      echo "Cross-building for Win32 ..."
      export HOST=i686-w64-mingw32
   else
      echo "Cross-building for Win64 ..."
      export HOST=x86_64-w64-mingw32
   fi
   export CROSS=${HOST}-
   export CC=${CROSS}gcc

   # set env vars for harbour ...
   export HB_WITH_CURSES=no
   export HB_BUILD_3RDEXT=no
   export HB_BUILD_CONTRIBS=no
   export HB_BUILD_DYN=no
   export HB_BUILD_NAME=$HOST
   export HB_CCPATH=/usr/bin/
   export HB_CCPREFIX=$CROSS
   export HB_COMPILER=mingw64 # or mingw, clang
   export HB_CPU=x86-64 # or x86
   if (test "$3" = "32") then
      export HB_COMPILER=mingw # or mingw, clang
      export HB_CPU=x86
   fi
   export HB_HOST_BIN=$HOME/c/harbour-core/bin/linux/gcc
   export HB_PLATFORM=win
   export HB_USER_LDFLAGS="-L$HOME/c/harbour_win/lib/win/mingw64"
   if (test "$3" = "32") then
      export HB_USER_LDFLAGS="-L$HOME/c/harbour_win/lib/win/mingw"
   fi
fi
if (test "$2" = "mac") then
   echo "Cross-building for macOS64 ..."
   # set env vars for osxcross ...
   export SDK_VERSION=11.1   # set built tools generation
   export ODVER=20.2
   export OHOST=i386-apple-darwin$ODVER   # only till darwin17
   export OHOST=x86_64-apple-darwin$ODVER
   if (test "$3" = "arm") then
      echo "arm64 Apple Silicon"
      export OHOST=arm64-apple-darwin$ODVER
   fi
   export OCROSS=$OHOST-
   export OSXROOT=/opt/osxcross
   export OSX=$OSXROOT/target/bin
   export OSXDEPS=$OSXROOT/target/macports
   export OSXQUARTZ=$OSXROOT/target/quartz
   export OSXCROSS_TARGET=darwin$ODVER
   export MACOSX_DEPLOYMENT_TARGET=$SDK_VERSION   # used for macports
   export OSXCROSS_PKG_CONFIG_USE_NATIVE_VARIABLES=1
   export PKG_CONFIG_LIBDIR=$OSXDEPS/pkgs/opt/local/lib/pkgconfig:$OSXDEPS/pkgs/opt/local/share/pkgconfig
   export PKG_CONFIG_PATH=$PKG_CONFIG_LIBDIR
   export PATH=$OSX:$PATH

   # set env vars for harbour ...
   export TOOLCHAINDIR=$OSXROOT
   export TOOLCHAIN_DIR=$OSXROOT
   export HB_WITH_CURSES=no
   export HB_BUILD_3RDEXT=no
   export HB_BUILD_CONTRIBS=no
   export HB_BUILD_DYN=no
   export HB_BUILD_NAME=$OHOST
   export HB_CCPATH=$OSX
   export HB_CCPREFIX=$OCROSS
   export HB_COMPILER=clang
   export HB_CPU=x86-64
   if (test "$3" = "arm") then
      export HB_CPU=arm
   fi
   export HB_HOST_BIN=$HOME/c/harbour-core/bin/linux/gcc
   export HB_PLATFORM=darwin
   export HB_USER_LDFLAGS="-L$HOME/c/harbour_macOS.amd64/lib/darwin/clang -L$OSXROOT/target/lib/"
   if (test "$3" = "arm") then
      export HB_USER_LDFLAGS="-L$HOME/c/harbour_macOS.arm64/lib/darwin/clang -L$OSXROOT/target/lib/"
   fi
fi
if (test "" = "$2") then   # native compile
   echo "Native building for Linux64 ..."
fi

echo "Running: $HOME/c/harbour-core/bin/linux/gcc/hbmk2 -workdir=. -inc $1 $deps"
$HOME/c/harbour-core/bin/linux/gcc/hbmk2 -workdir=. -inc $1 $deps
#rm *.o *.c 2> /dev/null
echo ""

hope will help someone. THANK YOU

lailton commented 1 year ago

Great :octocat: