Difference in fpc and lazarus compiling lazarus / 21-General ---------------------------------------------------------------------- HotShoe · 2024-10-27 17:52 First I am using the current stable version of both, installed via fpcup. I am running on Linux KDE Neon (ubuntu based). and have no fp or laz components installed via .deb or other type files at all. Ok, the question is, I am resurrecting a console based set of programs that I originally wrote in 1986 and maintained via Freshmeat.net until 2011. It is a console file manager and a small fast text editor package that uses ncurses. I do most of the work in Lazarus because it is a much nicer IDE to use than the FP ide. When I compile using laz, the program(s) run fine, but the line drawing characters are wrong. Both fp and laz are set up for UTF-8 which supports the line drawing stuff just fine. If I compile it in the FP ide, it runs as expected with nice borders and all. Is there a way I can make laz compile in the same way that fp does? I have looked at all of the encoding options and tried cp437, etc, but nothing compiled in laz displays borders correctly. This is easy to reproduce by making a simple window using ncurses, ncrt, or ocrt and including a border. Thanks, ---Jem ---------------------------------------------------------------------- marcov · 2024-10-27 17:58 Either Lazarus overrides some codepage settings to the compiler, like source code encoding, or it is the debug console of Lazarus. The latter is easily tested, does it also happen if you run the lazarus generated binary from a terminal ? ---------------------------------------------------------------------- HotShoe · 2024-10-27 18:03 HI, I just tested using Konsole set to xterm+256colors (stock setup), and it does the same. Thanks, ---Jem ---------------------------------------------------------------------- Thaddy · 2024-10-27 18:32 FPC tries to default to the system codepage, which differs per system. On Windows that is CP_OEM. Lazarus, however, tries to use the UTF8 codepage, which is CP_UTF8. Which you don't want in your case, since the drawing characters are in Ansi 128-255 range and even then differ from the old CP_437 (oem_us)  codepage that you need. If you set a console program to CP_437 It will draw correct. Strange thing is you are on linux and most if not all terminals are utf8. Try to start the text mode IDE (fp) and see what it looks. Are you sure you didn't write those old programs for DOS? Then you need codepage CP_437, maybe CP_850 works too. ---------------------------------------------------------------------- HotShoe · 2024-10-27 18:57 DT was originally written for DOS. We didn't adopt Linux until 1996, but the package was thoroughly tested and distributed for Linux via Freshmeat for many years. I opened the fp IDE in Konsole and it looks fine. the graphic is displayed and the borders are fine when a file is loaded. I can provide sceenshots if needed. it also compiles just fine and the resulting binary displays proper borders as well. Thanks, ---Jem ---------------------------------------------------------------------- HotShoe · 2024-10-27 18:59 By the way, the freevision stuff compiles , runs, and displays nice borders on both FP and lazarus. ---------------------------------------------------------------------- Zoran · 2024-10-27 19:00 Quote from: Thaddy on October 27, 2024, 07:32:23 pm Lazarus, however, tries to use the UTF8 codepage, which is CP_UTF8. Actually, it is not Lazarus IDE, but LazUtils package that redefines the default RTL codepage to utf8. So, if your programme has got LazUtils dependency (note that if it has LCL dependency, then it has LazUtils dependency too, as LCL is dependent on LazUtils), than it happens. When creating new project in Lazarus, if you choose "New project -> Application" you get LCL dependency by default (you are expected to create gui application). If you choose "New project -> Program" or "New project -> Console Aplication", you don't get LCL dependency. ---------------------------------------------------------------------- Zoran · 2024-10-27 19:06 When you have a project opened in Lazarus, you can see the added dependencies in Project Inspector, under "Required packages" (see the attached image). ---------------------------------------------------------------------- HotShoe · 2024-10-27 19:14 Attached is a small test program that will not display borders correctly if compiled by laz, but does if compiled by fp. --- Jem ---------------------------------------------------------------------- Zoran · 2024-10-27 19:43 Quote from: HotShoe on October 27, 2024, 08:14:35 pmAttached is a small test program that will not display borders correctly if compiled by laz, but does if compiled by fp. --- Jem In Lazarus you have to have a project to open a program. You sent the pas file, how did you open it in Lazarus? I'm attaching the same program as Lazarus project. Open it in Lazarus and try. ---------------------------------------------------------------------- HotShoe · 2024-10-27 19:50 Laz creates a tst.lpi and a tst.lpr with the .lpr being the actual source. I open it as I would a lazarus app with the .lpi file. in FP ide I open the .lpr file. Thanks, --- Jem ---------------------------------------------------------------------- HotShoe · 2024-10-27 20:05 I unzipped your file into a new dir and loaded the app in both laz and FP ide. they perform the same way that mine did. the laz version has ascii chars around borders and the fp version has line drawn borders. Thanks, --- Jem ---------------------------------------------------------------------- Zoran · 2024-10-27 21:10 Strange... Lazarus uses the same compiler... Sorry, I cannot test, as I don't have your environment (I am on Windows now, and the units in the uses list are not available). There must be something I don't see there... ---------------------------------------------------------------------- Zoran · 2024-10-27 21:15 Perhaps this might help: https://wiki.lazarus.freepascal.org/Lazarus_w ith_FPC3.0_without_UTF-8_mode#Simple_Example ---------------------------------------------------------------------- HotShoe · 2024-10-27 22:12 I thought that would solve this, but alas it did not. I have spent a fair amount of time testing using different encodings just to see what happens, but I cannot get the tst program to display anything but ASCII when compiled with laz. I really appreciate the help, but this is not a high priority problem. I can compile with FP and everything looks fine. I am still curious, but as I said, it is not causing me any real grief. Thanks again, --- Jem ---------------------------------------------------------------------- dbannon · 2024-10-27 23:06 My test of Zoran's project - Needs libncurses-dev to compile. When built in Lazarus (4.0rc1 and FPC323) it displays rubbish from Lazarus's console but when the same Lazarus made binary is run from the real console, works as expected. HotShoe, maybe you did not pick up Zoran's advice about testing from (the real, linux) console ?  When using the Lazarus Console (Lazarus->View->DebugWindows->ConsoleInOutput, you are going through Lazarus's idea of how text should be handled. And these days, that means UTF8 unless you instruct otherwise. In a Lazarus project, its useful sometimes to see just what the fpc command to be used is. Lazarus->Project->ProjectOptions, click button, lower centre, "Show Options".  You can copy and paste that command to use FPC at the command line. So secrets or magic happening ! Davo ---------------------------------------------------------------------- HotShoe · 2024-10-27 23:40 Actually I didn't know you could do Lazarus->View->DebugWindows->ConsoleInOutput. Both compilers (fp IDE and laz) are set to release mode with debug turned off. To test, I either use Ctrl+Alt+F3 to get a true login console, or I use Konsole (in KDE). From there I run through the program and see if I can break it. Then I go find the problem and repeat the process. On my system at least both the login console and the konsole terminal show the correct borders if FP is used to compile the project, but not if laz is used. I am fully aware that this may boil down to something on just my Linux setup, so I will try testing further at the office tomorrow. In the mean time this is not a critical problem for the development of this project, just an interesting problem in general. Thanks, --- Jem ---------------------------------------------------------------------- tetrastes · 2024-10-28 10:08 When I played with libncurses some years ago, I also noticed that apps compiled with Lazarus were not shown correctly. The problem was the following. At x86_64-linux Lazarus adds -Cg option silently, fpc and fp IDE do not. Ncurses did not work properly with this option. I didn't find how to remove it, so I had to add -Cg- in Lazarus manually. Quote from: dbannon on October 28, 2024, 12:06:09 amMy test of Zoran's project - Needs libncurses-dev to compile. When built in Lazarus (4.0rc1 and FPC323) it displays rubbish from Lazarus's console but when the same Lazarus made binary is run from the real console, works as expected. I cannot test with 4.0rc1. May be it doesn't add -Cg option now? ---------------------------------------------------------------------- Zoran · 2024-10-28 11:49 There is one thing -- your file doesn't have directive which explicitly say the compiler mode. Then FPC assumes mode fpc, whereas Lazarus sets new project by default to mode objfpc (this can be adjusted in project options). This might affect this, I don't know, but anyway, add mode directive to the beginning and try: 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 program tst; {$mode fpc} // <--- add the mode directive! uses    ncurses, ocrt, baseunix;  And really, regardless of this, you should always put the mode explicitly in each unit! Make a habit of it! ---------------------------------------------------------------------- HotShoe · 2024-10-28 15:41 I tried that compiler option in my fpc.cfg but it made no difference. Also, I do use mode directives in my programs, but in that test I did not. However, both FP and Laz are set to objfpc. I have attached a screenshot of what dt looks like compiled with laz. I cannot post one that is correct due to total file size restrictions. Thanks, --- Jem ---------------------------------------------------------------------- Fred vS · 2024-10-28 16:00 Hello. I don't know if this helps, but I had similar problems with the crt unit. Using instead keyboard unit helped me. https://forum.lazarus.freepascal.org/index.php/topic,57284.msg426272.h tml#msg426272 ---------------------------------------------------------------------- HotShoe · 2024-10-28 18:37 I may cut all but the ncurses units and see what happens. The interesting part to me at least, is that the drawing characters are being used. In the screenshot I posted above, the corner characters are correct, but the vertical and horizontal line chars are not. So, I'm not convinced that is is an encoding problem. --- Jem ---------------------------------------------------------------------- Thaddy · 2024-10-28 18:41 Quote from: Zoran on October 28, 2024, 12:49:16 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program tst; {$mode fpc} // <--- add the mode directive! uses    ncurses, ocrt, baseunix; <----- fix the order. The uses clause is in the wrong order and in this case important. Baseunix should be first. ---------------------------------------------------------------------- tetrastes · 2024-10-28 19:29 Quote from: HotShoe on October 28, 2024, 04:41:17 pmI tried that compiler option in my fpc.cfg but it made no difference. If that is about -Cg option. I don't know how you tried it in fpc.cfg, I simply compile your tst.pas by fpc and fpc -Cg. Results are in the attached picture. Adding -S2h to options (to be compatible with Lazarus default settings) changed nothing. FPC 3.2.2 x86_64-linux. ---------------------------------------------------------------------- HotShoe · 2024-10-29 01:25 Ok, so I tried a simple experiment just for my own sanity. I installed lazarus and fpc from the package repository for my linux distro. Just to see if there is some innate difference between the way FpcUpDeluxe installs lazarus and FPC, and the way the pre-rolled packages do things. The good news is that the problem no longer exists. I can now compile with either FP IDE or Laz and get the same results. That is nicely drawn borders without having to do anything in either package. I am still curious why this is though. What is fpcup doing or not doing, that the official package does. Maybe when I have more time and the inclination I'll try to find out. For now it seems to be one of those mysteries. Thank you all for your helpful suggestions, I really do appreciate your time. This is not a bug or some programming error or improper switch setting on my part. It is just a difference is the 2 installation procedures it seems. Thanks all, --- Jem ---------------------------------------------------------------------- dbannon · 2024-10-29 01:34 Quote from: HotShoe on October 29, 2024, 02:25:12 amI am still curious why this is though. What is fpcup doing or not doing, that the official package does. Maybe when I have more time and the inclination I'll try to find out. For now it seems to be one of those mysteries. Yep, strange !  Remember, it worked fine in my test too, no fpcupdeluxe, just FPC and Lazarus both built from source. Davo ---------------------------------------------------------------------- Thaddy · 2024-10-29 08:55 I can confirm that is you build lazarus from source the visual output is correct with both fpc and lazarus. I used ubuntu 22 tls 64 bit and both fpc and lazarus trunk from 26-10. ---------------------------------------------------------------------- tetrastes · 2024-10-29 09:40 Out of curiosity, did anybody try to compile with fpc -Cg? ---------------------------------------------------------------------- dbannon · 2024-10-29 10:12 Generate PIC code ? Yeah ? It make no difference to the already working fpc build.  Which way do you expect it to make a difference ? Davo ---------------------------------------------------------------------- tetrastes · 2024-10-29 12:13 See my replies #17 and #23 (note picture). I don't know why there is difference, it was unexpected to me. May be there is problem with fpc 3.2.2 for x86_64-linux (didn't try i386), may be only with fpc-laz_3.2.2-210709_amd64.deb package, which I use. And why OP had difference with fpc and Lazarus compilation? ---------------------------------------------------------------------- tetrastes · 2024-10-29 12:54 Quote from: dbannon on October 29, 2024, 11:12:31 amGenerate PIC code ? Yeah ? It make no difference to the already working fpc build.  Which way do you expect it to make a difference ? Davo Oh, it seems you think I talk about compiling fpc itself? No, I mean compiling OP's tst.pas with -Cg option. ---------------------------------------------------------------------- dbannon · 2024-10-29 23:16 Quote from: tetrastes on October 29, 2024, 01:54:21 pm(Generate PIC code) Oh, it seems you think I talk about compiling fpc itself? No, I mean compiling OP's tst.pas with -Cg option. Nope, its me not being clear. I can and did easily test OP's small example using just FPC both with and without -Cg.  But both work identically. Now, I see you mention that adding -Cg (as Lazarus does) breaks things, so, if thats the case, me adding -Cg to my fpc command line test would make a broken binary ?  Sorry, no. No point me adding -Cg- to my in-Lzarus test because my plain Lazarus test produces a working binary too. We need someone who is using an officially packaged Lazarus (ie a deb or, maybe rpm) to do that test. Davo ---------------------------------------------------------------------- tetrastes · 2024-10-30 09:32 Thank you for testing! There is something weird indeed. ---------------------------------------------------------------------- HotShoe · 2024-10-30 16:43 OK, so I can't leave stuff like this alone, so I did the following. I uninstalled the fpcupdeluxe and the .deb packaged installations completely. Including config file directories , all /usr/lib/fpc and /usr/share/lazarus, /etc config files, and config files in my home .config  and .Lazarus directories. Then I reinstalled laz with the 3 packages on the lazarus-ide.org page by clicking the Download Now link. The installed went fine and then I had a a lazarus that brought up a new project and factory colors when run. None of my defined directories or options were in place, so it was as close to a virgin install as I can make it. I set up my directories in fp.cfg and in fpc.cfg so that my components and stuff can be found, and set up my colors for the editor, fonts. etc. Now I had a working lazarus that can compile all the stuff I do. I am the odd one in that I am the only one in the company that works with pascal (plus c++ and java for the few android apps we still maintain). Now when I run fpc tst.lpr I get perfect borders. It's the same when I load it into fp ide. When I compile with lazarus, I get the same bad borders as I originally did. Cool, now I can play. First I tried adding the -Cg to the compiler commands in Laz. That did nothing, so I removed that and tried the -dDisableUTF8RTL in the options. That also did nothing. Yes I am being careful that I am using the same mode (default, debug, release) always using release mode. Then I uninstalled and wiped the config files again and re-installed with the lazarus package from the Neon (ubuntu) repository. This is the one that worked fine, but after this install, it was back to not working (as in not giving me borders). Right now, I am back to the official 3 package install from the lazarus site (because it's 3.6). I know that laz can create the same binary as fpc/FP IDE because it did so on this machine for a full day and night until I got cocky and decided to find out why. I will eventually stumble across the right switch or setting, it might just take a while though. --- Jem ---------------------------------------------------------------------- TRon · 2024-10-30 16:53 @HotShoe: option -va. It is a compiler option so that works for both FPC and Lazarus. It generates output of all that the compiler does (the log is long). It is also possible to get more detailed information on the linking stage by passing the -k-- (search for gnu binutils ld for the manual). That should cover all information required to determine the difference of building between FPC and Lazarus (Lazarus uses the same FPC executable, unless you have multiple installations and configured things differently). I explicitly mention the latter because I do not know what these packages you use(d) actually contains (e.g. could be Lazarus with its own configured FPC) There is no need to re-install over and over. There simply seem to be a difference somewhere. Except for the -Cg option none of the compiler options made any difference for me. It is definitely a encoding related issue but it also beats me where it originates from. Because I checked the compiler output myself (and did not notice any other differences) I would suspect a difference at linking stage. ---------------------------------------------------------------------- HotShoe · 2024-10-30 17:56 Thanks TRon, I'll try those. One thing interesting that I have noticed is that when I compile in laz after setting everything back to stock settings, and do a build. Then when I use fpc in a terminal it rebuilds the source and dependencies, so it sees something has changed and makes some changes that it likes and then rebuilds again. I think that is where the problem (difference) lies. --- Jem ---------------------------------------------------------------------- tetrastes · 2024-10-30 21:05 Quote from: HotShoe on October 30, 2024, 05:43:09 pmFirst I tried adding the -Cg to the compiler commands in Laz. This option is already added by Lazarus, you have to add -Cg-. Or compile from terminal with fpc -Cg and see, if there are bad borders. ---------------------------------------------------------------------- HotShoe · 2024-10-30 22:55 I just spent over an hour going through the -va outputs on both laz and fpc. then I went through all of the compiler switches being sent. Low and behold, when I added the -Cg- switch to turn off pic, the borders worked fine. I tried this switch back in the beginning when someone, (tetrastes maybe?) suggested it, but that was on the fpcup installed version. Anyway, tetrastes is absolutely right that on this install at least, adding the -Cg- switch fixes the bad borders. Thanks, --- Jem ---------------------------------------------------------------------- HotShoe · 2024-10-31 01:46 Ok, time to add to the head scratching. The little tst program that I attached in an earlier post works. It doesn't matter what I change in that program, it just works. DT, my filemanager project however does not just work. I had put in a line to print some drawing characters while testing different options to get borders to work. Going through the code now that the borders are working I found this line: stats.WriteAC(2,20,colors(white,red),ACS_RTEE); That is the first line after the status window is initialized and then the stats.show is called. So what you say? it's just a left over line from testing right? Right, but if I comment that line out, the dt program no longer draws pretty borders. Yep they go back to the bad borders. Un-comment the line again and everything looks just fine. So a writeac somehow forces the character set to initialize to show drawing characters? I don't have an answer. I don't know enough about how the Laz IDE works, but it is certainly interesting. --- Jem ---------------------------------------------------------------------- TRon · 2024-10-31 22:54 @HotShoe: The xxxxAC routines have some special checking against certain characters and bails out if the default used characters are not used. The bail out fallback part relies on your system termcap settings. I checked this code/implementation before joining the discussion and initially thought that was the culprit of your issue but I removed that post because in my specific situation (and according to the test- program and description) I was able to solve it with the -Cg parameter (just as user tetrastes). unit ocrt of ncurses contains the following comment at nWriteAC: Quote  Write a character from the alternate character set. A normal   value from the alternate character set is larger than $400000.   If the value passed here is 128..255, then we assume it to be   the ordinal value from the IBM extended character set, and try   to map it to curses correctly. If it does not map, then we just   make it an alternate character and hope the output is what the   programmer expected. Note: this will work on the Linux console   just fine, but for other terminals the passed value must match   the termcap definition for the alternate character.   Note: The cursor returns to it's original position. Now, that still does not answer how to solve but at least provides a lead. ---------------------------------------------------------------------- HotShoe · 2024-11-01 19:20 So it really is initializing the acs system, at least on linux. That's pretty cool, and good to know. --- Jem