Compiling the FreeBASIC compiler

Started by Paul Squires, September 08, 2018, 01:00:49 PM

Previous topic - Next topic

Paul Squires

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.


Paul Squires
PlanetSquires Software

Joerg B.

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. :-)
Greeting from Germany

Joerg

James Fuller

Paul,
  That is not insignificant!! Good work!
  Both 32 and 64 bit??

James

Marc Pons

Hi Paul
very good and simple solution , worked fine and compiled both 32 and 64

Joerg B.

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?
Greeting from Germany

Joerg

Wilko Verweij

Hi Joerg,
What do you see if you go to the tab 'Compiler log file'?

Joerg B.

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.
Greeting from Germany

Joerg

Paul Squires

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?
Paul Squires
PlanetSquires Software

Joerg B.

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.
Greeting from Germany

Joerg

Jean-pierre Leroy

Just a question : FreeBASIC compiler is written in FreeBASIC ?

Paul Squires

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
Paul Squires
PlanetSquires Software

Marc Pons

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...


Marc Pons

#12
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 .

Marc Pons

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.

Joerg B.

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?
Greeting from Germany

Joerg