How to execute a CLion program in gnome terminal? - c++

This question already has an answer here but I am using CLion version 1.2.1 and the answer in that post doesn't help. It is possible to run a CLion program in gnome terminal instead of its own console ? If yes, how ? Thanks.
EDIT : I know where the executable file are stored but want to know if it is possible to run the file in terminal directly from the ide i.e. by selecting the run option in ide.

Yes, you can execute a Clion c/c++ program in a gnome terminal from the IDE. Here is how:
In the top right of your clion application you should see your project name or "Build All". Click on that and go to "edit configurations"
there click on the plus sign(top left) and then on "Application"
Now go to "Executable:" and click on "select others". There you should go to where your gnome-terminal is stored (mine is at "/usr/bin/gnome-terminal" on ubuntu)
Next go to "Program arguments:" and type -e ./myProjectName (For newer versions of gnome-terminal -e is deprecated, use -- ./myProjectName)
go to "Working Directory:" and type in the location to your cmake-build-debug folder found in your project folder
You can now press okay and go to the top right to select the name of your application that you created in step 2
This will run your program in the gnome terminal.
Hope this helped :)

Related

Running CLion on the System console (like Visual Studio)

I am trying to run a simple C++ program on CLion. The problem is that when I try to compile and run it, it shows the result in the application console. I want to run on the System console like the Visual Studio runs the output of the console apps. Is there a way of doing this. I use MINGW compiler.
You can use an external terminal, do these steps.
(top menu) run\ edit Configurations
tick 'run in external console'
Well, if anyone is still around wanting to open an external cmd window on run, there is a way to do it on Windows as well:
Go to Run > Edit Configurations
For the executable select C:\Windows\System32\cmd.exe
For program arguments use: /c "start cmd.exe #cmd /k "ProjectName.exe""
For working directory set the cmake debug (or release) folder
Save and select the profile from the dropdown right next to the run button
Note: In the third step /k can be replaced with /c to make the window close after the program is run (with /c its more like visual studio and with /k its more like code blocks)
I am not sure about Windows but in linux you can do it using this answer.
You might be able to change the gnome-terminal to cmd if you are using windows but you will probably need to change the "Program Arguments" too.
the above answer works fine in windows also. In working directory you can set this $CMakeCurrentBuildDir$
enter image description here

NetBeans 7.0.1 good C++ program execution "RUN FAILED"

Working inside NetBeans 7.0.1, fresh install on Ubuntu 13.10.
I have a known good C++ program.
I finally get it to compile and link.
When I press the Netbeans Run Main Project triangle, the execution breaks with
java.util.MissingResourceException: bin/nativeexecution/Linux-x86/pty
RUN FAILED
What's going on, and how to fix it?
This is a NetBeans output-window setting problem.
NetBeans comes up with C++ projects defaulting to "Internal Terminal". This is not working on your present configuration.
The answer is to switch your output to "External Terminal", which pops up a separate purple terminal typing console in its own window for your interaction, or "Standard Output",which presents the output in the expected white subpane below.
Do this by:
Right-mouse-click on your project name -> Properties
on the left side, in the "Categories:" column, select * Run
on the right side, beside the >General -> Console Type:,
change the pulldown menu from "Internal Menu" into "Standard Output".
Hit the OK button at the bottom to lock it in.
Now your project will run, forever after, when you ask it to.
according to this netbeans forum post package of netbeans 7.0.1 is lacking some files.
Removing version from repo and installing from netbeans download site worked like a charm for me and nb forum OP.
So problem is also in ubuntu 14.04.
Also repo version is little out-of-date and NB have nice .sh installer. Just remember to install some JDK from repo or anywhere else.

Qt - Qt Command Prompt

