PlanetSquires Forums

Support Forums => PlanetSquires Software => Topic started by: Paul Squires on September 08, 2018, 01:00:49 PM

Title: Compiling the FreeBASIC compiler
Post by: Paul Squires on September 08, 2018, 01:00:49 PM
A year or so ago, I downloaded the FreeBASIC compiler source code and tried to compile it with WinFBE. There were problems at the time so I gave up on it.
Today, I decided to give it another try. I was amazed at how easy it was to compile a successful FBC exe this time  :)
Downloaded the code from GitHub. fbc-master
Extracted the zip
Created a WinFBE project
Add The following the "Other Options" in the Project settings (per Marc's post below):    -d ENABLE_STANDALONE
Loaded all files from the \src\compiler folder (this took a while) :)
Closed all of the open Tabs because there was obviously way too many open
Opened the "fbc.bas" file and set it to be the "main" file
All of the other files in the folder were already set to the correct file types based on their file extensions. Cool. I didn't have to do anything special for those files.
Pressed the compile button on fbc.bas
In the status bar you see all of the source code files being compiled from *.bas to *.o object files
The fbc exe gets created 1144KB
Subsequent compiles are lightning fast because only the changed source files are re-compiled. Pretty cool.

Anyway, a pretty insignificant post but it made me happy that if I ever get the nerve to try to hack the compiler source code that at least I'll be able to make working copies of the compiler without having to resort to makefiles and MSYS environment.


Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 09, 2018, 05:16:57 AM
Hello Paul
I wanted to try that now, but I'm probably not there yet so far.

With me the process breaks off with a single error. :-)
Title: Re: Compiling the FreeBASIC compiler
Post by: James Fuller on September 09, 2018, 07:02:38 AM
Paul,
  That is not insignificant!! Good work!
  Both 32 and 64 bit??

James
Title: Re: Compiling the FreeBASIC compiler
Post by: Marc Pons on September 09, 2018, 08:23:46 AM
Hi Paul
very good and simple solution , worked fine and compiled both 32 and 64
Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 09, 2018, 02:29:06 PM
hmmmmmm. I get following mistakes:

