Using gcc to compile C file - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Using gcc to compile C file (/showthread.php?tid=2604) |
RE: Using gcc to compile C file - JRace - 04-20-2024 I also use Notepad++ to compile with QB64PE & MinGW using the NppExec plugin. Here are the lines I use in npes_saved.txt for NppExec. They assume Notepad++ is in a directory parallel to QB64PE; in my case they are "c:\prog\npp" & "c:\prog\qb64pe": Code: (Select All) ::QB64PE compile NppExec can use absolute paths or paths relative to your Notepad++ folder. The example above uses both types of paths. RE: Using gcc to compile C file - bplus - 04-20-2024 +1 thanks @jrace that might be handy with book i am reading (referring to bat file ends page 1) RE: Using gcc to compile C file - JRace - 04-20-2024 Lemme know if it gives you any problems. It's a Frankenstein's monster, pieced together from the suite of batch files that I normally use, but it seems to be friendly. RE: Using gcc to compile C file - Kernelpanic - 04-20-2024 Quote:-Os -s -Wall -static-libgcc -static-libstdc++ -static -fomit-frame-pointer -luser32 -lgdi32 -lshell32@JRace, I looked at the compiler options in your bat file and found them a bit confusing. The description of the individual options for GCC can be found here: GCC - Compiler Options Regarding -fomit-frame-pointer: "Omit the frame pointer in functions that do not require one. This eliminates the instructions for saving, setting up, and restoring the frame pointer." https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fomit-frame-pointer Optimization: "Optimize. Compile optimization requires a little more time and a lot more memory for a large function. With -O, the compiler tries to reduce code size and execution time without performing optimizations that take a lot of compile time." -Wall makes sense because the option displays warnings if the source code was compiled but contains imperfections. In my opinion, something is wrong there. It seems to me that some options interfere with each other, and I can't find this one in the description: -luser32 -lgdi32 -lshell32. I doubt that it makes sense to compile every file with all the specified compiler options. RE: Using gcc to compile C file - JRace - 04-20-2024 Yeah, I could have shortened that line a bit. Feel free to edit that line in the batch file to suit your needs. Anyway:
A person really doesn't need any of these. I suppose my personal option list would be -Wall -Os -static, but your tastes may be different. I recommend -Wall to help create programs with fewer bugs. Any optimization setting is up to the creator. I've always been fond of -Os. If you don't use -static linking, then you may need to copy some DLLs from the GCC bin\ folder. RE: Using gcc to compile C file - Kernelpanic - 04-20-2024 @JRace, the problem ultimately lies in the fact that you absolutely want to use QB64's GCC. (The program for deleting it is yours, right? And that's well!) Bat files cannot be used meaningfully if they are not in the path. I've known this since 1995, when I was still programming with QuickC, and more (I have all QuickC versions with manual 1.0, 2.0, 2.5 the last one). Back then you had to write this into the autoexec.bat for it to work. The compiler options for the Quickc compiler were also in there. So that you can access it from any directory. The most practical use is to include the GCC in the path, and if you want to make it easier you can create a bat file with: -o -Wall. This should apply to the vast majority of all files. For the rest, just enter it directly. That was my autoexec.bat file. The instructions for the QuickC compiler were set so that I only had to call it on the command line with a bat file (the reason for this was that many programs were 1/3 smaller than when compiled in the QuickC IDE became.): Code: (Select All) echo off The autoexec.bat Code: (Select All)
RE: Using gcc to compile C file - JRace - 04-20-2024 AUTOEXEC.BAT is good for permanent, system-wide settings, but for compilation we only need a short-term, temporary solution. The batch file I posted must be run from the QB64PE directory or from the MinGW directory. This fact could be changed with a small modification to put QB64PE's location into the batch file. My concern was to make the batch file "just work" without too much customization. The batch file DOES set the path before running the compiler, even though setting the path for GCC is NOT mandatory. The batch file determines where GCC.EXE is located and could call the compiler directly if we wanted it to. GCC knows where its own files are located relative to itself, so GCC does not actually need the PATH. The PATH and environment variables can be set at ANY time before running the compiler. That setting does not need to be permanent or system-wide. The PATH can be set "on the fly" from the command prompt, either by typing or by using a batch file such as this one, which sets the PATH variable then opens a command prompt: Code: (Select All) @echo off I currently have 18 compilers and interpreters ready for immediate use, with many more available if needed. Imagine how long and confusing my PATH would be if I added ALL of those directories to it. (I guess I'm a language hoarder.) Each of these compilers has batch files which set the PATH and other environment variables only when needed. Then, when the compiler is finished and the batch file ends, Windows forgets all of those changes. Many years ago I created similar batch files for Quick C, Turbo C, Small C, DeSmet C, and any other compiler that I found myself using. Here is a batch file I wrote to compile programs using Quick C: Code: (Select All) @echo off When I started using Windows I was so weary of creating so many batch files that I wrote a program generator that can create many batch files from one .INI file. It's all quite clean, simple, and very functional. RE: Using gcc to compile C file - Kernelpanic - 04-21-2024 @JRace - the autoexec.bat is from 1995! From Windows XP onwards it was no longer necessary. It was still there, but it was empty because the system no longer took it into account. The autoexec.bat and the config.sys were only relevant for the DOS-based versions of Windows, i.e. until Windows Me. RE: Using gcc to compile C file - JRace - 04-21-2024 (04-21-2024, 07:22 PM)Kernelpanic Wrote: @JRace - the autoexec.bat is from 1995! From Windows XP onwards it was no longer necessary. It was still there, but it was empty because the system no longer took it into account. Which is why my original post never mentioned AUTOEXEC.BAT. YOU mentioned it in your previous post. I guess I misunderstood the intent of that post. I think I misread the intent of that post. I thought maybe you did not understand how my batch script worked, so I went on to explain how the batch file worked, and that a permanent PATH setting is not needed. I then listed a batch script from my own Quick C installation which demonstrated that permanent PATH settings are not necessary for compilers, even in DOS. If a person has just one compiler or is using one particular compiler all day, every day, then a permanent PATH setting can be justified, but my compiler batch scripts follow a "set it, use it, forget it" philosophy that has worked very well for years. (EDIT: I've tweaked the batch script in my first post and added a few more comments. Not a @TerryRitchie level of comments, but a few which may be useful.) RE: Using gcc to compile C file - TerryRitchie - 04-22-2024 (04-21-2024, 07:59 PM)JRace Wrote: Not a @TerryRitchie level of comments, but a few which may be useful.)LOL, yeah, my code gets wordy, but when I revisit my code later I'm sure glad I took the time to do it. Plus, I need to comment code very well for the tutorial so I must stay in the habit. |