Qbasic: BC.EXE and LINK.EXE - QB64 Wiki

Qbasic: BC.EXE and LINK.EXE

From QB64 Wiki

Jump to: navigation, search

Qbasic used BC.EXE to compile programs and LINK.EXE to link compiled programs together in DOS. The following documentation is supplied for informational purposes only! QB64 has no file size or DOS memory limitations so this process is not necessary!


The following information is supplied by Pete who is the current owner of the Network 54 Qbasic Forum

Say that this example is one Qbasic program:

CLS CLS PRINT "HELLO WORLD" PRINT LINE INPUT "TYPE 1 TO CONTINUE: "; A$ IF A$ = "1" THEN CLS: SLEEP 1: RUN SYSTEM


To break it into two modules, you could do this:

Module1.bas

COMMON SHARED A$ CLS PRINT "HELLO WORLD" PRINT CALL INPUT1 '_______REM THIS IS MAIN MODULE 1 "MODULE1.BAS"

Module2.bas

DECLARE SUB INPUT1() COMMON SHARED A$ SUB INPUT1 LINE INPUT "TYPE 1 TO CONTINUE: "; A$ IF A$ = "1" THEN CLS: SLEEP 1: RUN END SUB SYSTEM '_______REM THIS IS MODULE 2 "MODULE2.BAS"


Compile them each with BC command from the QB dir:

SHELL "BC MODULE1.BAS /O/S/E/X;" SHELL "BC MODULE2.BAS /O/S/E/X;"


Then, link them both together as "MYPROG.EXE"

SHELL "LINK /E MODULE1+MODULE2,MYPROG.EXE,,BCOM45.LIB+QB.LIB"

Note: DOS command lines or batch files can be used instead of SHELL!


The main thing to remember is to use something like COMMON SHARED to pass the variables and that both modules must contain the same exact COMMON SHARED variables in the same order. I usually just copy and paste from the main module to all others to insure that this is done correctly. You can DIM in the modules independently, if the variables will not be shared. You can duplicate labels and line numbers from one module to another.

You can trap errors in the Main Module or in each module. If you use the Main Module only to trap errors, your only problem will be in tracing an error. If the error occurs in another module, the closest a resume next statement after an error break will get is to the call line in the Main Module to the other module routine. I like to put an ER1 as my error handler in each module. Other than that, just call all subs from any module to any other module in the same way. What you really end up with is just a larger program. I have written code up to 301K in 6 modules this way.

I would recommend just taking one or two areas of your present program that are in:

1) A gosub.

2) A sub.

3) A separate function, like a print routine.

Cut that area of code out and save it as module2.bas or what ever you want to call it. Save the cut-down program as the name it has now or call it module1.bas. Try and compile what is left. If it is still too big, cut some more, etc.




Compiling and Linking BAS files in the Qbasic IDE

You can continue to use the QB IDE this way:

1) OPEN your main program as usual (It is now the smaller, cut-down version.)

2) Use LOAD from the File tab to LOAD the module2.bas module on top of your main program. Now, both programs are in the IDE and will run as usual.

You can experiment with the code I provided. Just save 1 as module1.bas and 2 as module2.bas. OPEN module1.bas and then load module2.bas. Run the IDE and it will work. Then, try to compile each and link it as myprog.exe.

It's a bit difficult; however, once you get used to it, you will enjoy 5 times the coding limits you now have in QB.

Please respond with any further questions in this thread if you get stuck and also, I did give you a shell example to compile and link, but you can just drop the shell part and use a DOS prompt if you want.

Pete


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page