building fbc for Windows - for beginners by a beginner

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

building fbc for Windows - for beginners by a beginner

Post by srvaldez »

Download a mingw distribution and setting up a bash shell
The only solution that I found is by using msys2, note that in this example, we copy a mingw distribution that's not part of msys2, therefore, it's not intended to be updated by using pacman.

I am assuming that msys2 will be installed in C:\msys64, which is the default.

First download msys2 https://sourceforge.net/projects/msys2/ ... e/download

Download the 32-bit gcc toolchain 7.3.0 https://sourceforge.net/projects/mingw- ... v5-rev0.7z

Download the 64-bit gcc toolchain 7.3.0 https://sourceforge.net/projects/mingw- ... v5-rev0.7z

Install msys2

From the msys shell install the following

Code: Select all

pacman -S make
pacman -S patch
pacman -S git
pacman -S zip
pacman -S p7zip
Extract i686-7.3.0-release-win32-sjlj-rt_v5-rev0.7z into the msys64 folder
Extract x86_64-7.3.0-release-win32-sjlj-rt_v5-rev0.7z into the msys64 folder

Copy C:\mingw64\mingw32\opt\lib\libffi-3.2.1\include\ffi.h into C:\mingw64\mingw32\i686-w64-mingw32\include
Copy C:\mingw64\mingw32\opt\lib\libffi-3.2.1\include\ffitarget.h into C:\mingw64\mingw32\i686-w64-mingw32\include
Copy C:\mingw64\mingw64\opt\lib\libffi-3.2.1\include\ffi.h into C:\mingw64\mingw64\x86_64-w64-mingw32\include
Copy C:\mingw64\mingw64\opt\lib\libffi-3.2.1\include\ffitarget.h into C:\mingw64\mingw64\x86_64-w64-mingw32\include

Install fbc into msys64
Download fbc730 for mingw toolchain
Extract the fbc370 archive
launch mingw32.exe
cd into the fbc730 folder
sh install.sh

Open a new document in notepad and paste following patch by StW, the patch is needed to build fbc 32-bit
diff --git a/makefile b/makefile
index 8145b4f..512b81b 100644
--- a/makefile
+++ b/makefile
@@ -242,7 +242,12 @@ else
# For DJGPP, always use x86 (DJGPP's uname -m returns just "pc")
ifeq ($(TARGET_OS),dos)
TARGET_ARCH := x86
- else
+ # For MSYS2, use default compilers (uname -m returns MSYS2's shell architecture)
+ else ifneq ($(findstring MINGW32,$(uname)),)
+ TARGET_ARCH := x86
+ else ifneq ($(findstring MINGW64,$(uname)),)
+ TARGET_ARCH := x86_64
+ else
TARGET_ARCH = $(shell uname -m)
endif
endif
Save as C:\msys64/tmp/fb-make-patch.txt

launch mingw32.exe

Code: Select all

git clone https://git.code.sf.net/p/fbc/code fbc-code

Code: Select all

cd ~/fbc-code
patch -N -Z -p1 < "/c/msys64/tmp/fb-make-patch.txt"
Open a new document in notepad and add the following text
ENABLE_STANDALONE=1
Save As "config.mk" into the folder fbc-code, which if msys2 was installed using the defaults, would be C:\msys64\home\your-user-account\fbc-code

Now go back to mingw32.exe and type

Code: Select all

make
cd lib/win32
make
rm *.def
rm makefile
cd ../..
make mingw-libs

mkdir -p bin/win32
wget http://www.godevtool.com/Gorc.zip
7z e Gorc.zip
cp GoRC.exe bin/win32
rm *.gif
rm GoRC.exe
rm GoRC.htm
rm Gorc.zip

cp /c/msys64/mingw32/bin/ar.exe bin/win32
cp /c/msys64/mingw32/bin/as.exe bin/win32
cp /c/msys64/mingw32/bin/dlltool.exe bin/win32
cp /c/msys64/mingw32/bin/gcc.exe bin/win32
cp /c/msys64/mingw32/bin/gdb.exe bin/win32
cp /c/msys64/mingw32/bin/gprof.exe bin/win32
cp /c/msys64/mingw32/bin/ld.exe bin/win32