So I found an excellent video where it teaches me about static compile. But in there it doesn't show where he got the "Qt Command Prompt" from. I searched alot but didn't find it in the directory. What do I do? Can anybody tell me where it's located? I even searched for it in Explorer but didn't find it.
Just add the following paths:
<qtdir>\mingw\bin;
<qtdir>\Desktop\Qt\<qtver>\mingw\bin;
<qtdir>Madde\bin\
to your %PATH% environment variable, and the default command prompt (cmd.exe) will become what you need. Don't forget to restart an already opened cmd.exe after editing %PATH%.
What OS do you use?
For exanple, here you can find how to edit %PATH% on win7.
The Qt command prompt is simply a normal cmd.exe session where the paths to the Qt libraries and binaries have been added to the environment.
It depends on how you installed Qt (using the SDK, build from source, etc.). If you used the SDK, a shortcut should have been installed in your Start menu. My Qt command prompt is at:
C:\Qt\4.8.2\bin\qtvars.bat vsvars
That being said, I rarely use the Qt command prompt. If you use the normal Visual Studio command prompt, then navigate to your Qt "bin" folder, you should be able to execute the command you need, like configure.
If you are using Windows 8, just type "Qt 5.4 for Desktop" after pressing the windows button.
Actually in windows 8 just typing "qt" in start menu, will give you the suggestion.

C++ program written in Eclipse using Windows and MinGW cannot display output to console view

