Author Topic: hello world for linux in C++  (Read 28792 times)

0 Members and 13 Guests are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18889
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: hello world for linux in C++
« Reply #50 on: September 13, 2024, 02:09:30 pm »
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #51 on: September 13, 2024, 02:16:53 pm »
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.
« Last Edit: September 13, 2024, 02:19:28 pm by ataradov »
Alex
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6415
  • Country: nz
Re: hello world for linux in C++
« Reply #52 on: September 13, 2024, 02:48:03 pm »
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: [Select]
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello world!");
    [pool drain];
    return 0;
}

Code: [Select]
$ sudo apt install -y gobjc gnustep-devel
$ gcc hello.m -o hello `gnustep-config --objc-flags` `gnustep-config --base-libs`
$  ./hello
2024-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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #53 on: September 13, 2024, 02:52:00 pm »
Of course it uses Objective-C for the GUI stuff
Which 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.
Alex
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6415
  • Country: nz
Re: hello world for linux in C++
« Reply #54 on: September 13, 2024, 03:05:03 pm »
Of course it uses Objective-C for the GUI stuff
Which 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.

Basically 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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #55 on: September 13, 2024, 03:07:41 pm »
Basically 100% of apps on MacOS and iOS use it
I 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.
Alex
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6415
  • Country: nz
Re: hello world for linux in C++
« Reply #56 on: September 13, 2024, 03:49:30 pm »
As soon as you don't have to use it on other platforms, you instantly drop it.

I 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: [Select]
// 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];
}

@end

int 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!

 

Online Jeroen3

  • Super Contributor
  • ***
  • Posts: 4564
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: hello world for linux in C++
« Reply #57 on: September 13, 2024, 03:52:36 pm »
Basically I'd like to develop with visual studio on windows and be able to run the results on Linux.
...
C# using .NET (not framework) is supposed to be cross platform. Microsoft is obsoleting everything windows-only in it, and it's super annoying  :P.
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 found Textual, 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)
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #58 on: September 13, 2024, 03:58:59 pm »
Easy peasy!
I'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.
Alex
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 6415
  • Country: nz
Re: hello world for linux in C++
« Reply #59 on: September 13, 2024, 04:30:31 pm »
Easy peasy!
I'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.

Or, 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.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18889
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: hello world for linux in C++
« Reply #60 on: September 13, 2024, 06:22:50 pm »
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #61 on: September 13, 2024, 07:03:07 pm »
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.
« Last Edit: September 13, 2024, 07:06:16 pm by ataradov »
Alex
 

Offline Postal2

  • Frequent Contributor
  • **
  • !
  • Posts: 826
  • Country: 00
Re: hello world for linux in C++
« Reply #62 on: September 13, 2024, 07:04:48 pm »
... the next challenge is to add the FLTK libraries. ...
ImGui 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.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17781
  • Country: fr
Re: hello world for linux in C++
« Reply #63 on: September 13, 2024, 09:02:00 pm »
Yea I am confused.

If 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.

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.

FLTK 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).
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18889
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: hello world for linux in C++
« Reply #64 on: September 13, 2024, 09:49:15 pm »
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.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30153
  • Country: nl
    • NCT Developments
Re: hello world for linux in C++
« Reply #65 on: September 13, 2024, 10:37:02 pm »
For this wxWidgets may be better, since it tries to use native controls for the OS.
I 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.
« Last Edit: September 13, 2024, 10:54:26 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5734
  • Country: Earth
Re: hello world for linux in C++
« Reply #66 on: September 14, 2024, 01:11:51 am »
I found FLTK mentioned in the C++ book by stroustrp which I take as a decent endorsement.

here 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.
« Last Edit: September 14, 2024, 01:34:12 am by radiolistener »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #67 on: September 14, 2024, 01:43:47 am »
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. 
« Last Edit: September 14, 2024, 01:48:25 am by ataradov »
Alex
 

Offline Postal2

  • Frequent Contributor
  • **
  • !
  • Posts: 826
  • Country: 00
Re: hello world for linux in C++
« Reply #68 on: September 14, 2024, 01:59:04 am »
... 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. ....
Please explain how to create such a program that manages to eat up resources by outputting static data once to the buffer?
Quote
Dear ImGui is a bloat-free graphical user interface library for C++. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline-enabled application.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12464
  • Country: us
    • Personal site
Re: hello world for linux in C++
« Reply #69 on: September 14, 2024, 02:09:04 am »
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.
Alex
 

Offline Postal2

  • Frequent Contributor
  • **
  • !
  • Posts: 826
  • Country: 00
Re: hello world for linux in C++
« Reply #70 on: September 14, 2024, 02:27:51 am »
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.
This 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.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5734
  • Country: Earth
Re: hello world for linux in C++
« Reply #71 on: September 14, 2024, 03:54:25 am »
This means very little. FLTK is stable and does not need a lot work, so there is no particular reason to fork it.

However, 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...  :)

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.

Just 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.

You have to render the whole UI every frame. It is objectively less optimal than an application that only renders on events.

Yes, 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.
« Last Edit: September 14, 2024, 04:37:42 am by radiolistener »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 18889
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: hello world for linux in C++
« Reply #72 on: September 14, 2024, 06:49:28 am »
There is also LVGL, I don't know where square line studio got to as changes have been afoot.
 

Offline Postal2

  • Frequent Contributor
  • **
  • !
  • Posts: 826
  • Country: 00
Re: hello world for linux in C++
« Reply #73 on: September 14, 2024, 03:48:13 pm »
... 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. ...
The 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.
 

Offline djsb

  • Super Contributor
  • ***
  • Posts: 1121
  • Country: gb
Re: hello world for linux in C++
« Reply #74 on: September 14, 2024, 06:14:24 pm »
If you want to give WxWidgets a try, I would recommend these tutorials as a taster

https://www.youtube.com/playlist?list=PLFk1_lkqT8MbVOcwEppCPfjGOGhLvcf9G

The 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.
David
Hertfordshire, UK
University Electronics Technician, London, PIC16/18, CCS PCM C, Arduino UNO, NANO,ESP32, KiCad V10+, Altium Designer 21.4.1, Alibre Design Expert 28 & FreeCAD beginner. LPKF S103,S62 PCB router Operator, Electronics instructor. Credited KiCad French to English translator.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf