hello world for linux in C++ - Page 1
Forum section: electronics / general

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 10:37:59 am
content: I have decided that it is time to start getting into writing programs for linux in C++.I am aware that the system libraries are all different between windows and linux.Where do I start? I have installed debian on a laptop and attempted to use a hello world program I found on the internet in visual studio code, well the system header file did not exist apparently.I have visual studio on my windows PC but this is not linux. I had a working program but it can't compile for linux and it was a very poorly written one at that but it showed that my visual studio was working.Next I tried a c++ program for linux project in VS and I managed to connect to my debian laptop. I got a bash error saying that there were too many arguments for cdThen I tried a cmake project but really at this point I have no idea and as this is cross platform I don't know if it is for windows or linux.All I want is a working setup that will produce a hello world program that will run on linux.What do I do?

author: brucehoult
author_rank: Super Contributor
timestamp: September 11, 2024, 10:49:42 am
content: It doesn't matter what OS you are on, the C or C++ standard library will work just the same for programs that read and write files, including stdin and stdout.Code:bruce@i9:~/programs$ cat hello.cpp#include <iostream>int main() {std::cout << "Hello World!" << std::endl;return 0;}bruce@i9:~/programs$ g++ hello.cpp -o hellobruce@i9:~/programs$ ./helloHello World!bruce@i9:~/programs$That happens to be on Ubuntu on Windows 11, but it will work exactly the same on native Linux (obviously), or MacOS or Linux on Arm or RISC-V etc etc.Code:bruce@i9:~/programs$ scp hello.cpp lp:hello.cpp 100% 96 8.6KB/s 00:00bruce@i9:~/programs$ ssh lp____ _ ____ ____ _ __ ____ _ _| _ \ _ _ _ _(_) ___|| _ \| |/ / / ___|(_)_ __ ___ ___ __| || |_) | | | | | | | \___ \| | | | ' / \___ \| | '_ \ / _ \/ _ \/ _` || _ <| |_| | |_| | |___) | |_| | . \ ___) | | |_) | __/ __/ (_| ||_| \_\\__,_|\__, |_|____/|____/|_|\_\ |____/|_| .__/ \___|\___|\__,_||___/ |_|-- Presented by ISCAS and SipeedDebian GNU/Linux 12 (bookworm) (kernel 5.10.113-lpi4a)Linux lpi4a 5.10.113-lpi4a #2024.01.01.02.29+2bd2eac4a SMP PREEMPT Mon Jan 1 02:30:07 UTC 2 riscv64The programs included with the Debian GNU/Linux system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extentpermitted by applicable law.Last login: Fri Aug 23 16:47:25 2024 from 192.168.1.169debian@lpi4a:~$ g++ hello.cpp -o hellodebian@lpi4a:~$ ./helloHello World!debian@lpi4a:~$ file hellohello: ELF 64-bit LSB pie executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, BuildID=a16873f88fc47464ae68d2b28df89f7b10b39437, for GNU/Linux 4.15.0, not strippeddebian@lpi4a:~$

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 11:15:21 am
content: well i got burnt the first time but the program had a file called windows.h included. So if there is no windows.h included can i assume that I won't be able to use windows only stuff?I have now correctly compiled a linux console program making sure I don't have spaces in any file or folder name and there is a .out file, surely that is not the finished program? I thought linux programs had no extension.

author: brucehoult
author_rank: Super Contributor
timestamp: September 11, 2024, 11:28:24 am
content: You can have spaces in file and directory names, no problem, if you want to.Code:debian@lpi4a:~$ ls -l *.cpp-rw-r--r-- 1 debian debian 96 Sep 11 10:52 'hello world.cpp'debian@lpi4a:~$ g++ 'hello world.cpp' -o 'hello world'debian@lpi4a:~$ ./'hello world'Hello World!If you don't tell the compiler what output name you want then it usesa.outfor historical compatibility reasons dating back to the early 1970s.Unix file names don't have extensions, but they can have dots in their names if they want to, and this can be used to indicate the file contents.

author: ataradov
author_rank: Super Contributor
timestamp: September 11, 2024, 02:40:16 pm
content: Quote from: Simon on September 11, 2024, 11:15:21 amThis mans that your program likely calls WinAPI functions, and it is not going to link on Linux.Quote from: Simon on September 11, 2024, 11:15:21 amThere are no meaningful extensions. "a.out" is just a file name that includes period. This is the default output file name for a very long historic reasons. The "OUT" was an actual binary format before ELF existed. Then everyone moved to ELF, but the name stuck. The actual contents is ELF, of course, and it can just run.

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 03:50:33 pm
content: right so sounds like I have a basic working setup.

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 05:09:49 pm
content: So if I create a generic console app instead of a Linux one I can write a program that will also compile under Linux providing I don't include windows.h

author: ataradov
author_rank: Super Contributor
timestamp: September 11, 2024, 05:15:05 pm
content: Yes, if you only use only functions from the standard C library, it will compile and work everywhere.In general, for cross platform development it is easier to focus on the Linux side and use MinGW to compile on Windows. You get a rich ecosystem of cross platform libraries.But if you need Windows specific stuff, then it must be separated into the platform files, which are unique for each platform.

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 05:20:50 pm
content: Functions from the standard C library? but I want to do this in C++, I realize that pretty much all of the C stuff either works in C++ or was rewritten for C++ but if windows.h gives access to windows only stuff and I avoid that, what is the next gotcha I have to look out for?Basically I'd like to develop with visual studio on windows and be able to run the results on Linux. My next step for example is to start looking at the FLTK libraries so my assumption is that as I can compile the libraries for either platform what runs in one will run in the other.

author: ataradov
author_rank: Super Contributor
timestamp: September 11, 2024, 05:30:29 pm
content: Quote from: Simon on September 11, 2024, 05:20:50 pmWell, C++ has sttd:: namespace. Same principle.Quote from: Simon on September 11, 2024, 05:20:50 pmIt is hard to tell the extent of things you want to do. If you are fine doing basic console applications, then there is not much that can go wrong. But if you want to interact with outside word, like using USB or networking, you will have to interact with the OS to some extent.Quote from: Simon on September 11, 2024, 05:20:50 pmAssuming VS only supports MSVC as a compiler, you may also need to deal with minor differences between MSVC and GCC. There is nothing major, but there are differences.Quote from: Simon on September 11, 2024, 05:20:50 pmNo idea, I have not looked at FLTK. It should be possible to figure out, but I would not expect it to be trivial.The most straightforward way to do cross platform graphical applications is Qt, but their licensing and pricing sucks.

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 06:42:44 pm
content: OK so it sounds like I will be best off using a linux specific console application and connect to my debian machine.

author: radiolistener
author_rank: Super Contributor
timestamp: September 11, 2024, 07:35:12 pm
content: You can start with this command in Linux:Code:printf '#include <stdio.h>\nint main() { printf("Hello World!\\n"); return 0; }\n' > hello.c && gcc hello.c -o hello && ./helloRegarding to C vs C++, I recommend you to start from C and when you will be able to use structs to represent different entities, you will be ready to switch to C++.If you want to develop UI app on VS under Windows and then run it on Linux. I think the most easy way is to develop it in C# using WinForms, use .NET FW 4.You can run it on linux using mono. Also on Linux you can open your project and compile in MonoDevelop, but you will not be able to use WinForms designer to edit window layout on Linux. For Linux there is GTK# form designer.Here is hello world example in C# using WinForms:Code:using System;using System.Windows.Forms;class Program {static void Main() {Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);using (var form = new Form()){form.Text = "Hello World Form";var button = new Button();button.Text = "Click me";button.AutoSize = true;button.Location = new System.Drawing.Point((form.ClientSize.Width - button.Width) / 2,(form.ClientSize.Height - button.Height) / 2);button.Click += (sender, e) => MessageBox.Show("Hello World");form.Controls.Add(button);Application.Run(form);}}}This example opens window with a button "Click me". When you click it, it will show you message "Hello world".You can compile it with this command on linux:Code:mcs -r:System.Windows.Forms -r:System.Drawing helloworld.csthen you can run it using this command on linux:Code:mono helloworld.exeOn Windows you can compile it withCode:csc /r:System.Windows.Forms.dll /r:System.Drawing.dll helloworld.csIf you want better cross-platform support you can use other libraries.

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 08:10:07 pm
content: Um structs, you mean those things that are all over the micro controller code that I program, yes quite, I use structs quite a lot. My main reason for looking to move on to C++ is that it will have broader library support and fltk runs with C++ not C. I have not done anything with it but I gather that it is as close as one gets to a C++ native graphical library.

author: radiolistener
author_rank: Super Contributor
timestamp: September 11, 2024, 08:20:25 pm
content: if you select language for MCU, it's better to stay with C style even if you use C++ compiler.This is because using C++ libraries leads to more large and slower bloated code which require more memory. This is not good for MCU.Regarding UI for MCUs, it depends very much on which MCU you use. Not many MCUs are capable of running full-featured UI libraries.

author: Simon
author_rank: Unknown
timestamp: September 11, 2024, 08:27:51 pm
content: uh, I regularly program MCU's in C. I now want to start looking at programming in C++ for linux on single board computers, totally different ball game.

author: radiolistener
author_rank: Super Contributor
timestamp: September 11, 2024, 08:34:30 pm
content: If your SBC supports OpenGL or OpenGL ES, I can recommend to useDear ImGui.It runs very well on Raspberry Pi Zero 2W in KMS DRM mode using SDL2 backend.If you know C, I think it will be easy to use it even if you don't familiar with C++, despite the fact that it is written in C++.It is very simple, lightweight, very fast and allows to implement cool professional UI with minimal effort.There are numerous ready-to-use widgets available for ImGui that cover nearly any use case.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 01:34:50 am
content: You are confusing C++ and MFC. In fact, it turns out that for portability between different Linuxes you will have to drag and drop the entire graphics subsystem. In the same way, you can use a Windows emulator and MFC, and the development speed is higher, and the weight of the software is comparable.

author: brucehoult
author_rank: Super Contributor
timestamp: September 12, 2024, 02:23:29 am
content: Quote from: ataradov on September 11, 2024, 05:30:29 pmArguably, an HTML-based UI is easier, certainly if your UI needs are not demanding. Either with an HTTP server library added to your app, or with an HTTP server app running your app as a CGI.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 12, 2024, 02:50:04 am
content: Quote from: Simon on September 11, 2024, 08:10:07 pmUsing FLTK is not unreasonable if you want to develop simple, cross-platform GUI stuff that doesn't requires gigabytes of install and a 6-month learning curve.It's certainly simpler and much more lightweight than Qt.And this may help get you started with the tooling:https://www.fltk.org/articles.php?L1820

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 03:16:07 am
content: Quote from: brucehoult on September 12, 2024, 02:23:29 amAs an option, you can carry with your program several assemblies of the customized browser for different Linuxes.

author: radiolistener
author_rank: Super Contributor
timestamp: September 12, 2024, 05:58:03 am
content: Quote from: brucehoult on September 12, 2024, 02:23:29 amYeah, when I see these gigabytes of libraries and all the issues with versioning just to implement a simple window with buttons, it looks like a nightmare to support software written with Qt. Debugging is another issue. I know of one software that raises a segmentation fault exception somewhere inside Qt, and when you see the stack trace and all the code that needs to be analyzed, it's a nightmare to figure out what's going wrong.Currently, I'm looking for a lightweight desktop UI for my tools (different kinds of calculators, debuggers, DSP processing, etc.). I first considered Qt, but after testing it, I decided to avoid this nightmareAlso tried Rust with some UI libraries, but when the folder with a simple example swelled to several gigabytes of libraries (which also require to update rust compiler) and after some fiddling with the compatibility of package versions, just to write a simple window, I decided that this is not what I need...Currently, I’ve written part of my tools in HTML and JavaScript, and they can be run from a browser or using Python with the python3-webview library. For example:Code:import webviewwindow = webview.create_window('Calculator', url='~/mycalc.html')webview.start()for other tools I'm using C# with OpenGL or WinForms backend and C++ with ImGui.And still looking for a good cross-platform solution to replace old WinForms with something more modern, lightweight and beautiful.

