Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, I am a noob.
I compiled a very simple program, using Eclipse.
In the DEBUG folder, it generates the program file: WinProjectTest005
If I double click on it, nothing happens.
OS: Kubuntu 18.04.3 LTS (aka Ubuntu 18.04.3 LTS)
I guess the file manager is Dolphin.
On Windows, when you double click on a EXE file, it would popup a cmd window. In Kubuntu nothing happens.
Here is the boring program:
================================
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout<<"!!!Hello World!!!"<<endl; // prints !!!Hello World!!!
cout<<"Enter a value:\n";
cin>>a;
cout<<"\nEnter a value:\n";
cin>>b;
a+=b;
cout<<"\nThe total is = "<<a<<endl;
Your program doesn't include any graphical interface so it needs a terminal to run in, but KDE hasn't been told that. You can launch such a program from a desktop icon if you create a .desktop file for it specifying that it needs a terminal. I believe some desktops also allow the choice "run in terminal" when you right-click on an executable. Otherwise, you will need to open a terminal and run it from there.
Your program doesn't include any graphical interface so it needs a terminal to run in, but KDE hasn't been told that. You can launch such a program from a desktop icon if you create a .desktop file for it specifying that it needs a terminal. I believe some desktops also allow the choice "run in terminal" when you right-click on an executable. Otherwise, you will need to open a terminal and run it from there.
So if I write a program with a GUI, I could double click it and it would display itself?
Does anybody have a simple Linux GUI program I could test?
I downloaded Eclipse and QT which came with QT Creator so far.
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
Quote:
Originally Posted by vmelkon
So if I write a program with a GUI, I could double click it and it would display itself?
Does anybody have a simple Linux GUI program I could test?
I downloaded Eclipse and QT which came with QT Creator so far.
Yes for your first question.
But I'm not sure I understand exactly what you mean by your second question though.
Following on from what Hazel was saying above about running a program in a terminal via KDE; if you right click the shortcut for your program and select "Properties", then in the "Application" tab click on "Advanced Options", you should see an option called "Run in terminal" - if you want to do it via the graphical interface rather then manually editing the .desktop file for your program.
But I'm not sure I understand exactly what you mean by your second question though.
Following on from what Hazel was saying above about running a program in a terminal via KDE; if you right click the shortcut for your program and select "Properties", then in the "Application" tab click on "Advanced Options", you should see an option called "Run in terminal" - if you want to do it via the graphical interface rather then manually editing the .desktop file for your program.
For the second question, I am asking, is there a small program/project that opens a window with maybe a button and a menu? Better yet, is there a site that teaches GUI programming (C++)?
I don't have a shortcut to my program. I have the program file. The EXE or whatever you want to call it. Let's say the name is MyProgram.
I'm not sure what you mean by .desktop file.
I have a Windows background, so things are different. A program file needs to end with a .EXE. If it does not have that, forget it, Windows won't run it. We just write our little project with C++ and compile it with whatever compiler we have, we just double click the icon and Windows runs it.
So, Linux (and the BSDs) do not care about file extensions at all, they care about file content. To run your original executable, just open a terminal in the directory where the executable resides and run ./nameofyourexecutable. If you get a "permission denied", the executable bit needs to be set on the file by running
Code:
chmod +x <your executable name>
Perhaps someone else can help with the graphical application as I am not a programmer.
Last edited by sevendogsbsd; 01-14-2020 at 12:42 PM.
You shouldn't need to use chmod. All locally compiled programs should already have the execute bit set. Just open a terminal and run it.
But to create a program with a GUI, you would need to learn how to use a widget library to provide you with things like windows, buttons and menus. For a KDE desktop, this would be qt. As this is Linux, not Windows, all such libraries have detailed online manuals. If you understand basic C, you can learn how to add widgets to your program.
I'd suggest using a different environment for this, especially beginner programming like this, where you only have one file to worry about.
Here, try this:
Create a directory (aka 'folder') for all of your learning projects inside your home directory.
Make a directory for this current project inside there.
Fire up a simple text editor.
Paste, or rewrite the code in there.
Save the document as main.cpp
Open a terminal emulator, like xterm, or press Ctrl+Alt+T to open one with shortcuts.
cd ~/my_programming_projects/my_current_project
g++ main.cpp
./a.out
That should run your command line program just fine, you won't even need the last "cin>>a;"
cd means change directory (that's why it's good to think of folders as directories)
g++ is the command line 'interface' to the gnu C++ compiler, and, without any additional options other than the filename(s), it will compile the sources into an executable called "a.out", which ./a.out runs.
If you get any errors or warnings, then you will also get the line numbers and all that alongside it, so you can change those in your text editor there.
Now, I'm not saying that this is not a pain in the neck, to an extent, but this will work even when huge titanic things like Eclipse fail on you.
(And why many text editors can do this from within them, because it IS annoying to go back and forth)
Because this is an Eclipse configuration problem, you need to tell it to open your program with a terminal emulator, and from what I remember Eclipse is frustrating to work with for these things.
Linux has many other options, including the simple text editors that have your back on it.
In fact, I'd consider Linux (with the tools installed) an IDE in itself. You can even set up 'inotify' events (don't worry about that right now though) to watch a certain directory for changes and then run an operation on it, like, saving a source code file and then compiling that automagically.
So, while I realize I'm not very helpful with your problem specifically, and that is bad form, ultimately you can do a lot better than Eclipse, and I'm not talking just out of my behind either.
I used to use Eclipse and Visual studio and I while it was easy enough to use in both cases for simple stuff ( although at this point it's been probably a decade or longer so I forgot the options for these) when I wanted custom build steps, like back in the days having external compilers to compile 3d shaders, for example I just couldn't take their needless hoops any longer ,that xml like build script stuff from microsoft and blafjlkjdlfsd, no thanks.
Nowadays all I use is vim with some plugins, even for 'big boy' projects like opentoonz and other such calibers.
(P.S.: excuse the usage of big boy, it's just for illustration purposes :P it does't even scratch nightmare projects that have roots in the pre cambrian era and have been maintained since then)
I'd suggest using a different environment for this, especially beginner programming like this, where you only have one file to worry about.
Here, try this:
Create a directory (aka 'folder') for all of your learning projects inside your home directory.
Make a directory for this current project inside there.
Fire up a simple text editor.
Paste, or rewrite the code in there.
Save the document as main.cpp
Open a terminal emulator, like xterm, or press Ctrl+Alt+T to open one with shortcuts.
cd ~/my_programming_projects/my_current_project
g++ main.cpp
./a.out
That should run your command line program just fine, you won't even need the last "cin>>a;"
cd means change directory (that's why it's good to think of folders as directories)
g++ is the command line 'interface' to the gnu C++ compiler, and, without any additional options other than the filename(s), it will compile the sources into an executable called "a.out", which ./a.out runs.
If you get any errors or warnings, then you will also get the line numbers and all that alongside it, so you can change those in your text editor there.
Now, I'm not saying that this is not a pain in the neck, to an extent, but this will work even when huge titanic things like Eclipse fail on you.
(And why many text editors can do this from within them, because it IS annoying to go back and forth)
Because this is an Eclipse configuration problem, you need to tell it to open your program with a terminal emulator, and from what I remember Eclipse is frustrating to work with for these things.
Linux has many other options, including the simple text editors that have your back on it.
In fact, I'd consider Linux (with the tools installed) an IDE in itself. You can even set up 'inotify' events (don't worry about that right now though) to watch a certain directory for changes and then run an operation on it, like, saving a source code file and then compiling that automagically.
So, while I realize I'm not very helpful with your problem specifically, and that is bad form, ultimately you can do a lot better than Eclipse, and I'm not talking just out of my behind either.
I used to use Eclipse and Visual studio and I while it was easy enough to use in both cases for simple stuff ( although at this point it's been probably a decade or longer so I forgot the options for these) when I wanted custom build steps, like back in the days having external compilers to compile 3d shaders, for example I just couldn't take their needless hoops any longer ,that xml like build script stuff from microsoft and blafjlkjdlfsd, no thanks.
Nowadays all I use is vim with some plugins, even for 'big boy' projects like opentoonz and other such calibers.
(P.S.: excuse the usage of big boy, it's just for illustration purposes :P it does't even scratch nightmare projects that have roots in the pre cambrian era and have been maintained since then)
Eclipse is actually working fine for that tiny C/C++ program. It can run it and the bottom area of Eclipse acts line the command line.
I just wanted to run the program outside of Eclipse.
Since I come from a Windows background, I have used Borland C++ and Visual C++ for a long time. Debugging is easy in these apps.
So, I prefer to use a IDE.
I don't want to develop in Visual C++ on Windows, and as a last step, just port to Linux and hit compile.
So, from what I understand, I can make a GUI program and just double click and it should work. I am releaved to hear that.
I'm not sure how you guys are working on opentoonz without an IDE.
vim is very primitive but if it satisfies, go for it.
Vim is anything but primitive - I don't use it but the folks I know who can positively FLY using vim. Vim hooks into whatever language you want and has autocompletion, etc. Just gotta know how to use it.
@sevendogsbsd
opentoonz is just a large and somewhat crusty project (an animation package used by companies like Ghibli to make some of their anime movies, it was used for Futurama, etc) but it works fine with just vim.
I used it as an example that vim is usable for anything, including big projects, big boy was a bit flippant, lol, and ultimately confusing I guess. It's just large, not super duper 'stereotypical enterprise' large, but still big.
@vmelkon
I consider vim the most powerful and 'ergonomic' text editor in existence, I cannot think of anything that matches its usability and 'speed' (and I don't mean speed in processor like terms, but the amount of changes you can introduce to a chunk of text in relation to the effort of invoking the commands/steps to do so).
IDE merely means "integrated development environment", it's not at all different to running a compiler, version control system, build system or whatever from within vim.
In "IDE"s it's merely done for you in the way the makers of the IDE find it best, hence all the different ways to configure them to do the same task.
(Granted, that's also the case for vim, but IDEs are just so huge and bumbling...)
In Eclipse if you hit "run" then internally that just invokes all the tools required to start the build chain, populating various windows with information, updating the IDE text editor with new information, and running the program, hopefully.
IDE just means "a buncha components in one window", whereas my approach is "a buncha components in one or more windows", the result is entirely the same.
As for launching the program in Kubuntu itself by double clicking it, well that requires some configuration I can't remember (but it might be in the "confirmations" "general" options)
Alternatively, you can also right click the file, Actions -> Run with Konsole.
Edit:
Not going to make a new post for this, but I should have addressed you both separately, my bad!
If you want to write programs in an editor, try geany. It's a kind of halfway house between an IDE and a simple editor. Like vim, it has syntax checking. It has tabs for individual files if you are using more than one. It autocompletes function names. It lets you fold up blocks of code that you are not interested in so that you can intensively study the bits that are causing trouble. I like vim but I would never use anything but geany for a programming job.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.