I'm using Windows 7 64bit.
I installed eclipse version 3.6.2, cdt, and MinGW. I have a C++ console program in Eclipse as follows:
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
setbuf(stdout, NULL);
for (int i = 0; i < 10000000; i++) {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
}
int val;
cin >> val;
return 0;
}
If I run this console program, it should display Hello world to Console View in Eclipse, but nothing displays.
If I go to the debug folder and run the exe, it does print to the console.
If I make some syntax mistake, then the Eclipse Console View will show something, such as:
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hh.o ..\src\hh.cpp
..\src\hh.cpp: In function 'int main()':
..\src\hh.cpp:17:3: error: expected ';' before 'return'
Build error occurred, build is stopped
Time consumed: 255 ms.
Why is nothing showing in the Eclipse console view and how can I make my C++ console program display output?
I found a workaround from this site:
http://www.eclipse.org/forums/index.php?=42e862594001fa4469bbc834885d545f&t=msg&th=197552
At that link, look at the reply from "No real Name".
In case the link goes down, here is the content:
Environment: jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit
No console output at "Run", but output correctly at "Debug".
The following method worked for me:
1. Goto Project->Properties->Run/Debug Settings, choose the .exe file
and press "Edit"
2. In the "Environment" tag, press "New", set it as:
"Name:PATH"
"Value:C:\MinGW\bin"
In fact, I have already set "C:\MinGW\bin" in windows PATH environment
variable, but it seemed to not work.
The problem is that your program uses dll libraries from MinGW - try to start the exe file manually, it will report some error about missing dlls.
Solution can be, that you copy required dlls to .exe file in your project directory (and Release or Debug subdirectory, depends on what .exe are you executing with Run command).
Or, in menu Run -> Run Configuration select the configuration which you use for that .exe file (or create a new C/C++ Application configuration) and select Environment tab in the right panel. There add new variable named PATH with value c:\MinGW\bin (this is default path to mingw\bin directory, use a path valid for your instalation if it's somewhere else)
Edit: Now I'm looking at post by Vikyboss and it's in fact the same - setting the PATH variable in Run configuration. Setting PATH variable in Preferences > C/C++ (Expand it) > Environment as described by Sydraps didn't work for me.
But I think that static linking that libraries may be the best solution for you. In menu Project -> Properties select C/C++ Build -> Settings. In the right panel select Configuration which you want to change (you may select All). In the tab Tool Settings select MinGW C++ Linker -> Miscellaneous and in the right panel in the Linker flags type -static. Now the .exe will be bloated by the size of the libraries (in my case approx. +900kB for Hello world example, requiring 2 dlls), but it will be independent at any libraries.
I hope this will be helpful for anyone trying to start with Eclipse C/C++ and wondering why there's no Hello world in console.
Ales Chlubny
I fixed the problem on my windows 7 x64 PC. In the Eclipse window go to Preferences > C/C++ (Expand it) > Environment > Add:
"Name:PATH"
"Value:C:\MinGW\bin"
If this does not fix it. Try adding the above to the system environment variables on your PC in Computer > Advanced System settings
I find the reason, just because I'm using 64bit eclipse!
I turn to 32 bit eclipse, the same code works fine.
My problem with displaying hello world(64 bit Windows7) in console was solved when I ran eclipse as administrator.
I added the C:\MinGW\bin to environment variable path and then started eclipse as administrator
I created a Hello World C++ Project (MinGW GCC) app from the Eclipse wizard, cut and pasted your code and it compiled fine. Then prior to running I reduced your loop to 10 and it ran fine.
You don't say how you created your project but it would appear likely your missing some include directive or library path. Also I don't see the need to include or setbuf(stdout, NULL). I also find it helpful when troubleshooting to NOT bring an entire namespace into scope. Rather do this:
using std::cout;
using std::cin;
Finally, flushing the buffer each time with << endl; seems like overkill, adding a simple \n to the end of the string would be more efficient.
(I did all this on Win 7 64 bit - but I was using a 32 bit version of Eclipse Galileo)
If you are using MinGW compiler,
Add -static-libgcc -static-libstdc++ as Linker flags for your new
project. This text should be added to the Linker flags field, which
can be found by right-clicking on the new Project in the Project
Explorer and clicking on Properties. Under the Project Properties,
expand the C/C++ Build menu and click on Settings. Under the Tool
Settings tab, expand the MinGW C++ Linker menu and click on
Miscellaneous. Add the text to the Linker flags field, then click the
Apply button.
http://orfe.princeton.edu/help/article-296
For me installing the 32 bit versions of Eclipse (Indigo 3.7) and the 32 bit Java JDK/JRE did not work. I use the much quicker solution from the Eclipse CDT/User/FAQ:
Quote from Eclipse CDT/User/FAQ - Eclipse console does not show output on Windows:
Eclipse console does not show output on Windows In Eclipse CDT on
Windows, standard output of the program being run or debugged is fully
buffered, because it is not connected to a Windwos console, but to a
pipe. See bug 173732 for more details. Either add fflush calls after
every printf or add the following lines in the start of the main
function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
I had an issue with my eclipse-cdt, new C++ project > hello world (cygwin gcc), right click on exe file, run as and nothing was showing on console. It was the same with c project.
I saw that my eclipse version was already a 32bits one.
I figured this out and here is (the) my solution:
There are several compilation profiles in eclipse cdt: release and debug. The default profile in eclipse cdt is debug. So, launching exe using "run as" does not work, you should launch it using "debug as". In my case, I was using a really recent cygwin installation with gcc installed, but with gdb not yet installed. I had to install gdb package in cygwin using cygwin-setup. I reran the exe using "debug as" and it worked.
I guess using release profile instead of default debug profile, rebuilding also works, and I guess that it's the same with mingw environment.
Just added the C:\MinGW\bin to environment variable 'Path' in Windows 7 64-bit.
Now Console outputs messages
I encountered a similar problem.
Environment:
jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit
No console output at "Run", but output correctly at "Debug".
The following method worked for me:
Go to Project > Properties > Run/Debug Settings
Choose the .exe file and press "Edit"
In the "Environment" tag, press "New", set it as:
"Name:PATH"
"Value:C:\MinGW\bin"
In fact, I have already set "C:\MinGW\bin" as the Windows PATH environment variable, but it seemed to not work.
Works for me by going Administator on Eclipse Kepler 64bit.
In case someone is interested, I found how to fix it forever on Windows XP (may work in other windows version though) without you having to specify the variables of each executable and such:
Start Menu > RightClick on MyComputer > Properties > Advanced Options > Environment Variables
There, in the "User variables" field,
If there's an environment variable called PATH, select Modify and add this information in the end of the Value field, separated by semicolon:
C:\MinGW\bin
Example:
C:\SomeDirectory; C:\Another; C:\MinGW\bin
If the environment variable PATH does not exist, add a new one with this information:
Name: PATH
Value: C:\MinGW\bin
Accept all and you should get console output :)

Launch Failed. Binary not found. CDT on Eclipse Helios