mkdir -p bin/libexec/gcc/i686-w64-mingw32/7.3.0
cp /c/msys64/mingw32/libexec/gcc/i686-w64-mingw32/7.3.0/cc1.exe bin/libexec/gcc/i686-w64-mingw32/7.3.0

make bindist
Last edited by srvaldez on Jun 10, 2019 21:24, edited 2 times in total.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: building fbc for Windows - for beginners by a beginner

Post by srvaldez »

build fbc-64bit
Rename fbc-code to fbc-code32
launch mingw64.exe

Code: Select all

git clone https://git.code.sf.net/p/fbc/code fbc-code
cd to fbc-code
Open a new document in notepad and add the following text
ENABLE_STANDALONE=1
Save As "config.mk" into the folder fbc-code

Code: Select all

make
cd lib/win32
Make
cp *.dll.a ../win64
cd ../..
make mingw-libs
mkdir -p bin/win64
wget http://www.godevtool.com/Gorc.zip
7z e Gorc.zip
cp GoRC.exe bin/win64
rm *.gif
rm GoRC.*
rm Gorc.zip

cp /c/msys64/mingw64/bin/ar.exe bin/win64
cp /c/msys64/mingw64/bin/as.exe bin/win64
cp /c/msys64/mingw64/bin/dlltool.exe bin/win64
cp /c/msys64/mingw64/bin/gcc.exe bin/win64
cp /c/msys64/mingw64/bin/gdb.exe bin/win64
cp /c/msys64/mingw64/bin/gprof.exe bin/win64
cp /c/msys64/mingw64/bin/ld.exe bin/win64

mkdir -p bin/libexec/gcc/x86_64-w64-mingw32/7.3.0
cp /c/msys64/mingw64/libexec/gcc/x86_64-w64-mingw32/7.3.0/cc1.exe bin/libexec/gcc/x86_64-w64-mingw32/7.3.0

make bindist
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: building fbc for Windows - for beginners by a beginner

Post by integer »

THANK YOU
THANK YOU
THANK YOU

I'm tried many times to generate the compiler, but never success.
This will help.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: building fbc for Windows - for beginners by a beginner

Post by srvaldez »

hello integer
I am interested whether you succeeded or not.
note also that you could use another mingw distribution with different gcc-toolchain version, but I recommend that you use the /threads-win32/sjlj/ branch, as that is what coderJeff uses.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: building fbc for Windows - for beginners by a beginner

Post by deltarho[1859] »

If ever a thread should be made a 'sticky' this one should be. A phenomenal amount of reading has been done to be able to write the two opening posts above and that should be recognized if nothing else.

However, there is an easier way to get gcc 7.3.0 and that is to go /stw/builds/_custom/gcc730 where we have 32-bit and 64-bit (04-Oct-2018). In the directory above that we have gcc 8.1.0.

With my Encrypternet.exe most of the application session time is file input/output so any 'crunch time' optimization plays only a small role so there is little performance difference between using different versions of gcc. The obvious difference is with the size of the resulting binaries.

Code: Select all

Using -gen gcc -Wc -O3
gcc 32-bit 64-bit
 
5.2 129024 128000
7.3 131584 Problem with -O3 ( 121344 with -O2 )
8.1 128000 124416
9.1 122880 121856
Notice how the binaries get smaller with each new version except for gcc 7.3.

With 9.1 I used the strip command because srvaldez did not use ENABLE_STANDALONE=1 in his build, but that is no big deal.

However, more importantly gcc 7.3 fails to compile in 64-bit using -O3 with "^libbacktrace could not find executable to open". This does not happen with every 64-bit compilation but I have seen it a few times. "^libbacktrace could not find executable to open" was an issue in old versions of gcc but was fixed before 5.2. I have no idea what it is, but, obviously, we do not need it. It would seem that -O1 and -O2 are OK. Many members steer clear of using -O3 and prefer -O2, as does srvaldez, so the occasional failure with -O3 may not be a deal killer.

7.4 may be a better bet but I cannot find a /threads-win32/sjlj/ branch for 7.4.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: building fbc for Windows - for beginners by a beginner

Post by srvaldez »

hello deltarho[1859]
yes, my goal was to use gcc-7.4 but was unable to find it.
Post Reply