hacking into the c compiler?
#9
It should be possible to use QB64's included Mingw compiler stand-alone.  You would need to add internal\c\c_compiler\bin to your PATH and set a couple more environment variables to point to the compiler's include files and library files.  Hang on a sec...

OK, it seems to be doable.  You need to set a few envars for GCC.  Here's a batch file which will do that:

Code: (Select All)
@echo off

REM v2022.08.25, JSR.
REM FREE FOR USE, ABUSE, OR MODIFICATION BY ANYONE, ANYWHERE.  HAVE FUN WITH IT CUZ I'M DONE WITH IT.

REM Drop this file in your QB64 directory alongside QB64.exe.

REM set up environment vars for direct invocation of QB64's included MinGW C/C++ compiler....

:: WE'LL SKIP THE SETUP IF WE'VE BEEN THROUGH THIS BEFORE....
:: WE'LL USE THE PRESENCE OR ABSENCE OF MGWDIR TO TELL US IF WE'VE PREVIOUSLY SET THE ENVARS.
:: IF MGWDIR ALREADY EXISTS, THEN SKIP THE SETUP SO WE DON'T KEEP ADDING THE SAME
:: STUFF TO THE PATH ENVAR OVER AND OVER EVERY TIME WE RUN THIS BATCH FILE....
if not "%MGWDIR%"=="" goto work


:: SET MGWDIR TO POINT TO MINGW IN OUR QB64 INSTALLATION DIRECTORY,
:: (THIS BATCH FILE SHOULD BE IN THE MAIN QB64 DIRECTORY)....
set MGWDIR=%~dp0internal\c\c_compiler


set PATH=%MGWDIR%\bin;%PATH%
set LIBRARY_PATH=%MGWDIR%\x86_64-w64-mingw32\lib
set CPATH=%MGWDIR%\x86_64-w64-mingw32\include


:work
:: SIMPLY DRAG YOUR C SOURCE FILE ONTO THIS BATCH FILE!
:: NOTE: THE LINE BELOW IS SET TO PRODUCE A 32-BIT EXECUTABLE.
:: REPLACE -m32 WITH -m64 TO GENERATE 64-BIT EXEs
:: (OR REMOVE THE -m OPTION ENTIRELY TO GENERATE THE COMPILER DEFAULT)....
gcc -Wall -O2 -s -m32 --static -o "%~dpn1.exe" "%~1"


:: ...OR YOU COULD COMMENT OUT THE GCC INVOCATION LINE ABOVE
:: AND UNCOMMENT THE LINE BELOW TO OPEN A COMMAND PROMPT....
::start /wait cmd.exe


Save it in your QB64 folder under a batch filename of your choosing (maybe C_COMPILE.BAT or something similar), then you can drag-and-drop your C source file onto the batch file to compile.  (You can use the command line, as well)


[Image: 2022-08-24-205646.png]




Re Dev-C++ and Code::Blocks:

Both Dev-C++ & Code::Blocks have lots of nifty features, but I've only ever tinkered with them.  I usually prefer Notepad++ with the npp_exec plugin on Windows.


Google reveals several forks of Dev-C++; the original Dev-C++, which is quite old, Orwell Dev-C++, which was last updated in 2015, and the much more recent Embarcadero fork  The original and Orwell forks seemed to work just fine when I tested them a few years back.  I once tried setting up an early version of the Embarcadero fork, couldn't make it work, and gave up in disgust, so I can't say how well more recent versions work.

The Dev-C++ forks can be downloaded either with or without bundled C++ compilers.


Code::Blocks is a bit bigger than Dev-C++, but it supports MANY C/C++ compilers.  The most recent official release is a couple of years old, but "nightly builds" are made available frequently.  The nightly build requires the download of two additional files, one containing WxWidget .DLLs and another containig Mingw64 DLLs, all of which are unzipped into the Code::Blocks binary folder.  I have never tried an official release setup file, but I suspect it would be easier.

Code::Blocks should automatically recognize and configure itself for any supported compiler which is installed in its "default" installer-selected location, but that doesn't work for me because I have my own particular programming directory structure.  If C::B misses a compiler, you can tell it where to look for compiler & tools.

I've seen reviewers describe Code::Blocks as a lightweight IDE.  Well... lightness is relative.  While I personally don't consider C::B to be lightweight, it's light as a feather compared to Visual Studio or Eclipse!


As I recall, Dev-C++ & C::B official release both give you the option of downloading either the IDE alone, or the IDE with a compiler pre-installed.  Depending on your needs, you may need to look at the ages of the included compilers.



Quote:Taking this in another direction, is there a way to see the "intermediate" C code that is generated when it compiles your QB64 program to an EXE?


QB64 has a command-line option, "-z", to "Generate C code without compiling to executable".

The compiler SAYS it's generating C++ code, but I have yet to find that generated code, so maybe QB64 it deleting it?



My $0.02 on compilers:
  • Pelles C is a decent C suite which offers a lot, but it MUST be installed.  It''s just one of my quirks that I despise installers; if I can't extract the files, drop them where I want, and run them directly, then I question if I really need them.  But it is a respectable C compiler.
  • Mingw and Mingw64 are Windows ports of GCC.
  • Cygwin is a Windows port of GCC and many other tools, built into a Posix-compatible environment.  It works if you need Posix software on Windows, but it is larger & slower than the Mingw variants.
  • Speaking of Mingw variants, TDM GCC is another.  I really like it, but some people have unkind opinions of its exception handling mods.  Whatever, YMMV.
  • Tiny C is an unbelievably fast C compiler by Fabrice Bellard, author of FFMpeg, QEmu, etc.  While a "big" compiler like GCC might give you better optimization and more detailed error messages, Tiny C really shines for tiny programs, because it adds much less "boilerplate" code to your executable.  For instance: A "Hello, world!" program which compiles to a 11,264-byte EXE under Mingw, compiles down to a 1,536-byte EXE under Tiny C.  I routinely use Tiny C for many of the small one-off utilities that I throw together.  TinyC does NOT optimize, so my rule of thumb is that if the C source file is over about 10,000 bytes, GCC can probably produce a smaller EXE.
  • Portable C Compiler (PCC): I loved it when the project first started, but it's been dormant for years, and Windows versions of the compiler have some bugs.  PCC for Windows has crashed on me a few times during simple compiles.  (ETA The official PCC website, http://pcc.ludd.ltu.se/, is not loading for me.  Didn't work last night or this morning.  Hmmm.)
Reply


Messages In This Thread
hacking into the c compiler? - by madscijr - 08-24-2022, 08:19 PM
RE: hacking into the c compiler? - by Jack - 08-24-2022, 09:53 PM
RE: hacking into the c compiler? - by madscijr - 08-24-2022, 11:49 PM
RE: hacking into the c compiler? - by mnrvovrfc - 08-24-2022, 10:02 PM
RE: hacking into the c compiler? - by madscijr - 08-25-2022, 12:00 AM
RE: hacking into the c compiler? - by Kernelpanic - 08-24-2022, 11:23 PM
RE: hacking into the c compiler? - by madscijr - 08-25-2022, 12:02 AM
RE: hacking into the c compiler? - by Jack - 08-25-2022, 12:08 AM
RE: hacking into the c compiler? - by JRace - 08-25-2022, 02:35 AM
RE: hacking into the c compiler? - by madscijr - 08-25-2022, 02:58 AM
RE: hacking into the c compiler? - by JRace - 08-25-2022, 02:54 PM



Users browsing this thread: 1 Guest(s)