Why is -Cg forced and cannot be removed on Lazarus? lazarus / 11-Options ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2025-06-23 10:15 Hey Y'All, So, in my quest to suss out why my ncurses programs, when compiled under Lazarus, were misbehaving I FINALLY got it down to one thing: The -Cg or Generate PIC code is hardcoded in the options and cannot be removed!!!  I then had a nose around the project options and I found quite the issue!!! This is what I get when I press the "Show Options" button under Project Options->Compiler Options->Custom Options: Code: [Select]/home/gcarreno/FreePascal/fpc/bin/x86_64-linux/fpc.sh -MObjFPC -Scghi -Cg -O1 -gw3 -gl -l -vewnhibq -Fi../../bin/lib/x86_64-linux -Fu../../src/application -Fu../../src/forms -Fu../../src/base -Fuforms -Fu../../src/messages -Fu../../src/components -Fu. -FU../../bin/lib/x86_64-linux -FE../../bin -o../../bin/oneform -FcUTF8 Now, if I press the the "All Options" button on the same thing, a dialog with all the options is shown with appropriate check-boxes and drop-downs for all the options. I scroll down to find the -Cg option, and to my utmost confusion, it's check-box is NOT SELECTED. I then select that check-box to add the -Cg option. Now the contents of the "Show Options" button, looks like this: Code: [Select]/home/gcarreno/FreePascal/fpc/bin/x86_64-linux/fpc.sh -MObjFPC -Scghi -Cg -O1 -gw3 -gl -l -vewnhibq -Fi../../bin/lib/x86_64-linux -Fu../../src/application -Fu../../src/forms -Fu../../src/base -Fuforms -Fu../../src/messages -Fu../../src/components -Fu. -FU../../bin/lib/x86_64-linux -FE../../bin -o../../bin/oneform -FcUTF8 -Cg Do you see my confusion?!?!? There are now 2, TWO entries on that dialog that contain -Cg. And if I deselect the -Cg check-box, we revert to the first example!!! So... My question is: Why is -Cg being hardcoded ?? Especially when there's an entry on the "All Options" dialog that is NOT SELECTED!!! This makes no sense at all and it's giving a huge pain in the tuchus on my ncurses projects!!! Can someone please explain why this has been done this way? I'm quite sorry if I'm coming out a bit unhinged, but this has been a thorn in my brain for the past 3 days, and now that I know what's the issue, it's even more frustrating !!! I apologise in advance if my anger is coming through and I'm being a bit disrespectful!!  Cheers, Gus ---------------------------------------------------------------------- Thaddy · 2025-06-23 10:20 -Cg- will override any hardcoded option from the command line. -Cg- with minus sign. Must appear after -Cg of course. Usually PIC code is what you want on platforms that support it, only maybe not while debugging. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2025-06-23 10:28 Hey Thaddy, Quote from: Thaddy on June 23, 2025, 12:20:05 pm-Cg- will override any hardcoded option from the command line. -Cg- with minus sign. Must appear after -Cg of course. Yeap, I got that part from another discussion about ncurses and the same issue I'm having with the borders not working using ACS_* functions. And yes, if I add the -Cg- to my "Custom Options", it all works as intended. But you haven't answered my question: Why is it hardcoded? And WHY is there no way to manage that via the User Interface? Also: Is there any special reason why enforcing the "Generate PIC code" has been thought as mandatory? If I'm doing a framework, that kinda relies on using the default options on Lazarus, but due to this issue I have to specify in some sort of documentation that one has to turn it off with a hack, that is a bit troublesome, no? Just my 2c while being a bit hotheaded about it, sorry!! Cheers, Gus ---------------------------------------------------------------------- Thaddy · 2025-06-23 10:31 I don't like hard coded too. All I can say. It is not hard coded in the sense of pascal code. It seems an IDE issue specific to ncurses. If I use it with Geany, everything works fine. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2025-06-23 10:36 Hey Thaddy, Quote from: Thaddy on June 23, 2025, 12:31:16 pmI don't like hard coded too. All I can say. Thanks for that!! And I do really appreciate you saying that, REALLY !!! On the verge of being frantic, may I ask if you're aware of the decision to make it so? Cuz I have the faintest memory that it was something one could toggle somewhere in the Project Options, and now I can't seem to find it. Nonetheless, and again, many thanks for the kind words. I think you were able to defuse most of my anger !!  Cheers, Gus ---------------------------------------------------------------------- PascalDragon · 2025-06-23 12:30 It is much more likely that user ask for the solution of a problem that leads to "you need to enable PIC" than the other way round (especially when libraries are involved), so it's better to enable that by default and deal with the less common issues. Though I don't know why Lazarus doesn't provide that as a toggleable option (if it indeed doesn't and you didn't just miss it somewhere 😉). ---------------------------------------------------------------------- n7800 · 2025-06-23 16:33 Quote from: Gustavo 'Gus' Carreno on June 23, 2025, 12:15:17 pmThe -Cg or Generate PIC code is hardcoded in the options and cannot be removed!!!  I don't have the "-Cg" option in the "Show Options" window. I checked it in two OS. What version of Lazarus and FPC do you have? Did you install them via the installer or FpcUpDeluxe? If you create a new empty project, is this option there? ---------------------------------------------------------------------- n7800 · 2025-06-23 16:42 Quote from: Gustavo 'Gus' Carreno on June 23, 2025, 12:15:17 pmThis is what I get when I press the "Show Options" button under Project Options->Compiler Options->Custom Options: ... Now, if I press the the "All Options" button on the same thing, a dialog with all the options is shown with appropriate check-boxes and drop-downs for all the options. Note that the "Show Options" button is not on the "Compiler Options->Custom Options" page. It's a separate panel at the bottom of the window. If you switch to any other category, this button will remain, since it does not belong to any specific options page. But the "All Options" button is actually on the "Compiler Options->Custom options" page. And since the "-Cg" option is not in this memo (next to "All Options" button), the checkbox is correctly unchecked. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2025-06-24 06:54 Hey PascalDragon, Quote from: PascalDragon on June 23, 2025, 02:30:26 pmIt is much more likely that user ask for the solution of a problem that leads to "you need to enable PIC" than the other way round (especially when libraries are involved), so it's better to enable that by default and deal with the less common issues. Though I don't know why Lazarus doesn't provide that as a toggleable option (if it indeed doesn't and you didn't just miss it somewhere 😉). While I see your point, and it's a valid one, I still don't understand why it's hard coded. Lazarus already comes with a set of default settings. This could be just another one. And in the project options we could turn it off/on at will. Again, my confusion is with the hard coded not the fact that it's convenient to have it on all the time. Do you understand me now? Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2025-06-24 07:06 Hey n7800, Quote from: n7800 on June 23, 2025, 06:33:36 pmI don't have the "-Cg" option in the "Show Options" window. I checked it in two OS. That's rather odd !! Quote from: n7800 on June 23, 2025, 06:33:36 pmWhat version of Lazarus and FPC do you have? Did you install them via the installer or FpcUpDeluxe? I've checked all my previous fpcupdeluxe installs, way up to 2.0.10 and they all have the -Cg in them. And, yes, I only do fpcupdeluxe installs. So maybe I need to check if it's coming from there. Quote from: n7800 on June 23, 2025, 06:33:36 pmIf you create a new empty project, is this option there? Yes, it is. Cheers, Gus ---------------------------------------------------------------------- tetrastes · 2025-06-24 08:18 Quote from: n7800 on June 23, 2025, 06:33:36 pmQuote from: Gustavo 'Gus' Carreno on June 23, 2025, 12:15:17 pmThe -Cg or Generate PIC code is hardcoded in the options and cannot be removed!!!  I don't have the "-Cg" option in the "Show Options" window. I checked it in two OS. Was x86_64-linux among them? ---------------------------------------------------------------------- n7800 · 2025-06-24 10:47 I checked Windows 7 and 8.1. Now I've launched a virtual Ubuntu, and the option is there indeed. At first I thought that the difference might be in the fpc.cfg files, but I couldn't find anything. In addition, I tried to specifically add the option there, and it still wasn't reflected in the IDE interface. In the end, I searched the IDE code, and indeed found it. I should have done this right away, but I still thought that the issue was in the compiler settings. This lines was first added in b78a550572 ("IDE,lazbuild: append -Cg on targets linux, freebsd, openbsd, netbsd, solaris, bug #17412"). It has a lot of makefile changes, the only lines of code are: Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i @@ -2798,6 +2798,9 @@ function TBaseCompilerOptions.MakeOptionsString(     switches := switches + ' -CX';   if RelocatableUnit and (CurSrcOS='win') then     switches := switches + ' -WR';+  if (CurTargetOS='linux') or (CurTargetOS='freebsd') or (CurTargetOS='netbsd')+  or (CurTargetOS='openbsd') or (CurTargetOS='solaris') then+    switches := switches + ' -Cg'; // see bug 17412    { Checks }   tempsw := '';  There was a small addition later in 0910e1bd5b ("IDE: checking Makefile.compiled: ignore -Cg on Linux"), with the following comment: Code: Diff  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i @@ -562,6 +562,15 @@ function ExtractSearchPathsFromFPCParams(const CompParams: string;       'B':         // build clean         continue;+      'C':+        if (StartPos+2<=length(CompParams)) and (CompParams[StartPos+2]='g')+        and TargetNeedsFPCOptionCG(GetCompiledTargetOS,GetCompiledTargetCPU)+      then begin+          // the -Cg parameter is added automatically on Linux, but not in the+          // Makefile.compiled, because that is platform independent.+          // -> ignore+          continue;+      end;       end;     end;     if Reduced<>'' then  By the way, now (in the modern version) the condition has been moved to a separate function and slightly changed (a CPU check has been added): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TargetNeedsFPCOptionCG(TargetOS, TargetCPU: string): boolean;begin  Result:= (TargetCPU='x86_64')    and ((TargetOS='linux') or (TargetOS='freebsd') or (TargetOS='netbsd')      or (TargetOS='openbsd') or (TargetOS='dragonfly') or (TargetOS='solaris'));end;  Finding the report by issue number was not easy, as it turns out it is not a Lazarus or FPC report, but a CCR from 2010 year: https://gitlab.com/freepascal.org/lazarus/ccr/-/issues/17412 Personally I didn't understand anything about this option (I'm not a Linux user and not very interested), hope this will help others. ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2025-06-25 01:43 Hey n7800, WOW, that was quite the report !!! I couldn't hope for a better explanation of what happened!! Thanks you soooooo very much for the leg work. It's really appreciated !! Cheers, Gus