G:\WinFBE_Suite\FreeBASIC-1.06.0\bin\win32\ld.exe: G:\fbc-master\src\compiler\fbc.o: bad reloc address 0x60 in section `.data'

linking failed: 'G:\WinFBE_Suite\FreeBASIC-1.06.0\bin\win32\ld.exe' terminated with exit code 1
Can someone tell me why I'm getting this mistake?
Title: Re: Compiling the FreeBASIC compiler
Post by: Wilko Verweij on September 09, 2018, 04:15:21 PM
Hi Joerg,
What do you see if you go to the tab 'Compiler log file'?
Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 10, 2018, 05:26:23 AM
Quote from: Wilko Verweij on September 09, 2018, 04:15:21 PM
Hi Joerg,
What do you see if you go to the tab 'Compiler log file'?
Hello Wilko

I've attached the LOG file.
Title: Re: Compiling the FreeBASIC compiler
Post by: Paul Squires on September 10, 2018, 08:35:03 AM
The missing function, FBGETOPTION, is located in "FB.BAS". I didn't notice a "FB.O" compiled object in the log output so maybe you didn't add fb.bas to the project?
Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 10, 2018, 09:25:33 AM
Hello Paul
You are my hero today. :-)
The Fb.bas in my directory only had a size of 370 bytes.
The original fb.bas file had 35,683 bytes.
In this case the file was probably damaged.
Now I have replaced the file and can compile it without problems.
Many thanks for this not "incidental" information and for viewing the log file.
Title: Re: Compiling the FreeBASIC compiler
Post by: Jean-pierre Leroy on September 10, 2018, 10:12:07 AM
Just a question : FreeBASIC compiler is written in FreeBASIC ?
Title: Re: Compiling the FreeBASIC compiler
Post by: Paul Squires on September 10, 2018, 10:29:16 AM
Quote from: Jean-pierre Leroy on September 10, 2018, 10:12:07 AM
Just a question : FreeBASIC compiler is written in FreeBASIC ?
The main compiler is written in FreeBASIC however the runtime library and graphics libraries are written in C. Imortis starting re-writing the runtime library in FB https://www.freebasic.net/forum/viewtopic.php?f=8&t=25923
Title: Re: Compiling the FreeBASIC compiler
Post by: Marc Pons on September 10, 2018, 11:37:54 AM
Hi Paul

As I"ve already said, it compiled fine for 32/64, but after that new created fbc.exe does not work very well

the connected As.exe  application and linker need to know where to be found

so you have to put a complementary compiling argument        -d ENABLE_STANDALONE

before creating the exe  put it on the project options  for 32 and 64

that compiling option will assume the relative position of the needed folders...

Title: Re: Compiling the FreeBASIC compiler
Post by: Marc Pons on September 10, 2018, 02:03:10 PM
Hi Paul again,

I was so interrested on your trick to simplify the fbc.exe compilation and jump immediatly on it,
because i was trying to implement 2 new intrinsic defines on the compiler (i've put a request, but did not expect fast reaction)

__FB_CONSOLE__   and   __FB_GUI__

to make something like that #if __FB_CONSOLE__
print "Console mode"
print : print "Any key to close"
sleep
#endif

#if __FB_GUI__
#include "windows.bi"
messagebox(0, "Gui mode", "info",0)
#endif


and i suceed much faster with your ide project feature

only adding some lines in 4 files is enougth
in fbc.bas ; fb.bi ; fb.bas ; symb-define.bas      the lines are marked with   '***** console/gui

it work without any difficulty on 32 or 64   :)

i put under the modified files on the zip   and the exe files created

i will put a link on freebasic forum to here .
Title: Re: Compiling the FreeBASIC compiler
Post by: Marc Pons on September 15, 2018, 05:49:37 AM
hi
to inform the  rolling freebasic version has implemented the __FB_GUI__ define
so now we can test the -s console or -s gui compiling argument, in fact 1 define is enougth because as default (without -s option) a console is visible

test with
#if __FB_GUI__
#include "windows.bi"
messagebox(0, "Gui mode", "info",0)
#else
print "Console mode"
print : print "Any key to close"
sleep
#endif


to José (from freebasic forum)
Quote
Re: Feature request: instrisic Defines for console / gui mode
Postby Josep Roca » Sep 13, 2018 14:37
If the suggestion is implemented, additional features can be added like flagging as an error the use of SLEEP without parameters in an application compiled as a Windows GUI.

your request is not implemented, in fact i was also trying to implement that (plus the fxm remark)
but not easy (at least for me ) to do it.

as a general remark, you can see the quite fast reaction of freebasic mainteners to requests.
I think with the talented people here, it is a strong possibility to correct, adapt, expand the freebasic compiler.
Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 18, 2018, 02:41:33 PM
Hello Together
I compiled the compiler with WinFBE without errors, but didn't use it at all.
Now I came up with exactly this idea. :-)

But source code, which can be compiled with the original compilers without error messages, aborts with the self-created compilers.

Below the error message.

FreeBASIC Compiler - Version 1.06.0 (09-17-2018), built for win64 (64bit)
Copyright (C) 2004-2016 The FreeBASIC development team.
target: win64, x86-64, 64bit
compiling: G:\WinFBE_Suite\Sample_Projects\TEST-PROJEKT\Window.bas -o G:\WinFBE_Suite\Sample_Projects\TEST-PROJEKT\Window.c (main module)
G:\WinFBE_Suite\Sample_Projects\TEST-PROJEKT\Fenster.bas(619) error 23: File not found, "WinFormsX\WinFormsX.bi"

Do the self-created compilers work for you?
Title: Re: Compiling the FreeBASIC compiler
Post by: Johan Klassen on September 18, 2018, 04:41:04 PM
hello Joerg Buckel
my tests compile and run ok.
for a test, please download a new copy of the FreeBASIC sources from https://github.com/freebasic/fbc
compile that and after you have replaced fbc.exe with the newly compied fbc
open the project: G:\WinFBE_Suite\Sample_Projects\VisualDesigner\FormTest.wfbe
and select build to Win64 GUI(Release)
tell me if it compiles and runs or not.
Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 19, 2018, 08:35:51 AM
Hello Johan

Thank you for your feedback.
I did it the way you suggested.

The result or error message is the same.
I uninstall everything and reinstall everything. Then I see if there is a difference.
Title: Re: Compiling the FreeBASIC compiler
Post by: Joerg B. on September 19, 2018, 11:46:30 AM
Hello Johan

I'm almost ashamed to admit it....
I had recreated the project and simply forgot to set the "-d ENABLE_STANDALONE" switch in the project properties.

I have now done this and can use the two compilers I created.