author: JPortici
author_rank: Super Contributor
timestamp: September 12, 2024, 07:26:38 am
content: Quote from: radiolistener on September 12, 2024, 05:58:03 amyeahand the answer is NOT tkinter.I routinely have the same problem myself.. i DO NOT want to make another VB6 application for that simple task, because VB6's basic is archaic, i do not want to use visual studio, VBNET or C# (and visual c++ these days is confusing to me), in the end i go back to Qt. Qt is really comfy once you get past the first couple of applications, the problem is having to drag 50-60 MB of libraries every time. Sucks but i have not found a better solution(well, with a couple of more libraries one can use LVGL so the application could eventually be ported to a bare metal embedded solution... but then you have to do GUIs in C)

author: radiolistener
author_rank: Super Contributor
timestamp: September 12, 2024, 10:04:55 am
content: Quote from: JPortici on September 12, 2024, 07:26:38 amI think C# looks the best on Linux and MacOS from this point of view. The executable is very small and can run with no recompilation on any platform with better speed than Qt based app and eats much less memory. I even tried to run the multiplayer network game server written in C# on Raspberry Pi Zero 2W and surprisingly it works pretty smooth with no lags...I also have OpenGL multiplayer game client written in C# which uses my own cross-platform OpenGL engine, it is small and works on Raspberry Pi 4 better than other C++ and Web versions from another developers on Windows with i5 CPU...I like that C# code is so tiny, fast and easy to read and debug. The only issue with C# is a lack of supported dev tools on Linux. MonoDevelop works good, but its unfortunately abandoned and don't have WinForms editor. And I don't want to use vscode due to telemetry.So, I think the recipe probably is to use C# with MonoDevelop, but replace WinForms with some more modern cross platform UI library. And I am in the process of searching.Quote from: JPortici on September 12, 2024, 07:26:38 amI don't see the reason to use bare metal apps. Using C++ app and ImGui with SDL2 backend you can run nice UI app with no X11, just lightweight linux kernel with drivers for DRM/KMS acceleration.This is how ImGui interface looks:

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 03:36:18 pm
content: Quote from: radiolistener on September 12, 2024, 10:04:55 amMFC does this in 3 minutes:

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 12, 2024, 06:30:40 pm
content: Quote from: radiolistener on September 11, 2024, 07:35:12 pmBad advise. C and C++ are two very different languages, even though they have a very similar syntax. The thoughts behind oject oriented programming is also quite different.A "Hello Wold" in C++ is easy for the command line. Just a few lines of code that spit out characters. It's when you want to get into GUI applications that things start getting complicated.A long time ago (25 years or so) I used the Borland C++ builder and clicked together some GUI applications, and that worked quite well, I really liked how Borland C++ Builder worked. But I did not have many applications to write, and it got dusted over. A bit over 10 years ago I switched to Linux, and I have not (knowingly) used a microsoft product after that. I did dabble a bit with QT Creator for a bit, but they are constantly attempting to annoy their open source part and I started to dislike them for that, so I ditched QT and the QT Creator. (Even though I quite liked the IDE. I have used it for a while for programming AVR microcontrollers.Every now and then I have a short look at wxWidgets. It's also a cross platform windowing framework with bindings to a lot of languages. You can write a wxWidgets GUI program in 15 lines of Python (but I don't like python). Recently I accidentally bumped into the Codelite IDE. It seems to have a very nice mix of simplicity but yet being powerful enough to be taken seriously. I installed it, created a wxWidgets program (In C++), compiled it and it just all worked. I have also used CodeBlocks for a while to write microcontroller programs. It also has "built in" support for writing wxWidget GUI applications, but I had a lot of trouble to get that to work. One of the reasons I am (a bit) interested in wxWidgets is that it's also used by KiCad. KiCad is struggling a bit with it. QT is more powerful, but wxWidgets is more then capable for anything I would want to do with it. Debugging (breakpoints, single stepping and such) also "just worked" in the Codelite IDE.And now I (accidentally) installed an IDE win which wxWidgets "just works", it's getting time to read more about wxWidgets, and how those "sizers" work. It's not as easy and intuitive as the Borland C++ Builder was 25 years ago and I find myself in need of some kind of book or tutorial to get started in a decent way with wxWidgets. But getting my STM32 programs away from that eclipse monstrosity has a higher priority for me, but that's a different chapter of a different book.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 06:44:11 pm
content: I think it is necessary to mention:

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 12, 2024, 06:50:37 pm
content: I thought Windoze CE was obsolete 15+ years ago, (but I haven't kept up with stuff from microsoft)For embedded stuff, I'd also much rather donate money to some Linux distribution then pay for each windoze license.

author: ataradov
author_rank: Super Contributor
timestamp: September 12, 2024, 06:53:02 pm
content: It is obsolete. The screenshot (what it even supposed to show?) is from 23 year old document. It must be nice to live in the past, but some of us need to be in the present.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 06:58:35 pm
content: I don't understand, my screenshot is about outdated software, but this software works like a clock. You are discussing "new products" that are childish attempts to copy this and nothing works properly. What's the point?

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 12, 2024, 07:19:57 pm
content: Quote from: Postal2 on September 12, 2024, 06:58:35 pmMaybe you'll find out after you attempt to feed hay to your electric car.Windoze CE did not even work in windoze itself, have never attempted to use it under Linux. I don't even want to think about what sort of mess that would be.QT apparently has libraries that work both in regular QT (windows, Linux, maybe the fruit brand too) and for embedded systems. But as far as I know that stuff is not free. They may even be dabbling into android, but as I wrote before, I quit from QT some time ago.

author: Karel
author_rank: Super Contributor
timestamp: September 12, 2024, 07:39:29 pm
content: Quote from: ataradov on September 11, 2024, 05:30:29 pmHuh? Qt is open source and available under the lgpl license. Even if you want to write closed source software,you can use Qt for free on the condition that you don't link static with the Qt libraries.So, what about Qt licensing sucks exactly?

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 07:42:38 pm
content: Quote from: Doctorandus_P on September 12, 2024, 07:19:57 pmEverything works, I can post you the documentation, but you won't have time to read it because in the next 5 years you'll be burying your head in QT or some other crap.And based on your knowledge you will do the same shit that you don't like from others now.

author: JPortici
author_rank: Super Contributor
timestamp: September 12, 2024, 08:06:55 pm
content: Quote from: Postal2 on September 12, 2024, 07:42:38 pmIs there new hardware that deploys Windows CE? Or windows 7 while we're at it... I must have missed something!

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 09:04:22 pm
content: Quote from: JPortici on September 12, 2024, 08:06:55 pmYou missed to look at my screenshot above, on the left.Windows CE API is identical to Windows 98, with some simplification. Almost any project for Windows 98 can be compiled for Windows CE. As for "deploy on new hardware" - you need to compare binary compatibility, since Windows CE exists for the old version of ARM. But if there is no binary compatibility - then, as I already said, you can use a Windows emulator, which will provide the necessary API.

author: JPortici
author_rank: Super Contributor
timestamp: September 12, 2024, 09:35:19 pm
content: But does new hardware come out with Windows CE? can i put out new hardware with Windows CE?

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 09:48:06 pm
content: Quote from: JPortici on September 12, 2024, 09:35:19 pmI had a portable translator running Windows CE, and you have no idea what's inside Windows CE - it's not mentioned anywhere. You can release new hardware for anything. Using hardware encryption, you can steal any software and install it on your device.

author: ataradov
author_rank: Super Contributor
timestamp: September 12, 2024, 10:01:23 pm
content: This thread turned into some sort of absurd theater.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 10:05:37 pm
content: Quote from: ataradov on September 12, 2024, 10:01:23 pmThis branch is just not for you yet. You will learn over time.However, I appreciate your experience with Microchip controllers.

author: radiolistener
author_rank: Super Contributor
timestamp: September 12, 2024, 10:37:09 pm
content: Quote from: Postal2 on September 12, 2024, 09:04:22 pmI just wonder, can you run OpenGL ES app in Windows CE on Raspberry Pi Zero 2w?Quote from: Doctorandus_P on September 12, 2024, 06:30:40 pmWhy is it bad? Yes, they are different, but C++ is based on C and is more complex for beginners. That's why it's better to start with C, learn procedural programming, and then move on to OOP in C. Having experience with OOP in C provides a good background for learning C++.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 10:42:38 pm
content: Quote from: radiolistener on September 12, 2024, 10:37:09 pmIf it were a more powerful device, I would use Wine, create a driver that would forward calls, and everything would work.

author: radiolistener
author_rank: Super Contributor
timestamp: September 12, 2024, 10:50:27 pm
content: Quote from: Postal2 on September 12, 2024, 10:42:38 pmSo it will run on Linux through an additional layer. But what's the point if you can run it directly on Linux and make direct calls?RPI02W has only 512 MB of RAM, so it's highly undesirable to load any additional code.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 11:06:07 pm
content: Quote from: radiolistener on September 12, 2024, 10:50:27 pmIf you are doing something small on a small controller, you will be forced to engage in perversions, this is a classic approach. As for multiplatform applications, I considered the opposite situation - emulation of the Linux graphical environment by Windows. That is, you create a project on Raspberry, and use it on Windows. Or is it better the other way around?

author: radiolistener
author_rank: Super Contributor
timestamp: September 12, 2024, 11:19:12 pm
content: If you create an X11 app, you can run it on the RPI02W, but it requires starting X11, which will consume all available RAM.If you implement your app with Windows CE and run it on the RPI02W using Wine, it will consume even more RAM.However, if you implement it with ImGui and the SDL2 backend, it won't require X11 to run, leaving all the RAM available for your app. Additionally, you can compile and run your ImGui app for Windows CE without needing to change the code, no need for additional drivers and call translators. Isn't that a reason to use ImGui?

author: Postal2
author_rank: Frequent Contributor
timestamp: September 12, 2024, 11:43:17 pm
content: I understand. But I don't understand ImGui. I know how to use MFC, ataradov knows how to use the Turbo Pascal 7.0 shell. And everyone will pull in their own direction and argue. That's normal.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 13, 2024, 12:01:22 am
content: Quote from: ataradov on September 12, 2024, 10:01:23 pmI'm guessing that mad russian is worse then Faringdon.

author: radiolistener
author_rank: Super Contributor
timestamp: September 13, 2024, 12:22:39 am
content: Quote from: Postal2 on September 12, 2024, 11:43:17 pmit's pretty easy, for example here is the code:Code:ImGui::Text("Hello, world %d", 123);if (ImGui::Button("Save"))MySaveFunction();ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));ImGui::SliderFloat("float", &f, 0.0f, 1.0f);You should run this code for every frame and get this result:It already handle mouse and keyboard, so when you press the button it leads to trigger the conditionCode:if (ImGui::Button("Save"))And the main loop of app looks like this:Code:// Main loopbool done = false;while (!done){SDL_Event event;while (SDL_PollEvent(&event)){ImGui_ImplSDL2_ProcessEvent(&event);if (event.type == SDL_QUIT)done = true;if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))done = true;}// Start the Dear ImGui frameImGui_ImplOpenGL2_NewFrame();ImGui_ImplSDL2_NewFrame();ImGui::NewFrame();// here you call your UI code// ....// RenderingImGui::Render();glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);glClear(GL_COLOR_BUFFER_BIT);ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());SDL_GL_SwapWindow(window);}Here is another example of code:Code:// Create a window called "My First Tool", with a menu bar.ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar);if (ImGui::BeginMenuBar()){if (ImGui::BeginMenu("File")){if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }if (ImGui::MenuItem("Save", "Ctrl+S")) { /* Do stuff */ }if (ImGui::MenuItem("Close", "Ctrl+W")) { my_tool_active = false; }ImGui::EndMenu();}ImGui::EndMenuBar();}// Edit a color stored as 4 floatsImGui::ColorEdit4("Color", my_color);// Generate samples and plot themfloat samples;for (int n = 0; n < 100; n++)samples = sinf(n * 0.2f + ImGui::GetTime() * 1.5f);ImGui::PlotLines("Samples", samples, 100);// Display contents in a scrolling regionImGui::TextColored(ImVec4(1,1,0,1), "Important Stuff");ImGui::BeginChild("Scrolling");for (int n = 0; n < 50; n++)ImGui::Text("%04d: Some text", n);ImGui::EndChild();ImGui::End();and result:

author: Postal2
author_rank: Frequent Contributor
timestamp: September 13, 2024, 12:40:28 am
content: Quote from: radiolistener on September 13, 2024, 12:22:39 amWell, yeah, not bad. It's a pure C.I need to unpack the disk structure now, can ImGui make a treeview?

author: radiolistener
author_rank: Super Contributor
timestamp: September 13, 2024, 03:11:19 am
content: Quote from: Postal2 on September 13, 2024, 12:40:28 amit has imgui_demo.cpp with examples for different widgets.Just include this file into project and call ImGui::ShowDemoWindow(NULL); to show demo window:Here is example of a typical ImGui UI app:

author: Postal2
author_rank: Frequent Contributor
timestamp: September 13, 2024, 04:38:12 am
content: Yes, this interface solves the "Hello world" issue for Linux. As for graphics, it can be used instead of MFC. Of course, MFC contains different classes, not only graphics. But I downloaded and looked - this ImGui is really a good thing. Many thanks for the information. I'll try to use it under Windows, it's interesting.

author: djsb
author_rank: Super Contributor
timestamp: September 13, 2024, 05:31:30 am
content: Sorry if this confuses the original poster even more.I'm a dinosaur and I use BCX BASIC to C convertor (very useful for trying out ideas and algorithms and a wonderful forum) and Free BASIC (same helpful forum for beginners) for playing around with console and Windows GUI prototype code on Windows.I've not tried coding on Linux. Anything I do on microcontrollers I either use Great Cow basic, Arduino C/C++ or CCS C or XC8 on PIC micro's. I've dabbled with WxWidgets but have only followed one YouTube tutorial.I just can't get along with C++ at all, even though I keep trying.For me, it ALL comes down to how I take to any of the tutorials that I try. Anyway, I keep on trying and I suppose that's something.

author: Simon
author_rank: Unknown
timestamp: September 13, 2024, 02:09:30 pm
content: Yea I am confused.I found FLTK mentioned in the C++ book by stroustrp which I take as a decent endorsement. My ultimate goal is to have a single board computer running a CAN bus to control the machine or at least relay instructions with a graphical interface, touch and buttons that will be on CAN bus anyway. I also need to log the data on the CAN bus and convert the data into a PDF file.I realize this is a lot but I have patience. I know people will now suggest off the shelf HMI's, well i looked at those and for the same price as an in house made HMI and general computer to do whatever all you get is a HMI that I still need to learn a 700 page manual to understand and it will never do what we want.

author: ataradov
author_rank: Super Contributor
timestamp: September 13, 2024, 02:16:53 pm
content: FLTK is fine, it is far better than emulating WinCE, which is really just nuts.The best thing you can do is try all those graphical frameworks and see which one works best for your case. It should not take too much time. If it takes a lot of time to get even examples running, you may want to reconsider the library.And from all the suggested stuff ImGUI is also good for quick and dirty interfaces. And if your application is more graphical in nature and you just want to put some graphics on the screen, I would also suggest raylib. It is a very easy to use library primarily oriented for games, but can be used for all sorts of applications.If you want a polished desktop application that looks native on the OS, then both ImGUI and raylib approach would take a lot of effort. For this wxWidgets may be better, since it tries to use native controls for the OS.

author: brucehoult
author_rank: Super Contributor
timestamp: September 13, 2024, 02:48:03 pm
content: Does anyone use GNUStep now?I took a quick look at the github and all the subprojects have had commits in the last week, and many of them in the last 24 hours, so it appears to be actively maintained.I haven't had the need to do such things for some time, but I always loved how Interface Builder worked. Very very fast to build simple apps.Of course it uses Objective-C for the GUI stuff, but I think that's fine. It's simple, it lets you write all your own stuff in straight C/C++ if you want to (though their collection classes, string classes etc are handy and feature-rich when Python-ish performance levels are ok e.g. UIs). And it's all supported in gcc and clang, everywhere, I think.I just tried on my Lichee Pi 4A RISC-V board...Code:#import <Foundation/Foundation.h>int main (int argc, const char * argv[]) {NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];NSLog(@"Hello world!");[pool drain];return 0;}Code:$ sudo apt install -y gobjc gnustep-devel$ gcc hello.m -o hello `gnustep-config --objc-flags` `gnustep-config --base-libs`$ ./hello2024-09-13 14:43:39.941 hello[70653:70653] Hello world!So .. works on RISC-V. Which means it'll be no problems on an Arm board too.I haven't tried GUI.

author: ataradov
author_rank: Super Contributor
timestamp: September 13, 2024, 02:52:00 pm
content: Quote from: brucehoult on September 13, 2024, 02:48:03 pmWhich alone is enough to disqualify it for me. Learning and figuring out infrastructure for a new language just for this is not something I would ever consider doing.And the fact that I have not seen any software in the wild actually using it, tells me that I'm not too wrong. If it was so much better than other options, people would use it.

author: brucehoult
author_rank: Super Contributor
timestamp: September 13, 2024, 03:05:03 pm
content: Quote from: ataradov on September 13, 2024, 02:52:00 pmBasically 100% of apps on MacOS and iOS use it, or at least Apple's version of it, and have done for 25 years. Recently more new things are written using Swift rather than ObjC, but it's the same libraries.

author: ataradov
author_rank: Super Contributor
timestamp: September 13, 2024, 03:07:41 pm
content: Quote from: brucehoult on September 13, 2024, 03:05:03 pmI meant outside of Apple stuff, of course. People use it on Apple not because because they like it, but because they have to. And I have not heard a lot of love for it from those people. It is just something they are forced to use, so they use it.As soon as you don't have to use it on other platforms, you instantly drop it.

author: brucehoult
author_rank: Super Contributor
timestamp: September 13, 2024, 03:49:30 pm
content: Quote from: ataradov on September 13, 2024, 03:07:41 pmI don't agree with that. Back when I used to write GUI apps I liked Cocoa/NextSTEP much more than others I was forced to use at times such as MFC and QT.Anyway, I tried a simple GUI app on the Lichee Pi, logged in with "ssh -X", and sure enough it popped the app up on my desktop PC (a Mac in this case, running an X server).Code:// hello.m#include <AppKit/AppKit.h>@interface AppDelegate : NSObject<NSApplicationDelegate>@end@implementation AppDelegate- (void)applicationDidFinishLaunching:(NSNotification *)notification {NSAlert *alert = [[[NSAlert alloc] init] autorelease];[alert setMessageText:@"Hello, World!"];[alert runModal];[NSApp terminate:nil];}@endint main(int argc, char *argv[]) {NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];NSApplication *app = [NSApplication sharedApplication];AppDelegate *appDelegate = [[[AppDelegate alloc] init] autorelease];[app setDelegate:appDelegate];[app run];[pool drain];return 0;}Easy peasy!

author: Jeroen3
author_rank: Super Contributor
timestamp: September 13, 2024, 03:52:36 pm
content: Quote from: Simon on September 11, 2024, 05:20:50 pmC# using .NET (not framework) is supposed to be cross platform. Microsoft is obsoleting everything windows-only in it, and it's super annoying.Qt can be used as well, learning curve is steep, not everything is lgpl. up to qt5 it's fine, but from qt6 you need to compile your own binaries, this is complicated and slow.Python is fun, for small things. tkinter is a bit special but for very simple things this is fine. You could even use Qt with python.However, I'm not sure what you want, recently I foundTextual, which makes old dos style programs possible again!If you are truly going for C/C++ I'm afraid some modern UI will probably be web-based. I hate the fragility of web libraries, but it's what the industry has chosen. Frameworks such as Qt or Winforms are going extinct. You now have Angular and React. (ps. even the non-widgets Qt stuff is web)

author: ataradov
author_rank: Super Contributor
timestamp: September 13, 2024, 03:58:59 pm
content: Quote from: brucehoult on September 13, 2024, 03:49:30 pmI'm not arguing that it is hard too get a simple application going. If someone doing big practical application decided that it was overall the best solution for GUI in their case, we would see application using it. I can't name a single application doing it outside of Apple ecosystem.It may be nice and all, but overall people deciding against it considering all other factors.

author: brucehoult
author_rank: Super Contributor
timestamp: September 13, 2024, 04:30:31 pm
content: Quote from: ataradov on September 13, 2024, 03:58:59 pmOr, simply didn't know it was an option, didn't know it was portable outside of the Apple ecosystem.Also to different display back ends, by the way, including Cairo (which in turn supports X, Wayland, Quartz, Win32, raw frame buffers, PostScript, PDF, SVG, OpenGL), X11 directly, Windows GDI directly.

author: Simon
author_rank: Unknown
timestamp: September 13, 2024, 06:22:50 pm
content: OK so I can compile a linux console app on the debian machine from the windows machine, the next challenge is to add the FLTK libraries. I'm not sure which end I need to do this, the manual says that I need to add the " -L/usr/local/lib -lfltk -lXext -lX11 -lm" option.I have various *.a files in usr/local/lib from compiling the FLTK libraries.

author: ataradov
author_rank: Super Contributor
timestamp: September 13, 2024, 07:03:07 pm
content: The end that does the linking need to do this. You will also need the corresponding X11 files. Cross compiling a GUI app will be a much bigger challenge. And if FLTK is not setup for that already, it may be a lot of work. I personally would just build locally for each OS.Or, wait, if you are just SSHing into the Linux machine from Windows, then you have all you need. You don't even need to build FLTK yourself, Debian for sure has dev filed for it.Compile any program with those flags and you will likely get linking errors. If you do, you will need to install corresponding packages. Development versions usually end with "-dev" suffix. So, it wold be something like libx11-dev, libfltk-dev.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 13, 2024, 07:04:48 pm
content: Quote from: Simon on September 13, 2024, 06:22:50 pmImGui is preferable because it uses 3d mode natively, which is always present in modern solutions. FLTK has an add-on for this, and as a result you need 2 steps to understand its rendering process. So I will use Dear ImGui.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 13, 2024, 09:02:00 pm
content: Quote from: Simon on September 13, 2024, 02:09:30 pmIf you feel confused after having asked a question on some social media and getting a bunch of answers going in all directions, that's kinda what's to be expected in general. Isn't it.Quote from: Simon on September 13, 2024, 02:09:30 pmFLTK is fine, it's not the prettiest GUI toolkit there is in terms of visuals, but it's decent, it works and is cross-platform.You don't have to invest too much time either to figure out if that's what you want or if you have to keep looking.Just download Code Blocks, follow the tutorial I linked to, open a few example projects and toy with them. See if that fits your bill. If not, move on.Obviously the language is key here too. If you absolutely want to use C++, then FLTK is alright and Qt would be too, but as I said, much heavier weight, with possible licensing costs for commercial projects, so that may not work for you.If you're more flexible with the language, then you could even use Python. Or freepascal/Lazarus. You could also use GTK with C or C++.Imgui is great but keep in mind it doesn't look anything like native widgets, will not directly have (at least portably) a way to use OS controls such as open file, print dialog, etc, and on top of that has a pretty radically different approach to GUIs than the others ("immediate" concept).

author: Simon
author_rank: Unknown
timestamp: September 13, 2024, 09:49:15 pm
content: Python scares me, it sounds like someone came up with a swiss army knife that someone else tried to converter into a chainsaw. I don't like the whole tab thing, I see that it would be OK for little scripts but a whole language? I also tire of having to learn a new vocabulary of terms because some jerk decided that they had to really go all the way in pretending that this chain saw really is the real deal and very different from a real chainsaw so as to have me think I can't just go and get the proper tool. strings, arrays etc really don't need new names and if I have to learn all that just to talk basic python well they can shove up their wazoo for all I care unless there is a really good reason I should be using it over something else.

author: nctnico
author_rank: Super Contributor
timestamp: September 13, 2024, 10:37:02 pm
content: Quote from: ataradov on September 13, 2024, 02:16:53 pmI second the suggestion for using WxWidgets. This has been my go-to cross platform library / framework for over 2 decades. Even without using a GUI or requiring a program to be actually cross-platform, WxWidgets takes care of a lot of OS Idiosyncrasies. An alternative is Qt but care must be taken to have it use the native OS GUI controls when building a GUI otherwise you end up with something awfull and people need to jump through all kinds of hoops to get it look like something they can use.Where it comes to WxWidgets I can recommend to buy the book in order to get started quickly.About Python: I get that it means going through a new learning curve, but in the end Python is rather powerfull. If you want to get things done quickly then Python is the way to go. I don't call myself an expert but so far I'd rather use Python to create a small program to automate testing or doing some scripting compared to using C++. Python takes a lot of grunt work away.

author: radiolistener
author_rank: Super Contributor
timestamp: September 14, 2024, 01:11:51 am
content: Quote from: Simon on September 13, 2024, 02:09:30 pmhere is comparison between ImGui and FLTK.10115 forks / 59381 stars of ImGui versus 263 forks / 1631 stars for FLTK shows which one has decent endorsement.ImGui is cross-platform, so you can use it on Linux / Windows / MacOS / Android.It works well on PC and on SBC like Raspberry Pi.

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2024, 01:43:47 am
content: This means very little. FLTK is stable and does not need a lot work, so there is no particular reason to fork it.One huge disadvantage of ImGUI is power and resource consumption. You will be drawing all the stuff 30/60/unlimited frames per second whether stuff changes or not. Open any ImGUI based application ans see how much CPU it consumes. This is not an issue for games, since they draw stuff anyway. This is not great for desktop applications. This is possible to solve, but this is not how it works out of the box.And of course, ImGUI is more popular because of its use by the game industry.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 14, 2024, 01:59:04 am
content: Quote from: ataradov on September 14, 2024, 01:43:47 amPlease explain how to create such a program that manages to eat up resources by outputting static data once to the buffer?Quote

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2024, 02:09:04 am
content: It outputs data once every frame. You have to render the whole UI every frame. It is objectively less optimal than an application that only renders on events.Ultimately, I don't care what anyone uses.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 14, 2024, 02:27:51 am
content: Quote from: ataradov on September 14, 2024, 02:09:04 amThis is done by a 3D accelerator based on the buffer supplied. If some schoolboy started updating this buffer in the maximum cycle, then I just listened to the opinion of this schoolboy in your performance.

author: radiolistener
author_rank: Super Contributor
timestamp: September 14, 2024, 03:54:25 am
content: Quote from: ataradov on September 14, 2024, 01:43:47 amHowever, ImGui has 59400 satisfied users, while FLTK has only 1600 satisfied users.And ImGui also stable, it's just more friendly to make some customization in the code...Quote from: ataradov on September 14, 2024, 01:43:47 amJust tested it on Raspberry Pi. Even with the Demo window, which includes almost all widgets with thousands of controls in one window, it consumes about 5-8% of the CPU and works very smoothly. I would like to see how much CPU FLTK would consume with a thousand different controls in one window.The executable is about 1.4 MB and requires just SDL2 or GLFW library.Just for comparison with Qt, which needs to install gigabytes of different libraries...As I said before, ImGui works very fast and well with pretty heavy UI on Raspberry Pi Zero 2w in DRM/KMS mode through SDL2 backend with total system memory consumption about 200 MB of 512MB available... where about 155 MB is allocated by Linux OS.Quote from: ataradov on September 14, 2024, 02:09:04 amYes, that's true. It doesn't consume much (max 5-10% on Raspberry Pi), and this is not an issue for an active app. You can eliminate this CPU load for minimized window. But for a background window which is visible, it may be a drawback.However, even for a background window, you can use tricks like reduce refresh rate frequency, which will lower CPU consumption, making it almost the same as for event-driven UI. Since background window don't needs smooth animation, you can reduce its refresh rate with no issue.But you're right, for a tool which don't needs smooth graphics UI and it's background work should not affect CPU load much it may be drawback. And this is why I still looking for some WinForms replacement for Linux.

author: Simon
author_rank: Unknown
timestamp: September 14, 2024, 06:49:28 am
content: There is also LVGL, I don't know where square line studio got to as changes have been afoot.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 14, 2024, 03:48:13 pm
content: Quote from: radiolistener on September 14, 2024, 03:54:25 amThe fact that you and your friend ataradov can't use it normally doesn't bother me at all. However, it does mean that beginners may have difficulties with ImGui.

author: djsb
author_rank: Super Contributor
timestamp: September 14, 2024, 06:14:24 pm
content: If you want to give WxWidgets a try, I would recommend these tutorials as a tasterhttps://www.youtube.com/playlist?list=PLFk1_lkqT8MbVOcwEppCPfjGOGhLvcf9GThe tutorial use Visual Studio and OttoBotCode is responsive to questions if you get stuck. I've got as far as episode 8 (of 16 episode) so far. There have been no major problems so far. I'm going to go over them again at some point to reinforce/review what I've learnt.

author: Simon
author_rank: Unknown
timestamp: September 14, 2024, 07:16:09 pm
content: Quote from: Postal2 on September 14, 2024, 03:48:13 pmWhy do you see it your mission in life to beat everyone into submission in agreeing with you? oh, of course....

author: Simon
author_rank: Unknown
timestamp: September 14, 2024, 07:31:44 pm
content: Well a squareline studio project will not build, well cmake fails. Maybe I will just try to setup the lvgl library by myself but not sure how to go about it.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 14, 2024, 09:07:01 pm
content: Quote from: Simon on September 14, 2024, 07:16:09 pmThere are obvious things (like CAN bus), I try to explain, but I'm a really bad teacher. If the program just fills the buffer according to the current state - then it's the programmer's choice how often it does this. You can also run polling of an event that will never happen, and wonder about the resource consumption.ImGui is really very good, it has a modern approach and you still have to work with it.

author: Jeroen3
author_rank: Super Contributor
timestamp: September 15, 2024, 11:47:13 am
content: Quote from: Simon on September 13, 2024, 09:49:15 pmIt should scare you. However python has libraries for almost everything. It might not be fast, but you can make something fast. Like an arduino.Want to talk to your scope,sure. Want to write excel?Sure. Want to convert an image to ascii art,sure.Now try those things with C/C++, you havehttps://github.com/uhub/awesome-cyet you may still have to do many things yourself.But, tabs vs spaces should not be an issue anymore, your IDE does those. And there are linters for it. The worst bit is the weak typing, but there aretype hintsnow.(it's awfully close to C# today, which is a dumpsterfire of new conflicting features of itself)Not trying to convert you to python, just trying to paint the complete picture.C still is the best language ever invented. Everything else is basically calling C functions.Please do show your progress! I'm curious.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 12:06:37 pm
content: Oh you don't have to convert me. I started reading a book although I guess as always I was trying to do it the hard way: actually understand what the fuck I am doing rather than just creating copy paste mashes.I just got bored of having structures and arrays re explained to me like they are something really neat and specific to python just because they have a different name to what any other sensible language uses.The library availability has been what had me considering it. Time is always of the essence and I hate doing something that I am sure already exists. Having said that lots of people are in a hurry when they write their libraries and make a right mess of it.My only incentive to look at C++ was that I was getting a bit lost in C with the quite distinct separation between the language and the libraries. Try to read about the libraries and you are told that you need to know the linux interface. Start looking at the linux interface and you are told that you need a working understanding of the libraries. So I concluded that with C++ being more modern and maybe less hippy things would be clearer.Ultimately I could not care less what the language is, I am not a fanboy of anything, I have a job to do.So python is an interpreted language. Does this mean it will run slower? I have heared that it can be compiled now. Is this a mash up or is it a serious solution?

author: Jeroen3
author_rank: Super Contributor
timestamp: September 15, 2024, 12:39:50 pm
content: Quote from: Simon on September 15, 2024, 12:06:37 pmIt depends. Do you have specific performance targets to hit?You can compile python, it will be byte-code iirc. Still needs the interpreter. There are also some gotcha's in deployment, like launching is slow, but running is not for example. (loading runtime...)You can even compile it to C first, I've never done this. (cython)The multi-platform architecture is a penalty on performance, but a huge gain in development. This is vastly different from C/C++ which compiles to actual machine code immediately.Which will always be faster that any other higher language. But the question is, does the extra effort of C/C++ weigh up to the gained performance.I learned last week you can also run native javascript, if you hate yourself again an evenening you can play with that (with node.js).

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 01:30:43 pm
content: Well speed to launch is not critical as long as it is fast enough. This would run without the desktop. Last time I turned a RPi4 on with any old SD card and linux server it was alive in less than 30 seconds to get to the command line. From there the program would launch unless it needs more than the command line.I'm willing to put a solid state drive in it. Well MMC or whatever they are called.

author: brucehoult
author_rank: Super Contributor
timestamp: September 15, 2024, 01:47:44 pm
content: Quote from: Jeroen3 on September 15, 2024, 12:39:50 pmHundreds of millions of dollars have gone into making JavaScript run fast, starting 15 years ago. Heck, it might be billions of dollars by now, between Google, Apple, and Mozilla.If you run JavaScript in node.js it's faster than C compiled with default optimisation.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 02:05:04 pm
content: How do you mean "run JavaScript in node.js" ?

author: brucehoult
author_rank: Super Contributor
timestamp: September 15, 2024, 02:29:33 pm
content: Quote from: Simon on September 15, 2024, 02:05:04 pmCode:bruce@i9:~$ echo 'function fib(n){return n<2 ? n : fib(n-1)+fib(n-2)}; console.log("Hi from js, fib(40)="+fib(40))' | time nodeHi from js, fib(40)=1023341550.57user 0.00system 0:00.58elapsed 100%CPU (0avgtext+0avgdata 37872maxresident)k0inputs+0outputs (0major+2753minor)pagefaults 0swapsActually, I exaggerated. C with default optimisation takes 0.509 seconds for the same thing on the same machine. But it has the advantage that the compile time isn't included. If I time compiling and then running I get 0.53 seconds.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 03:12:19 pm
content: uh, no one will quibble over 0.21 seconds for a UI launch.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2024, 03:24:35 pm
content: Quote from: Simon on September 15, 2024, 12:06:37 pmThis thing about the libraries is quite the same with C++, but even more so. You cannot write modern C++ without making extensive use of the standard libraries (generally STL, or Standard Template Libraries).On the C side, it should be less the Linux interface, and more the Posix interface, which is a cross-platform standard. But it is true, that the C libraries are very Unixy in nature.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2024, 03:28:12 pm
content: Quote from: Simon on September 15, 2024, 12:06:37 pmFor most purposes, execution speed is less important than how quickly can you get a job done, or solve a problem.You can get an idea of what you can do with Python by watching some of Matthias Wandel's videos. He uses Python for calculation tools, hardware interfacing, and remote monitoring, for example.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 04:14:47 pm
content: Quote from: IanB on September 15, 2024, 03:24:35 pmSorry I forgot to finish, I was going to say that it felt like C++ had more built in support and that maybe the libraries are less of a mystery. I have only done bare metal micro controller programming so far so it's sort of start again from the other end of the candle.

author: brucehoult
author_rank: Super Contributor
timestamp: September 15, 2024, 04:15:10 pm
content: Quote from: IanB on September 15, 2024, 03:28:12 pmFor reference, that same fib(40) that takes 0.57s in JavaScript and 0.51 seconds in C takes 22.5s in Python, a factor of 40x.While you can argue that Python is faster to write code in and has a larger ecosystem of libraries than C, I don't think you can claim the same for Python vs JavaScript.And pretty much all the headline uses of Python are in fact Python wrappers around C code that does all the heavy lifting.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 04:19:52 pm
content: So I don't understand, if it's all C underneath why can't it be properly compiled?

author: ataradov
author_rank: Super Contributor
timestamp: September 15, 2024, 04:21:19 pm
content: The slowness of Python does not come from the fact that it is not compiled, its interpreter is extremely fast. The slowness comes from the high level abstractions and the need to allocate memory for all the operations. And its allocator is very efficient, but it is still an allocator.On the up side, you don't have to worry about integer value ranges, it is all infinite precision by default.And yes, a lot of AI and other high performance uses are just bindings to C code. So slowness of Python is fine because it is just a scripting language to tie together high performance code.Also, it is possible to write fast native Python code, but you need to be use specific constructions that result in fewer allocations underneath. This is not hard, but it is still something you have to learn.This is very similar to Matlab. It is a very fast and highly efficient language, but it gets dog slow as soon as you start doing things that result in memory reallocations and data movement.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2024, 04:27:39 pm
content: Quote from: brucehoult on September 15, 2024, 04:15:10 pmYes, but it's a case of using the right language for the right job. Nobody would seriously think Python is the right language for a simple recursive function benchmark. On the other hand, Python is heavily used for machine learning, AI and related tasks, and this is because of the rich numerical libraries and visualization tools that make such jobs a breeze in that environment.QuoteExactly. And why is this a bad thing?Bear in mind that in other languages, a clever optimizer will remove the recursion and turn the program into a simple loop, in which case that benchmark should execute in microseconds.

author: brucehoult
author_rank: Super Contributor
timestamp: September 15, 2024, 05:06:07 pm
content: Quote from: IanB on September 15, 2024, 04:27:39 pmA simple recursive implementation of Fibonacci numbers is not the point. That's just so I didn't have to write ten thousand lines of Python for a web forum post.The point is that as soon as you have a lot of Python code, and it's calling functions and looping and computery stuff like that, and takes an annoying amount of time, you can make your computer seem 40 times faster by writing your program in C or JavaScript instead.JavaScript in particular is just as fast to write as Python, has non-perverse syntax, and has at least as large an ecosystem of libraries as Python. And you don't have to go "Oh no, my code is too slow, I'd better rewrite half of it in C". Because it's already pretty much as fast as C. JavaScript is not only for web sites.

author: brucehoult
author_rank: Super Contributor
timestamp: September 15, 2024, 05:10:28 pm
content: Quote from: IanB on September 15, 2024, 04:27:39 pmI don't know of any optimiser that can turn double recursion into a loop.Yes, the the Fibonacci sequence happens to be able to be implemented as an iterative recurrence relation, but that's deeper mathematics specific to that function that doesn't apply in general to other doubly-recursive functions such as, for example, QuickSort.

author: Jeroen3
author_rank: Super Contributor
timestamp: September 15, 2024, 05:58:00 pm
content: By far the best example of slow python is SABnzbd. It's a server application with a web frontend that downloads files from usernet servers.It works fine for your DSL link, but if you get into gigabit wan speeds of 100MB and up the python tax starts to bottlenek on CPU. Especially with python 2 which was fundamentally unable to run multithreaded due to interpreter lock.Then you upgrade to NGBGet, which does the same, but is written in native C++.However, this has the drawbacks: It can only run on NAS boxes where is was cross compiled for. This meant that is might run fine on a x86 synology, but not an ARM synology.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 06:38:37 pm
content: Everything Javascript just goes on about web pages. Is every application therefore run in a browser or what?

author: ataradov
author_rank: Super Contributor
timestamp: September 15, 2024, 06:41:40 pm
content: No, JS can run as a standalone language independent of the browser. But a basic search would only find the browser stuff, since it is what majority of people would use.Look for "node.js" stuff specifically. It is Google's V8 JS engine adopted to run outside of the browser.But I'm not sure I would want to use it as a general purpose language. JS is still pretty lax with its syntax and libraries for the desktop use are not all there. It is still oriented more towards server side of the web applications.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 06:48:13 pm
content: Ok so it's still python for now, any recommended books on python?

author: ataradov
author_rank: Super Contributor
timestamp: September 15, 2024, 06:56:54 pm
content: Not from me, I just googled stuff I needed to do if something was not clear.But I don't understand the switch to Python. What was wrong with C++? If you need GUI, it will be hard to get cross platform stuff no matter what. And FLTK APIs look basically the same in C++ and Python.Python abstracts some of the OS stuff, but not all, and you still need to be careful writing cross platform code.One huge disadvantage of Python is that if you are distributing raw *.py files, you will also need to provide instructions to the customers on how to install all the dependencies. There are packers that would let you package all that, but I have no idea how well they work.No matter what you pick, you will have to spent time figuring things out and making sure that everything works on all the platforms you want to support. There is not one clear winner here, all possible solutions have upsides and downsides. You just need to pick the ones where downsides do not matter in your case. And to do that, you really need to get a few examples going in a few libraries/languages and see which one you like most.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 07:17:44 pm
content: Well apparently you can do it all in python, like you say I just need to get something going. I guess I need to try C++ too but it looks like maybe I just need to code for linux on Linux. I just go round in circles trying to setup an environment to work in. It's like they said just drive down the road in this car but the car has the wheels laying on the floor and the wrong size nuts are there to put them back on with and the only shop in town that sells them shut for a month.I'm almost sick of linux before I even start. Clearly I have to be a commandh line guru or I should not do anything. I set up debian on a laptop as I could not get anything sensible to run on a rasperry pi, well ubuntu would not even work on this laptop but then I think ubuntu is the windows of the linux world. So in debian I can't even copy and paste files from one folder to another and many other "normal" things you would do work as even though my account is an admin one, nah, I mean how hard is it supposed to be?Is a virtual machine worth considering? save me from jumping between a nice large desktop and a poxy little laptop. every time I look something up for help I just find more gogglybook, I mean where the heck does one start when one wants to start? No tutorial explains why you should do what it says and no tutorial is successful, but as they never told you why they told you to do things you are left, once again, 90% of the way there and buggered.

author: ralphrmartin
author_rank: Frequent Contributor
timestamp: September 15, 2024, 07:22:18 pm
content: Quote from: brucehoult on September 15, 2024, 05:10:28 pmYou need a language that will do memoisation, like LISP...

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2024, 07:31:44 pm
content: Quote from: Simon on September 15, 2024, 07:17:44 pmYes, for sure, a VM is worth considering. But before you go there, did you know Windows can run Linux directly, without even switching to a different machine?https://learn.microsoft.com/en-us/windows/wsl/installWindows also has a VM environment built in, and you can run Linux easily there too:https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/about/But, for a good experience you will need to make sure you have a decent spec PC with plenty of cores and memory, and you may need to be running Windows 10 Professional or Windows 11.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 15, 2024, 07:50:55 pm
content: Quote from: Simon on September 15, 2024, 07:17:44 pmYou don't need to "try C++" specifically, this extension is specifically made for the environment where you just write C. Over time, your eye will get used to the syntax generated by the machine, and you will start using it.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 08:02:57 pm
content: Well I have installed code blocks on my debian laptop and the hello world fltk program runs. vs code could not find any of the includes, despite me following the instructions.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 08:08:15 pm
content: Quote from: IanB on September 15, 2024, 07:31:44 pmYes I have heard of it, I have probably heard of most things by now but hearing of them is not enough to get anywhere with them. I started this thread using visual studio on a computer that had the WSL installed (and that name is backwards.... it's a linux subsystem that runs on windows? but then I know nothing). But I could not connect to it! I did manage to connect my physical laptop. But then the FLTK header files could not be found despite me following the install instructions that naturally were written for people who already know how the whole shbang works and as everyone does this I have no way of know where to start and how a basic setup works.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 08:10:40 pm
content: Quote from: ralphrmartin on September 15, 2024, 07:22:18 pmI already have a lisp and it never got me anywhere

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 08:12:01 pm
content: my virtiual machine also with debian has decided that my user is not on the sudo list...... cause every time I install the very same thing I get different results. Is ubuntu any friendlier? will it work on a virtual machine?

author: ataradov
author_rank: Super Contributor
timestamp: September 15, 2024, 08:19:41 pm
content: You can add user to the sudo list. What's the problem? Also what different results? Any Linux distro will work on a VM. But if you just jump from one to the other at the slightest problem you will not get anywhere. Just stick with one and figure out how to use it.But if you are asking for recommendations, I would stick with Mint.

author: Simon
author_rank: Unknown
timestamp: September 15, 2024, 08:34:23 pm
content: Yea I came across some long winded explanation. But that seems to be linux, sure you can drive down the road today, just change the brakes first... because.... I might try mint, I did try it once for desktop but as I'm sure we all know, unless you can program for linux you have no business expecting to be able to use it day to day so I'm still on windows. If I manage to get up and running with programming I guess I'll be able to use it properly some day.

author: ataradov
author_rank: Super Contributor
timestamp: September 15, 2024, 08:51:00 pm
content: Quote from: Simon on September 15, 2024, 08:34:23 pmThis is blatantly not true. There is absolutely no need to know programming to use Linux.

author: IanB
author_rank: Super Contributor
timestamp: September 15, 2024, 09:17:51 pm
content: Quote from: Simon on September 15, 2024, 08:08:15 pmYes, but Visual Studio is for Windows, not for Linux. If you try to build Linux programs on Visual Studio you will be making things impossibly difficult. To work on Linux, you have to work entirely on Linux, and ignore Windows. That means using Linux code editors, and Linux compilers, like gcc.You can install and run VS Code on Linux, but not Visual Studio. I know we've been here before, but it is worth repeating: VS Code is not Visual Studio, and Visual Studio is not VS Code. They have got nothing to do with each other. When posting here, please do not say "Visual Studio" unless you truly, genuinely mean Visual Studio, and not VS Code. Otherwise we will be very confused.This is the page about how to install VS Code on Linux:https://code.visualstudio.com/docs/setup/linuxI know the title says "Visual Studio Code", but that is insanely stupid on Microsoft's part, and it is just a case of Microsoft trying to confuse people.

author: shabaz
author_rank: Frequent Contributor
timestamp: September 15, 2024, 11:43:02 pm
content: Some of it is just about finding a way that you're comfortable with, there's no one right way or wrong way.For instance, I do most of my development on a Windows machine, but there are so many things that I'd like to also do in Linux, so a VM is super-useful. However, since I'm usually in the same physical location where I can have other machines, I decided to get some cheap machines (I have two or threeIntel NUCs, they are tiny, fairly quiet, and cost very little nowadays in used condition, maybe $100 or so, i.e. cheaper than some Raspberry Pi's + enclosure + SSD), and then I've got Linux on a couple of them, and VMWareESXI(it is free, bit of a learning curve though, and not an essential thing to start off with) on another so that I can quickly swap between VMs (i.e. I only run one VM on that box usually, but could run a couple simultaneously if really required). None of the NUCs are connected to a monitor or keyboard, they are just connected via WiFi or Ethernet to the network.VS Code on Windows has really nice remote Linux coding capability (it is an extension from Microsoft called "Remote - SSH"), it is pretty exceptional. Well worth a try in case it suits the way you want to work. This saves me from needing to run a remote desktop. Then, I can use an SSH terminal (I likeSecureCRTon Windows, it is equivalent to freePuTTY, but nicer but not free; there are other good free options but I don't know them) to get to a Linux shell and perform builds there if desired. Also, totally agree with the above comment that if you're developing for Linux, then build it on Linux, i.e. don't cross-compile unless you can justify it to yourself, because it is easy to end up with things breaking due to slightly different libraries being used. Cross-compiling is necessary for microcontrollers, but for desktop and server apps it's unnecessary usually (unless you're developing for a career, in which case there could be very good reasons for it, e.g. build-server support by the IT team, higher performance machines, and so on).I developed a C++ application running on a server for about five years, and it takes daily work with C++ to try to be reasonably competent, so it is for sure a high barrier. I'm still only familiar with a subset of C++ and a subset of the Standard Template Libraries (STL), since I no longer code frequently in C++. I didn't like it initially, but now I prefer Python unless there's a good reason not to. It's just very productive, you can do a lot with very few lines of code, and it is excellent for data manipulation type of programs. Plus there are many libraries for helping with almost anything. Example: I needed to write code the other day to make backups of file folders, timestamped and delete the oldest, and search-and-replace content within each one, based on text menu input from the user; it was all done in a couple of dozen lines of code.Python is a good complement to more 'normal' languages like C/C++; for instance, for writing tests, Python can save a lot of time, because you can use it interactively. In other words, your microcontroller app could be in say C or C++, but you could then test it with Python from your PC (or from microcontrollers running MicroPython). As an example, you could write a function to send I2C data, and then interactively (from a Python shell) issue commands one at a time, allowing you to (say) capture other signals with a 'scope easily since you're in control of the I2C stream. This is just a contrived example. Plus, MicroPython on boards like Pi Pico is very close to normal Python, so you've got control of hardware interfaces (GPIO, and peripheral interfaces like SPI or I2C, or UART or RS-232) very easily, under direct interactive control.As an example, when I wanted to test a servo motor, the interactivity looked something like this, all done one command at a time, so I could (say) quickly stop the motor if I was unhappy with something, or go back and try a different speed if it vibrated and so on:Code:import my_motor_controller as mm.reset()m.op_mode(m.SPEED)m.set_velocity(20)m.set_velocity(400)Some systems allow for combining great speed with that Python ease-of-use. An obvious example is that Pi Pico's high-speed 'PIO' code can be executed from MicroPython and data from the PIO can be processed by MicroPython too. You can also technically write some function in C to accelerate them, and execute from within MicroPython, although there are some limitations (it suits algorithms more than GPIO control from C).On a PC, you could write some parts of code architected as C command-line apps, and then execute them from within Python, but I've not often needed to do that, since Python is speedy enough for whatever I've worked on.Regarding GUIs, unfortunately (or fortunately) I've never had much need for developing them, and so I use what tools I'm familiar with, which can be config files, or command-line parameters, or (if none are supplied) just get the C/C++ or Python program to display a menu and prompt the user for input. But as mentioned by others, there are Python GUI libraries; I've not used a single library frequently enough to get good with it, but pyQt was fairly straightforward to use the few times I've tried it.If I just need graphical output with no GUI interaction, then again there are lots of options, ranging from (say) matplotlib for nice charts, to writing out SVG format, or generating data files for importing and charting with Excel or MATLAB or whatever.I also quite like (hate to mention the language!) to just use JavaScript for a simple web app; I don't like JavaScript itself, but it sure is convenient for a way to make an app that needs no compiling and will run on any platform with a browser. It's also super-easy to then convert that to what looks like an app on your mobile phone. I'm just a beginner, but there are enough examples online to make progress with JavaScript to do quite a lot. JavaScript can interact with hardware through various ways; one way is to implement your own web server (this is where Node.js is quite a useful option (it runs JavaScript on your server too, so you can program exclusively in JavaScript on both server and client [browser page], but you can also use Python, if you wish to minimize JavaScript usage to the web page only.A nice mechanism (well, it's the only one I know - I'm no expert in this) is to use socket.io; it allows you to asynchronously send and receive data between the server and the web page in the browser. This means you don't really need a GUI library at all, if all you want is things like boxes and buttons on a browser page, interacting with your app.I'm OK with not knowing everything, and not starting from first principles when it comes to writing code; I can generally fill in the blanks later for the areas I didn't initially understand. This doesn't suit everyone of course. I spend a fair bit on books (and books get outdated quickly, but I still find it's worth the investment provided I make use of the book quickly!). Provided it is a good book of course (some are pretty bad) to learn some best practices etc. Watching programmers code over their shoulder, to see what tools they use, how they name things, what notes they take and so on, and ask them questions, is super-interesting, but it's not feasible for many, especially if you're working in isolation.I'm a member of a Linux User Group or LUG (I simply joined an arbitrary one, not actually anywhere near me) and if I get stuck, then I can email and someone might know the answer, or I can wait and ask questions on the next Webex/Zoom group meeting and so on. A nearby one would have the benefit of in-person meetings of course. Many members do programming for a career, so generally someone is around to give some help if it comes to it; I don't necessarily ask Linux-specific questions, I just ask general programming questions and I try not to annoy the members by focusing on Windows. There are LUGs worldwide.This comment was a longer than it was intended to be; I don't know if any is useful or relevant, but I thought it worth adding in case you spot anything useful.

author: brucehoult
author_rank: Super Contributor
timestamp: September 16, 2024, 12:38:06 am
content: Quote from: ralphrmartin on September 15, 2024, 07:22:18 pmAny language can do memoisation using an array or hash table / dictionary but yes only a few such as CLOS, Dylan, Prolog allow you to add methods to Generic Functions on the fly.For example, consider the following Dylan program:Code:Module: hello-worlddefine dynamic generic fib (n :: <integer>);define method fib (n == 0) 0 end;define method fib (n == 1) 1 end;define method fib (n :: <integer>)let res = fib(n - 1) + fib(n - 2);//add-method(fib, method(n == n) res end);resend;format-out("Hello, world! %=\n", fib(40));Compiled with Open Dylan 2024.1 it runs in 1.655 seconds.Uncommenting the add-method line makes it run in 0.013 seconds.Writing a normal recursive function makes it run in 0.39s, so faster than the 0.51s for C with default -O0 optimisation.Code:define function fib (n :: <integer>) => (res :: <integer>)if (n < 2)nelsefib(n - 1) + fib(n - 2)endend;Generic functions are a little bit slow compared to simple function calls, as they have to examine the arguments to do dynamic dispatch. But of course you would not normally do this for such simple functions, so the overhead would be less.

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 06:29:16 am
content: Quote from: IanB on September 15, 2024, 09:17:51 pmIndeed, when I said visual studio I meant visual studio, and when I said visual studio code I meant visual studio code. I am aware that they are not the same thing. I have to try everything. I prefer visual studio, but alas. as vs code is just an editor it makes things more complicated as setting up paths etc is left to me.

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 06:38:04 am
content: Quote from: ataradov on September 15, 2024, 08:51:00 pmIn the past every time I sought help the answer was, well this is linux, we fix our own problems, that is what makes it so great you can fix the code and change things because it's open source. I kid you not, I have been told this when reporting problems.I once installed the open source equivalent of cPanel on a server. Got it all setup and a little bemused by the minimal user interface. Then the emails stopped working after an update. I spent ages just finding out the problem with a well known package. Everyone seemed to know and accept that it was broken. Small matter of a line of text in some file if not a character that someone grudgingly told me about. Now cPanel uses the same package, never had the problem, but cPanel is commercial with customers to keep happy, not a bunch of hippies that measure people up by how many well known but unfixed bugs they know about.

author: radiolistener
author_rank: Super Contributor
timestamp: September 16, 2024, 06:38:51 am
content: Quote from: ataradov on September 15, 2024, 06:41:40 pmJS could be a great language, but...

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 06:47:24 am
content: Quote from: Simon on September 16, 2024, 06:38:04 amThis is because instead of asking specific questions you make statements like "I've got some error, your stuff is broken".All software has bugs. For closed source software people just came to accept them because there is not much you can do. OSS does offer you ability to fix bugs, but you are absolutely not expected to do so. You can just do the closed source thing and wait for someone else to fix it. And if some piece of software does not work for you as a result of existing bugs, you can try something else. There is not just one cPanel equivalent, there are a lot. If all of them don't work, you are likely doing something wrong.But if you think Linux if not for you, it is fine. At the same time if you really think it is broken beyond being usable, you are mistaken and likely missing something. Whether you want to figure it out and use it is up to you.

author: gnif
author_rank: Unknown
timestamp: September 16, 2024, 07:44:05 am
content: @SimonI have not read through every post here, but I will weigh in with my $0.02 on development on Linux. But first a few things to clear up.C and C++ can link against and use each others libraries. If your only goal is to use C++ so you can use C++ libraries, then you're already shooting yourself in the foot. The main difference is the function name mangling, C doesn't mangle names, but C++ does. You can though write wrapper headers that will interface to C++ code from C just fine.Note: this is all written from the top of my head, there may be some errors here.MyClass.hCode:#ifdef __cplusplusclass MyClass{public:MyClass();~MyClass();};extern "C" {#endiftypedef void * MyClassHandle;MyClassHandle createClassFromC();void callClassMethodFromC(MyClassHandle handle);void freeClassFromC(MyClassHandle handle);#ifdef __cplusplus}#endifThe "extern "C" {" directive tells the C++ compiler to use non-mangled C compatible function names and calling convention.MyClass.cppCode:#include "MyClass.h"MyClass::MyClass(){}MyClass::~MyClass(){}MyClassHandle createClassFromC(){return (MyClassHandle *)(new MyClass());}void callClassMethodFromC(MyClassHandle handle){((MyClass * )handle)->calledFromC();}void freeClassFromC(MyClassHandle handle){delete (MyClass *)handle;}main.cCode:#include "MyClass.h"int main(int argv, char * argv[]){MyClassHandle handle = createClass();callableFromC(handle);freeClass(handle);}Compiling this is simple, build `cpp` sources with `g++` and `c` sources with `gcc`, but do not link.Code:g++ -c -o MyClass.o MyClass.cppgcc -c -o main.o main.cThen link the final executable using the linker (LD) to create the final executable.Code:ld -o main MyClass.o main.oNext up is automating much of this, on Linux `make` is the defacto standard, but there are alternatives or helpers such as `automake/autoconf`. I personally prefer `CMake`. But lets take a step back and just use `make` to compile the above example:Makefile:Code:CC=gccCXX=g++LD=ldmyApp:$CXX -c -o MyClass.o MyClass.cpp$CC -c o main.o main.c$LD -o myApp MyClass.o main.oall: myAppThis is as simple as you can get but it would require a fair bit of manual work to maintain a larger project. Do some research, there are good guides on how to use `make` effectively. To compile your projects, all you then need to do is run `make` and it would result in building the `myApp` file if it was not already built.There are helpers on Linux for linking, instead of specifying the library directly should rather use the `pkgconfig` tool. For example, to use a library like `libpng` you also need to amend the compiler (gcc/g++) flags with the include path directive, which can change depending on the distro/platform you build on.for example:MakefileCode:CC=gccCXX=g++LD=ldCFLAGS=`pkgconf --cflags libpng`LDFLAGS=`pkgconf --libs libpng`myApp:$CC -c -o main.o $CFLAGS main.c$LD -o myApp main.o $LDFLAGSall: myAppThis would expand to:Code:gcc -c o main.o -I/usr/include/libpng16 main.cld -o myApp main.o -lpng16Learning how all this works is critical to building projects that will build anywhere on anything. For example, the Looking Glass project (https://looking-glass.io) builds two applications, one is for Linux, the other is for Windows and can be either compiled native directly on windows, or cross compiled for windows on Linux, all with no code changes. (It also uses the C++ Dear ImGUI library from C via the cimgui api-wrapperhttps://github.com/cimgui/cimgui, and the C++ only Windows NvFBC capture interface by means of a some helper functions)I hope I was clear here, if there is anything more I can do to answer your questions please feel free to ask me (and tag me or I might miss it).

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 07:55:20 am
content: I am not saying that linux is broken, the world around us is a testament to that. But it often feels like you are on your own. Things are naturally complex but when seeking help I seem to hit the sort of attitude we may treat someone with who persists in being told which side of an incandescent light is the negative or positive. Or maybe a better comparison is the AVR freaks forum assuming it has not changed it's culture. There are people who are just not interested in the simple stuff and just expect you to know it.As I said when I try to look up official documentation it has a prerequisite that I am familiar with the documentation of other features/software, but on checking this documentation I find that either it points me right back where I started as a prerequisite or has a prerequisite for something else. As in my example with the linux interface and the C libraries, both expect knowledge of each other.I guess that this is why the culture of the copy and paste programmer has arisen. I don't like just doing something because a web page tells me. We have an entire product that a now departed colleague designed in this way. As a result any change meant weeks of more copy paste research because he had no clue about how much of what he had done really worked, he would just shrug his shoulders and say I don't know when I asked when trying to help him by just getting him to "rubber duck" the situation.it is this product that I am now in a way trying to gain the skills to replace. I realize that programming takes years to learn properly despite a book on amazon claiming that you can learn python in a week and unlock huge salaries. but I seem to spend a lot of time just trying to make a start with the fundamentals.I prefer to read a decent book, but most of what is produced today is for people with no patience.

author: brucehoult
author_rank: Super Contributor
timestamp: September 16, 2024, 09:01:31 am
content: Quote from: Simon on September 16, 2024, 07:55:20 amThat is not correct.The Linux syscall interface is strictly stand-alone. The calls are described in terms of being called from the C language but NOT using any knowledge of the C standard library.e.g.man 2 writeCode:WRITE(2) Linux Programmer's Manual WRITE(2)NAMEwrite - write to a file descriptorSYNOPSIS#include <unistd.h>ssize_t write(int fd, const void *buf, size_t count);DESCRIPTIONwrite() writes up to count bytes from the buffer starting at buf to the file referred to by thefile descriptor fd.<etc>C library functions build on top of whatever the OS provides e.g.fwrite(), which in this case on Linux iswrite()but on Windows or classic MacOS is something else. But C library functions such asprintf()build on top offwrite()without corresponding in any way to what the OS provides.Again, nothing in the Linux syscall interface ever depends in any way on the C standard library. The calls are described in terms of C, but you can equally well write them directly in assembly language with no library needed. Either way, whether you write in C or assembly language, if you only use Linux syscalls then you don't even link with the C library, you can say-nostdlibto gcc/clang.

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 01:49:32 pm
content: Quote from: Simon on September 16, 2024, 07:55:20 amThis is going to happen to anything that is "not windows". if feels like this because you don't know the correct terms to google and correct way to ask questions and what information to incude in the question.Quote from: Simon on September 16, 2024, 07:55:20 amThis is because people asking question often approach it from the position "this is not how it was in windows, I want things to be like in windows". Same things happens when people move from Altium to KiCad. They often complain that KiCad does not work like Altium without taking tie and effort to understand how things work.

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 05:12:14 pm
content: Quote from: brucehoult on September 16, 2024, 09:01:31 amI've never heard of a syscall interface. So what sorts of things do they do and where am I calling them from? if I write a program it is in "a" language, I can't just type anything into my program.

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 05:27:20 pm
content: Your language needs to have access to the low level instructions. This is hardware dependent. On x86 syscalls are called though the interrupt 0x80, on x64 there is a special instruction called "syscall". The arguments to the called function are passed in the registers. There are many sources for the syscall table, here is onehttps://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/All low level library functions like read() or write() are just simple interfaces for those syscalls. You can do it all manually if you want to or if your language does not already have this list translated into a native to the language form.Here is a basic assembly example that prints "Hello World!" without any libraries -https://www.cs.fsu.edu/~langley/CNT5605/2017-Summer/assembly-example/assembly.html

author: Postal2
author_rank: Frequent Contributor
timestamp: September 16, 2024, 06:26:18 pm
content: Quote from: ataradov on September 16, 2024, 05:27:20 pmWhy assembler, write everything in processor codes. I wrote a floppy disk driver in x86 codes. I keep this paper notebook and can take a photo if anyone doesn't believe me. So give me the Biggest Fool Award.

author: IanB
author_rank: Super Contributor
timestamp: September 16, 2024, 06:31:58 pm
content: Quote from: ataradov on September 16, 2024, 05:27:20 pmIn the very old days, this is what the BIOS provided (Basic Input Output System). These days what the BIOS used to provide is all abstracted away through device drivers, but operating systems still have to provide basic hardware access facilities for user programs to use.

author: nctnico
author_rank: Super Contributor
timestamp: September 16, 2024, 06:34:26 pm
content: Quote from: Simon on September 16, 2024, 07:55:20 amIMHO the truth is somewhere in the middle. Personally I like to start with an example and improve / change it to my liking while looking up the language constructs being used. Along the way you figure out what is good and what is bad about the example and which language constructs would be a better fit. And if the example turns out to be utterly useless, find another example. That way you don't have to start from scratch understanding everything but gradually gaining more knowledge about a programming language while getting results.

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 06:38:06 pm
content: Device drivers are still accessed though the same syscalls. That syscall list is all that Linux can do, there is no way to get more out of it. This includes all the hardware and driver access.

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 06:40:46 pm
content: Quote from: nctnico on September 16, 2024, 06:34:26 pmThis.People like to shit on StackOverflow, yet it is extremely valuable resource. Sure, it includes a lot of garbage, but that garbage is also called out in the comments. So, as long as you are actually reading the discussion, you can extract a lot of value from SO.

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 06:54:00 pm
content: Quote from: Postal2 on September 16, 2024, 06:26:18 pmWe will give you the award without the need for proof.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 16, 2024, 07:05:14 pm
content: If ataradov does write a program in machine code (as I did), he will have to additionally learn to knock on his head with the same empty sound as I can.

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 07:08:15 pm
content: I'm not into dick measuring contests, and the joke about writing things in machine code or scratching them with a needle on a surface of a hard drive ran their course 20+ year ago.The assembly code I linked is not just to show how "cool" you are. This is something you have to do when porting a new language to Linux.

author: Postal2
author_rank: Frequent Contributor
timestamp: September 16, 2024, 07:30:11 pm
content: Quote from: ataradov on September 16, 2024, 07:08:15 pmI didn't have an assembler, so I entered the bytecode into the "hiew" program.

author: ataradov
author_rank: Super Contributor
timestamp: September 16, 2024, 08:09:44 pm
content: Nobody cares. This is a waste of time.

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 08:23:09 pm
content: Quote from: Postal2 on September 16, 2024, 07:30:11 pmWhy don't you create your own sad little thread all by yourself about how great you are, you can even troll yourself in it to your hearts content and leave us to get on with our business!

author: Postal2
author_rank: Frequent Contributor
timestamp: September 16, 2024, 08:37:34 pm
content: Quote from: Simon on September 16, 2024, 08:23:09 pmOK.

author: Simon
author_rank: Unknown
timestamp: September 16, 2024, 08:41:48 pm
content: Quote from: Postal2 on September 16, 2024, 08:37:34 pmThank you very much!

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 17, 2024, 05:58:35 am
content: Simon, what you are experiencing is the exact situation I have mention I've observed: that it is more difficult for a Windows power user to learn Linux (or Mac, or any other OS) than it is for a complete newbie. One has to first "unlearn", or learn to understand that some of their built-in assumptions are not universal and are instead specific to Windows only, before they can "learn the new stuff".I've never said or intended it in any kind of derogatory way, it is just how it is. If Linux was the popular one, it would be the exact other way around. It is the same thing when learning a language when an adult: the first foreign language (not related to your native language) is the hardest, because you have to both learn how to learn a new language, and then learn the new language first. The following ones, even if not related to the languages you already know, are comparably much easier, because you've already learned how to learn a new language.(This does not apply to learning languages as a kid, because kids' brains have a specific language acquisition "mode" that adults don't tend to have; but looking at some language prodigies, their acquisition skills do seem awfully like what kids have, augmented with adult reasoning, logical capabilities, and memory management skills.)Quote from: Simon on September 16, 2024, 05:12:14 pmOthers have already talked about this above, so I should shut up.However, I think I can describe the situation well starting back in the 8086 MS-DOS era, with references to connect to other stuff. Apologies for repeating what has already been said; I just find this era, and how it affected what we have now in Linux, fascinating.Syscall interface is another name for the Application Binary Interface between applications ("userspace") and the OS (kernel part, specifically). We do use the termApplication Binary Interface, or ABIfor any interface between binary/machine code things, but for the specific one between an operating system and its applications, "syscall interface" is the most commonly used name.Intel 8086 and compatibles have a dedicated instruction,intn, for software to trigger an interrupt.nis an 8-bit value, with the smallest 8 or 16 reserved for specific interrupts, and with a couple of related instructions for breakpoints and such. The interrupt table has 256 entries, so most of these were utterly unused – and were perfect for programs to call standardized routines in BIOS. In fact, these interrupts, and the parameters they took in registers, were the DOS syscall interface.My own introduction to these was viaRalf Brown's Interrupt Listin 1988 or 1989. It described all the interrupts available on MS-DOS and IBM compatible 8086/80186/80286/80386 BIOSes, plus many extensions like VESA VBE (which you could use in DOS to get SuperVGA graphics modes).At the same time, in the Unix world, efforts for interoperability standards were heavily underway. POSIX started in 1988. Intel creatediBCSso that the same 80386 binaries could run on different Unix variants. RMS started the GNU project in 1983, founded Free Software Foundation in 1985, and the first release of GCC was in 1987.The late 1980s and early 1990s were the era of theUnix Wars. While BSD was much more popular at universities, many considered System V to be the "proper Unix"; but the USL-vs-BSD lawsuit meant BSD was still replacing the proprietary AT&T parts of it with its own during these times. In the end, System V, especiallySystem V Release 4.0became the basis for interoperability among Unix variants.Thus, when Linus developed Linux, he used theSystem V ABIfor calling conventions, because it had just become the standard among Unix variants by 1991, and the GNU toolchain he used already supported that.I believe theOSDev Wiki System V ABIpage is the easiest collection point for various hardware details of that ABI. On x86-64 aka AMD64 (PDF at gitlab.com), for example, it specifies that pointer and up to 64-bit integer arguments are passed (in order of left to right) inrdi,rsi,rdx,rcx,r8, andr9registers, and any left over on the stack, and thatr11is a scratch register whose value is not saved or retained over a function call (or a syscall). On AMD64, instead ifintn, a dedicatedsyscallinstruction is used for "calling" OS/kernel "functions". (These functions are also called "syscalls". So, it means both the act of calling a function provided by the OS/kernel, and such functions themselves.) Return values are passed inraxand optionally inrdx; that is, two separate integer or pointer values can be returned trivially from any function or syscall when using the System V ABI on AMD64. (In comparison, on the original 8086/80386 System V ABI, all parameters were passed on stack, which was definitely not optimal.)In Linux, the userspace-kernel ABI, the syscall interface, isvery stable. It is the internal kernel structures and function interfaces that they refuse to set in stone, because the kernel is much more flexible for development this way. For out-of-tree driver developers and e.g. kernel Rust developers, this is a huge cause of annoyance. Hell, even the excellentLinux Device Drivers, 3rd Editionbook about Linux device driver development by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman is out a bit wrt. in-kernel interfaces, as it refers to the state of the art for 2.6.10, and right now we're at 6.11.When incompatible changes are done to the syscall interface – for example, a new parameter is added –, the existing versions are kept as-is, and a new syscall allocated for the new purpose. I recommend looking atman 2 syscallsfor a list with links to the C interface description, and the kernel version each syscall was introduced in.It is quite possible to create applications using the syscall interfaces only and not use the standard C library at all. As with embedded development, this then relies on thefreestanding environmentpart of the C standards. For the syscalls, I've written some very trivial syscall wrappers in extended inline assembly for GCC and Clang; the only downside is that they're both OS and architecture-specific. There is much that I personally dislike about the standard C library, but like about the C language, so one of my long-term hobbies is examining what kind of a library replacement for the standard/POSIX C library would work better in practice. With C23 and parameter array/length notation, it might even help programmers avoid buffer overrun bugs.Because of Linux being developed using GNU toolchain and developers preferring the open standards like X/Open and Single Unix Specification (at the Open Group) and POSIX (also2024 edition at the Open Group), it is very natural –– but possibly confusing! –– that many of the syscalls the Linux kernel provides match thePOSIX System Interface functions(but seeIntroductionandGeneral Informationfirst).And this finally ties into theLinux man pagesproject atman7.orgby Michael Kerrisk. He maintains these pages actively participating in the Linux kernel mailing lists, plus collects them from other sources (like the GNU C library).Section 2contains system calls and C functions that are simple wrappers around them, likeopen(),read(),write(), andclose().Section 3contains the rest of the standard C library calls, likefopen(),fread(),fwrite(), andfclose(). (The former are the low-level I/O functions where one must deal with e.g.short countsand interrupts, and the latter are the Standard C I/O functions, implemented by the C library using the former.)Unlike many other man page collections, the Linux man pages list theStandardeach function or syscall wrapper is based on, usually a shortHistorylist of related past standards that implemented the same, plus notes with e.g. any known Linux-specific details. These are reliable; and when bugs or issues are found, Kerrisk is very friendly and appreciates fixes and contributions – I can say that from personal experience.Side note: One of the things that really, really bug me about systems-level C (low-level libraries or services) programming outside Windows, is how few understand and use the POSIX interfaces. A particular annoyance is whenever someone writes code usingopendir(),readdir(),closedir()whennftw(),scandir(), andglob()are not only free for use (baked in to the base C library, no size cost or anything), but are also more robustly written than self-coded tree traversals, and should deal things like file and directory renames and moves during traversal. A second one is arbitrary line length limitation due to the use offgets(), whengetline()andgetdelim()automagically manage a dynamic memory buffer for you.Simply put, there is a TON of extremely useful POSIX C functions baked in to the standard C libraries outside Windows that are underutilized, because MS never implemented them.Anyway, a question at the end:If you already know C, why do you go to C++ for GUI applications, instead of usingGTK?GTK has a pure C interface. Granted, because it is object-oriented as UI toolkits tend to be, it can feel quite odd at first. I recommend creating user interfaces either by hand or usingGlade, and saving the interface as an.uiXML file. In the C code, one uses GtkBuilder to instantiate the objects from the.uifile. There are two separate approaches for attaching the callbacks –– the functions that e.g. clicking on a button causes to be called ––: relying on GModule to automatically match the names to same-named functions in the global scope, or usinggtk_builder_add_callback_symbol()(orgtk_builder_add_callback_symbols()) to explicitly associate names with callback functions.I'm not averse to using dedicated ELF sections to collect callback function name-to-function mappings, but it will not work for native Windows GTK apps.Some dislike GTK, but to me, it is just another option for creating UIs. Gtk and Qt are my go-to ones, but I'm not tied to either one.Note that while GTK is associated with the GNOME project, you don't need GNOME to be able to use GTK. You can easily run GTK apps on any desktop environments, including KDE (which uses Qt), by just installing the support libraries (and none of the desktop applications). The same is true of all the toolkits, really.If you want an example of GTK UI application, just say something simple it should do/have. Because I haven't bothered to upgrade my Mint 20.3 yet, I'm using GTK 3, not GTK 4 yet.

author: Simon
author_rank: Unknown
timestamp: September 17, 2024, 06:46:19 pm
content: I am not one bit familiar with windows. The sum total of what I can do is write low level C for micro controllers. I abhor the HAL rubbish that manufacturers put out.If I understand correctly the syscalls are ultimately what the standard C library interfaces to.I thought it might be time to use C++ for the increased flexibility ultimately I will use what works. What I really lack is all the background stuff or setting up the environment and understanding how everything works. GTK? sure, whatever works, but I seem to just go in circles.

author: ataradov
author_rank: Super Contributor
timestamp: September 17, 2024, 06:58:22 pm
content: Quote from: Simon on September 17, 2024, 06:46:19 pmSyscalls are OS APIs. And since you need your standard library to interact with the OS, it has to use OS APIs for that.The fact that those syscalls look very close in functionality and arguments to the C library is just a side effect of the fact that both were designed and developed concurrently.Quote from: Simon on September 17, 2024, 06:46:19 pmThe best thing you can do is get all the libraries you can think of and build their examples. You will see how much code and effort it takes to achieve the result. Then you can pick whichever you like most and you will also have the starting point, since you already built the example. You can take it and expand it for your needs.

author: Simon
author_rank: Unknown
timestamp: September 17, 2024, 08:03:58 pm
content: Yes i need to play with the fltk example when I get a minute. Then see if anything else is really worth it.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 17, 2024, 08:52:17 pm
content: IMHO C++ is not worth the trouble for embedded dev on MCUs. (Of course, you'll always find die-hards who will swear by it.)If you want to learn C++ for other purposes, fine, why not. But if you're looking to do desktop GUI stuff in C++ mainly to get proficient enough in C++ to reuse that skill for your embedded development, I don't think that's worth your time.Time may be better invested in learning (if you're not comfortable with that yet, sorry if you are) how to install and use toolchains at a low level, with makefiles or Cmake (or whatever build system you like), not relying on complex IDEs and pre-digested environments. That will be much more invaluable in embedded contexts, again IMHO.Just my 2 cents. Have fun with FLTK though.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 17, 2024, 10:11:49 pm
content: Quote from: Simon on September 17, 2024, 06:46:19 pmThey are what all programming languages library functions ultimately interface to. Some, like Python, are written on top of the standard C libraries; some, like Rust, use their own. But yes, these are the only way an userspace process (an application or a service) can interface to things outside.Quote from: Simon on September 17, 2024, 06:46:19 pmI wish I could help, but I basically breathe this stuff nowadays, so cannot really tell what the best approach to get there is. (I've got the same problem with programming guides: that phase was so long ago for me, and so much better stuff is now available, I simply don't have the context to recommend guides and tutorials.)I, too, would recommend Mint over Debian or Ubuntu. And if using Cinnamon Desktop, to install Synaptic package manager; it's a graphical interface to the same package repositories you can access viaapton the command line. When you pick a package to be installed, it will automatically find all the dependencies, and ask whether it is okay to include them in the set. The same interface allows you to uninstall (or purge, removing even configuration files) anything you've installed, but again dependencies may install a lot more than you intended, soalways look at the additional changes; having any packages with-desktopin them means you're trying to delete something that (one of) the desktop environment requires. After you've got a suitable set of changes, click onApply. It will give you a final opportunity to check what will be installed/removed/upgraded, before accepting.Remember: it will not stop you from making your system unusable; it is up to you to be sensible about what you remove.I think you'll get a pretty good base set of packages and libraries useful for C and C++ software development if you installbinutils libc6-dev pkg-config libgtk-3-dev manpages manpages-dev gcc g++ clang make cmake glade libgladeui-dev libfltk1.3 libfltk1.3-dev qt5-default qtbase5-dev qtbase5-dev-tools qtchooser qtcreator qttools5-dev qttools5-dev-tools, but I probably am missing lots and lots.build-essentialis a metapackage that pulls in typical packages needed to build or rebuild Debian packages from sources.In any case, you should use the package manager (like Synaptic) to look for the libraries you need, noting that if you want to compile programs to use said libraries, you typically need both the runtime parts (like sayliblzma5for XZ-format compression) and the development parts (liblzma-devfor aforementioned XZ-format compression library). Just remember that you can only have one package manager application open at the same time. For example, if you have Synaptic running, command-lineaptcommands may fail.If you run Mint etc. in a virtual machine, I recommend you checkpoint the VM before installing or uninstalling stuff. That way, if you make a catastrophic mistake and remove your desktop environment or critical parts like Bash, you can always revert the VM to the checkpoint before any of the changes. It is easy to accidentally slip and click Ok before you meant to, and install or remove things you didn't intend, so the VM checkpoint acts as a safety net; I recommend it.

author: Simon
author_rank: Unknown
timestamp: September 18, 2024, 06:31:32 am
content: Quote from: SiliconWizard on September 17, 2024, 08:52:17 pmI am looking to progress into C++ solely for the GUI stuff. I don't see how going to all the effort of learning a GUI is time well spent only to say great, now I can do C++ on MCU's. I need both C and C++ probably.

author: westfw
author_rank: Super Contributor
timestamp: October 14, 2024, 07:04:55 am
content: BTW, I have a relatively "virgin", if relatively old Ubuntu VM, and here is what I did to get a c++ Hello World running:Code:westfw@ubuntu20:~$ g++ # See if it's there already?Command 'g++' not found, but can be installed with:sudo apt install g++westfw@ubuntu20:~$ sudo apt install g++ # Wasn't there. Take the offered advice! password for westfw:Reading package lists... Done # Wait a bit...Building dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required:libfwupdplugin1 libxmlb1: ## More logging from g++ install...Processing triggers for man-db (2.9.1-1) ...Processing triggers for libc-bin (2.31-0ubuntu9.9) ...westfw@ubuntu20:~$ g++ # Check againcompilation terminated.westfw@ubuntu20:~$westfw@ubuntu20:~$ cat >> hello.cpp # Create the program in the simplest possible way#include <iostream>int main() {std::cout << "Hello World\n";return 0;}westfw@ubuntu20:~$ g++ hello.cpp # Compile itwestfw@ubuntu20:~$ ./a.out # Run the resulting binaryHello Worldwestfw@ubuntu20:~$

author: brucehoult
author_rank: Super Contributor
timestamp: October 14, 2024, 07:35:40 am
content: You can get a 100% virgin Ubuntu any time by typing:Code:docker run -it ubuntuYou'll find that all you need to add to your instructions is to first do "apt update".No "sudo" needed because you're root by default. Of course you do ned to have docker installed -- which you should. Very very handy software. (or an alternative)

author: Karel
author_rank: Super Contributor
timestamp: October 14, 2024, 08:03:04 am
content: Code:docker run -it --entrypoint "/bin/bash" ubuntu:latest

author: westfw
author_rank: Super Contributor
timestamp: October 15, 2024, 10:43:35 pm
content: QuoteI haven't looked at docker. Is having an extra layer of virtualization an issue? I dunno if I have enough RAM (or allocated disk) to allocate my ubuntu VM enough RAM to run another VM...

author: brucehoult
author_rank: Super Contributor
timestamp: October 16, 2024, 12:14:42 am
content: Quote from: westfw on October 15, 2024, 10:43:35 pmAssuming you're using Linux and the docker images you're using are for the same ISA as your computer then it's not a VM it's just essentially managing a chroot.The default x86_64 Ubuntu image is 78 MB. Doingapt update && apt install g++and then committing that container as a new image (eg called "cpp") gives a 405 MB image. It doesn't have any text editor, but it's otherwise enough to write and run C++.Programs you run in the container use host OS RAM exactly the same as any other program.Code:bruce@i9:~$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcpp latest b5fd00408694 11 minutes ago 405MBubuntu latest dc4c1391d370 5 days ago 78.1MBbruce@i9:~$ docker run -it cpproot@30a089efa54f:/# cat >hello.cpp#include <iostream>int main(){std::cout << "Hello!" << std::endl; return 0;}root@30a089efa54f:/# g++ hello.cpp -o helloroot@30a089efa54f:/# ./helloHello!root@30a089efa54f:/#exitYou can copy the program you built in the container into your normal OS and run it there:Code:bruce@i9:~$ docker cp 30a089efa54f:hello .Successfully copied 18.4kB to /home/bruce/.bruce@i9:~$ ./helloHello!bruce@i9:~$Once you have your image with g++ installed in it, containers that you create from it (e.g. 30a089efa54f here) are only the size of the files you added to them, so 30a089efa54f is 16.6 KB in size on disk.Really a very convenient way to keep environments for different OSes or different versions of tools etc separate, with very low overhead in disk space, RAM, and execution time.

author: ejeffrey
author_rank: Super Contributor
timestamp: October 16, 2024, 03:16:54 am
content: Docker containers don't take reserved memory like a virtual machine. The container processes are running in the host kernel, just with a different view of the filesystem and other resources. A basic container doesn't run any daemons or even it's own init process: it's really just the memory image of the program running.They do usually have their own filesystem image which takes space. As Bruce explained that doesn't have to be huge for a simple build environment. That said, depending on how you use it old images can accumulate and need to be cleaned up occasionally.I use docker for running some xilinx tools and cadence tools that need a very particular OS version. It can definitely br a bit awkward at times but it's incredibly useful.