hacking into the c compiler? - madscijr - 08-24-2022
Disclaimer: I'm not sure if I posted about this specifically - if I did, sorry for the repeat!
I know the C compiler built into QB64 is "under the hood", and QB64 is not really a C IDE and compiler.
That said, is there a switch or some hidden setting, so you can type a C program in the editor and get it to compile it to an EXE?
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? It would be interesting just to look at, to see what the equivalent C code looks like...
Finally, I was looking at dedicated C compilers and IDEs, looking for something that is super simple to install and use. Has anyone got any experience and/or opinions on any of these for Windows?
cLang
Code Blocks
Dev-C++
Embarcadero C++ Builder
GCC
MinGW
MSYS2
Cygwin
Pelles C
Portable C Compiler (PCC)
Tiny C Compiler
Visual Studio 2022 Community
That's all!
RE: hacking into the c compiler? - Jack - 08-24-2022
hello madscijr
I doubt that you can use the QB64 IDE for C but you can certainly use the C/C++ compilers that's included with QB64
I use Geany , after installing and launching Geany open or create a C file, with the C file open in the editor click on the build menu and select Set Build Commands where you see gcc.exe add the the full path to gcc.exe
unless you want to add the bin folder to your path which I don't like to do
the reason for having a C file open to setup the compiler path is that Geany is a multi language IDE and depending on what type of file is open in the editor you will see different compiler and switches in the Set Build Commands
RE: hacking into the c compiler? - mnrvovrfc - 08-24-2022
(08-24-2022, 08:19 PM)madscijr Wrote: :
That said, is there a switch or some hidden setting, so you can type a C program in the editor and get it to compile it to an EXE?
: But you want to do this with QB64 editor only?
Use Notepad++, ask B+ about it. You could only do worse than that especially on Linux. On that OS there are Geany and Kate but I don't think they would suit you, that is, if you don't write in Python.
What I think is you want to do like Mr. McNeill coming up with that "direntry.h" or something like that. Just use your favorite text editor for it.
LOL you want to avoid the terminal at all costs... the other programs you listed are going to be more difficult to get around if you prefer to code in any language other than C/C++.
MinGW is actually utilized by QB64 for Windows; trying to make use of it another way produces more hassle. c-Lang is an attempt to turn away from C/C++ like C#, another programming system which is another flavor like fruit juice. Cygwin is a total mess, to make a long story short. The installer behaves just like a package manager (such as Pamac or Synaptics) for a Linux distro, too much complication and work only to have a system that works with Linux-oriented "make". Cygwin and MinGW don't get along as well as they should, which makes it even harder. Pelles C might still be used internally by Purebasic, it was around v4 but now I'm not sure. And M$'s product... LOL if you have at least 10GB of hard disk space to spare wasting time and effort with that baby...
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? It would be interesting just to look at, to see what the equivalent C code looks like...
Yes I thought I saw this in your quote! Look for the folders which are at the same level as "c" and "help", but excluding those two, part of "qb64/internal". I think there's also a "source" folder which contains the results of building QB64 itself.
RE: hacking into the c compiler? - Kernelpanic - 08-24-2022
@madscijr - I don't really know what you want.
For Windows: To use GCC for Windows - WinGW: MinGW - GCC for Windows
Unzip to a folder, move to C:\D:\E:\ or something like that in "Program Files". Then adjust the path so that you can call the compiler from any directory - done.
For C & Co. use Notepad++: Notepad++
RE: hacking into the c compiler? - madscijr - 08-24-2022
(08-24-2022, 09:53 PM)Jack Wrote: hello madscijr
I doubt that you can use the QB64 IDE for C but you can certainly use the C/C++ compilers that's included with QB64
I use Geany , after installing and launching Geany open or create a C file, with the C file open in the editor click on the build menu and select Set Build Commands where you see gcc.exe add the the full path to gcc.exe
unless you want to add the bin folder to your path which I don't like to do
the reason for having a C file open to setup the compiler path is that Geany is a multi language IDE and depending on what type of file is open in the editor you will see different compiler and switches in the Set Build Commands
Thank you for your reply.
Is this for Linux only or will it work the same way with Windows?
Thanks again...
RE: hacking into the c compiler? - madscijr - 08-25-2022
(08-24-2022, 10:02 PM)mnrvovrfc Wrote: (08-24-2022, 08:19 PM)madscijr Wrote: :
That said, is there a switch or some hidden setting, so you can type a C program in the editor and get it to compile it to an EXE?
: But you want to do this with QB64 editor only?
Use Notepad++, ask B+ about it. You could only do worse than that especially on Linux. On that OS there are Geany and Kate but I don't think they would suit you, that is, if you don't write in Python.
What I think is you want to do like Mr. McNeill coming up with that "direntry.h" or something like that. Just use your favorite text editor for it.
LOL you want to avoid the terminal at all costs... the other programs you listed are going to be more difficult to get around if you prefer to code in any language other than C/C++.
MinGW is actually utilized by QB64 for Windows; trying to make use of it another way produces more hassle. c-Lang is an attempt to turn away from C/C++ like C#, another programming system which is another flavor like fruit juice. Cygwin is a total mess, to make a long story short. The installer behaves just like a package manager (such as Pamac or Synaptics) for a Linux distro, too much complication and work only to have a system that works with Linux-oriented "make". Cygwin and MinGW don't get along as well as they should, which makes it even harder. Pelles C might still be used internally by Purebasic, it was around v4 but now I'm not sure. And M$'s product... LOL if you have at least 10GB of hard disk space to spare wasting time and effort with that baby...
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? It would be interesting just to look at, to see what the equivalent C code looks like...
Yes I thought I saw this in your quote! Look for the folders which are at the same level as "c" and "help", but excluding those two, part of "qb64/internal". I think there's also a "source" folder which contains the results of building QB64 itself.
Thanks for all the info.
Basically, I just want to use whatever C compiler is bundled with QB64 to compile C programs.
While it would be most convenient to edit the C directly in the QB64 editor, and compile & run right from there, I can use Notepad++ or whatever to edit, and compile however you can get QB64 to compile.
But if it can't be made to do that, or one of those other compilers/IDEs is better (I need to read your notes on those when back at the PC) then I'll give that a try.
Also thanks for clueing me in to where the C code our QB64 is translated into resides, I'll definitely give that a look too.
RE: hacking into the c compiler? - madscijr - 08-25-2022
(08-24-2022, 11:23 PM)Kernelpanic Wrote: @madscijr - I don't really know what you want.
For Windows: To use GCC for Windows - WinGW: MinGW - GCC for Windows
Unzip to a folder, move to C:\D:\E:\ or something like that in "Program Files". Then adjust the path so that you can call the compiler from any directory - done.
For C & Co. use Notepad++: Notepad++
Thanks for your reply, I'll give that page a look.
As for what I'm looking for, no problem, I think between you and the other answers, I have enough to go on for right now!
RE: hacking into the c compiler? - Jack - 08-25-2022
geany is cross platform, it works the same in Windows and Linux
RE: hacking into the c compiler? - JRace - 08-25-2022
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)
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.)
RE: hacking into the c compiler? - madscijr - 08-25-2022
(08-25-2022, 02:35 AM)JRace Wrote: 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 set up environment vars for direct invocation of QB64's included MinGW C/C++ compiler....
REM Drop this file in your QB64 directory alongside QB64.exe.
:: SKIP THE SETUP IF WE'VE BEEN THROUGH THIS BEFORE....
if not "%MGWDIR%"=="" goto work
:: SET MGWDIR TO POINT TO OUR QB64 INSTALLATION DIRECTORY,
:: WHICH SHOULD BE THE DIRECTORY WHICH HOLDS THIS BATCH FILE.
:: WE'LL USE THE PRESENCE OR ABCENSE OF MGWDIR TO TELL US IF WE'VE PREVIOUSLY SET THE ENVARS....
set _a=%~dp0
set MGWDIR=%_a:~0,-1%
set _a=
set PATH=%MGWDIR%\internal\c\c_compiler\bin;%PATH%
set LIBRARY_PATH=%MGWDIR%\internal\c\c_compiler\x86_64-w64-mingw32\lib
set CPATH=%MGWDIR%\internal\c\c_compiler\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 -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)
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. 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 main Code::Blocks folder. I have never tried an official release setup file, but I suspect it would be easier.
Code::Blocks should automatically recognize and configure ittself for any supported compiler which is installed in its "default" installer-selected location, but that's never worked for me because I have my own particular programming directory tree. 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. "Lightweight" seems to be subjective. While I wouldn't call C::B lightweight, it's very light 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 would rather live without 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.
Wow, that's a ton of information here, even a batch file!
Thanks a bunch - I look forward to giving this all a try!
(More tomorrow!)
|