I'm using Eclipse Helios on Ubuntu 10.04, and I'm trying to install CDT plugin on it. I download it from here here.
And then I go to Install New Software and select the zip file (I don't extract it, just select the zip file). And its ok, it installs, everything works fine, it shows optional features, blah blah blah.
And then I create a new HelloWorld project. And when I try to run it, it shows an error and says:
Launch failed. Binary not found.
Can anyone explain me how to fix it?
Thanks.
You must build an executable file before you can run it. So if you don't “BUILD” your file, then it will not be able to link and load that object file, and hence it does not have the required binary numbers to execute.
So basically right click on the Project -> Build Project -> Run As Local C/C++ Application should do the trick
First you need to make sure that the project has been built. You can build a project with the hammer icon in the toolbar. You can choose to build either a Debug or Release version. If you cannot build the project then the problem is that you either don't have a compiler installed or that the IDE does not find the compiler.
To see if you have a compiler installed in a Mac you can run the following command from the command line:
g++ --version
If you have it already installed (it gets installed when you install the XCode tools) you can see its location running:
which g++
If you were able to build the project but you still get the "binary not found" message then the issue might be that a default launch configuration is not being created for the project. In that case do this:
Right click project > Run As > Run Configurations... >
Then create a new configuration under the "C/C++ Application" section > Enter the full path to the executable file (the file that was created in the build step and that will exist in either the Debug or Release folder). Your launch configuration should look like this:
Go to the Run->Run Configuration-> now
Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case projectTitle+Debug).
Under this in main Tab -> C/C++ application -> Search your project -> in binaries select your binary titled by your project....
You must "build" before "run", otherwise "Binary not found". You can set up "Auto build", so that it will build and run. Check this post to set up "Auto build" http://situee.blogspot.com/2012/08/how-to-set-eclipse-cdt-auto-build.html
I had this problem for a long while and I couldn't figure out the answer. I had added all the paths, built everything and pretty much followed what everyone on here had suggested, but no luck.
Finally I read the comments and saw that there were some compilation errors that were aborting the procedure before the binaries and exe file was generated.
Bottom line: Do a code review and make sure that there are no errors in your code because sometimes eclipse will not always catch everything.
If you can run a basic hello world but not your code then obviously something is wrong with your code. I learned the hard way.
If you still have an error even after building the project then try to do this:
click on Binaries in Project Explorer with the left button
click on green "Play" button (Run Debug)
I was having this same problem and found the solution in the anwser to another question:
https://stackoverflow.com/a/1951132/425749
Basically, installing CDT does not install a compiler, and Eclipse's error messages are not explicit about this.
I faced the same problem. I have Eclipse Indigo and Eclipse Luna on Ubuntu. I tried many solutions, but none worked. Here's how you can try :)
Try it in order :)
Either do Build All and then compile :)
Install G++ Compiler
Windows->Preferences->NEW CDT PRoject-> Makefile-> Binary Parsers-> Choose Cywin or Window PE depending on your Os :)
Change your toolchain to cywin gcc
Project->Properties->Environment-> Release Active
After 1,2, 3, and 4, I tried changing paths, and other stuff, but nothing worked. In the end, I noticed that it mentioned Debug Active was not configured. So when I changed it to Release Active, it worked. Do note that change in environment and path is not required.
I faced the same problem while installing Eclipse for c/c++ applications .I downloaded Mingw GCC ,put its bin folder in your path ,used it in toolchains while making new C++ project in Eclipse and build which solved my problem.
Referred to this video
Seems like having "Build Automatically" under the Project menu ought to take care of all of this. It does for Java.
make sure you have GDB installed on your system...
If your using Linux based OS simply in a terminal type:
sudo apt-get install gdt
when finished downloading extract the file and install.
close your IDE (in this case eclipse and open it again and run your project.
Adding the compiler to the PATH fixed the problem for me...
export PATH="$HOME/opt/cross/bin:$PATH"
My problem was the same as one commenter above. I had to change the binary parser to the correct one (PE for windows, ELF for Linux, mach for mac)