Running Ubuntu Eclipse C++ Helloworld - c++

I'm trying to run a Hello world C++ on Eclipse on Ubuntu 12.04. I installed g++ and wrote this code:
#include<vector>
#include<string>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Compile output:
**** Build of configuration Debug for project TopCoder ****
make all
make: Nothing to be done for `all'.
**** Build Finished ****
Run output message:
Launching TopCoder has encountered a problem
Error starting process
Error starting process.
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
when I put the source code on ext4 drive it builds and run
I changed
proc /proc proc nodev,noexec,nosuid 0 0
in /etc/fstab to
proc /proc proc dev,exec,suid 0 0
But no usefulness.

You're tring to run an application from the /media/01CCE00FA6888D80 volume. Removable USB? The most likely culprit is noexec as an option to the default mount command line.
check if noexec is part of the options for mounting the filesystem using:
grep noexec /proc/mounts
if this results in output indicating that noexec is in effect for the file system then try:
sudo mount -o remount,exec /media/01CCE00FA6888D80
Also, if the removable volume is NTFS, your milage may vary.

Try to build it from the command line. Then you will know if the problem is involved with g++ or with eclipse. I guess you should change your compiler path somewhere in the eclipse, are you sure you have eclipse-cdt? THe easiest way to compile it is:
g++ yourfile.cpp

Your problem is that you're workspace is probably on a different drive than the one you installed ubuntu on

You are running you project over Linux . i had facing same issue when my project was in my E drive . i gave read -write permission but still that was not enough for me . The same error was keep coming when i was trying to run the project .
I have shifted my project in my Home folder ,gave permission and the project ran !! .
I believe there was a problem with some permission for LINUX C compiler .

Related

Script for Notepad++ NppExec for C++ in ubuntu

I just switched to ubuntu and I wanted to setup notepad++ for CPP.
So I used the NppExec plugin to compile within notepad++,
My script was :
npp_save
g++ "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART)obj"
./"$(NAME_PART)obj"
Here the "obj" I used is to just save the file with an "obj" keyword nothing else.
The last line ./"$(NAME_PART)obj" is to run the program.
But it looks not working in ubuntu, it produces this error:
NPP_SAVE: Z:\home\username\cpp\test.cpp
g++ "Z:\home\username\cpp\test.cpp" -o "Z:\home\username\cpp\testobj"
; about to start a child process: "g++ "Z:\home\username\cpp\test.cpp" -o "Z:\home\username\cpp\testobj"
CreatProcess() failed with error code 2:
File not found.
./"testobj"
; about to start a child process: "./"testobj""
CreatProcess() failed with error code 2:
File not found.
I have investigated some of what I think is the problem, so I think is the usage of / and \ in changing the directory.
I don't know how to fix that, so I can not be sure.
Any ideas? :) I am using vim btw in the same machine and it is working perfectly.
In theory it might be possible (see below), in practice it is rather convoluted and works only for simple compiles (like single file hello world type).
I would suggest you try a linux program, e.g.
an editor like
scite (same editing engine as notepad++) or
kate
or a real IDE like
kdeveloper or
qtcreator.
The problems with Notepad++ inside wine and g++ outside wine (from the linux install ) are this:
notepad++ inside wine under linux is still a windows program
NppExec can only do, what a cmd inside wine can do.
starting g++ directly inside cmd is an error due to g++ being a linux binary and not a windows binary
that is your CreatProcess() failed with error code 2, it means: you are trying to execute a linux program inside wine.
That does not work! (At least not so easy.)
Though you can start linux program inside cmd inside wine using start /unix ...
started this way, g++ wants linux paths and NppExec through its variables will provide only windows paths (whatever wine has set up as drives like Z:\home\username\src\hello.cpp)
though you can convert wine paths to linux paths via the winepath -u command.
g++ started through 'start /unix ... ' inside a cmd inside wine has no proper terminal to report errors to you
though you can start an xterm for g++ and have g++ reports its messages to the xterm
the downside is that g++ will report errors using the linux paths in the xterm, so you cannot double click on an error message an get to the corresponding filename and line.
You get the idea: its complicated not comfortable.
What worked for me for a helloword.cpp was this NppExec script:
NPP_SAVE
npp_run cmd /c start /unix /usr/bin/xterm -e "/usr/bin/winepath -u '$(FULL_CURRENT_PATH)' | xargs g++ -o /tmp/a.out && /tmp/a.out ; echo 'Press return'; read"
The second line
uses an xterm,
let winepath convert the Z:\home\... path to /home/... and
have that send to g++ for compilation using /tmp/a.out as binary
if compile is successfull, /tmp/a.out is executed
the echo and read are for keeping the xterm open so that you can read the output.
If you really want to use Notepad++ inside wine, one option might be using Gnu Make outside of wine and have NppExec run make all or make run similar to the g++ in my script example. That would work for more complicated compiles.

C++ Mingw32 CreateProcess() failed with error code 2: The system cannot find the file specified

I am just trying to run a basic program in notepad++ and mingw32. I have attempted multiple different thing but I continue to get.
Current directory: \\THEBOX\Users\jacks_000\Documents
C:\MinGW\mingw32\bin\g++.exe -g "testpgrm"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
================ READY ================
When I run the nppexec I use the following
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\mingw32\bin\g++.exe -g "$(FILE_NAME)"
I have also tried:
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW\bin\g++.exe -g "$(FILE_NAME)"
I am just using a basic test program:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hi";
return 0;
}
I don't know if I will have issue running it in the command prompt if I save it this way or if I have done something wrong. I am running Windows 10 if that is a issue.
Current directory: \THEBOX\Users\jacks_000\Documents
I think it's because g++ can't access to a SMB share.
Try to compile the file locally.
The problem is with the location of "C:\MinGW\mingw32\bin\g++.exe". Where it is on your PC, and what is the actual filename, will depend on your installation.
For example, on my machine I have and old version in "C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe", but a newer installation in another folder.
So you need to find the executable name and location of the compiler. You won't need to use the top two lines, just "C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe -g test.c", for example.
I did this and it gave a result of :
C:\Program Files (x86)\CodeBlocks13_02\MinGW\bin\mingw32-g++.exe -g test.c
Process started >>>
<<< Process finished. (Exit code 0)
================ READY ================

"Operation not permitted" running hello world binary compiled w/ clang++ on El Capitan

Background
I created a simple Hello World C++ program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
And compiled it with clang++ like so (g++ points to clang++ on OS X apparently):
g++ helloworld-cpp.cpp
This produces an executable, a.out. Running it at the prompt causes bash to throw the error Operation not permitted, as shown:
$ ./a.out
-bash: ./a.out: Operation not permitted
Things I've Tried
Verifying the file has execute permissions, and no attributes or flags that would prevent it from running, using ls -leO:
-rwxr-xr-x 1 monarch staff - 15212 Jan 1 13:51 a.out
Disabling "System Integrity Protection" using csrutil disable from the Recovery OS terminal, rebooting, recompiling, and running a.out. The same error messages results.
Question
Are there any other restrictions that could prevent binaries I compile on Mac OS X from running?
Figured it out.
My code was on an encrypted sparseimage, which had the quarantined attribute set on it. I checked this by running mount like so (see attributes on /Volumes/work):
$ mount
/dev/disk0s2 on / (hfs, local, journaled)
/dev/disk2s2 on /Volumes/work (hfs, local, nodev, nosuid, journaled, noowners, quarantine, mounted by monarch)
The actual sparseimage is located in my home folder, titled work.sparseimage. I removed the quarantine attribute like so:
$ xattr -d com.apple.quarantine work_personal.sparseimage
I then unmounted (ejected) the image, then re-mounted it, recompiled the file and it executed without the error.
Special thanks to #Mark Setchell for asking me in the question's comments if noexec was set on the drive, and to everyone else for their suggestions.

wxWidgets-2.9.4\include and \lib\gcc_lib\mswu No such file or directory error on CodeBlocks

I'm trying to learn C++ programming with wxWidgets and CodeBlocks (with MinGW) and earlier today I succeeded in installing the software (after some trouble) to my Windows 7 computer with the guidance given to me in this post:
wxWidget 2.8.12 not working in Codeblocks
Later on the same day, I did the exact same steps on another Windows 7 machine and after creating a wxWidgets project and trying to compile and run it I got the following errors:
\wxWidgets-2.9.4\include: No such file or directory
\wxWidgets-2.9.4\lib\gcc_lib\mswu: No such file or directory
I have checked and these folders really do exist on those locations...so what seems to be the problem here again?...on the earlier post user asanth kumar guided me that if the steps given in the guide don't get the job done, then I'm missing an important compiler search path in my build options.
Ok, so what do I do? Where do I enter the search path? What is the search path, etc. I'm very new with wxWidgets and CodeBlocks so I don't know very much terminology. If anyone should know what to do, could you please give me like step by step instruction what to do e.g. like Click Project --> Build options --> ... and so on
I have used the latest CodeBlocks (12.11) and wxWidgets (2.9.4) installers
Thank you for any help :)
UPDATE:
here is the build log: (I'm using CodeBlocks 12.11 and wxWidgets 2.9.4)
-------------- Build: Debug in TEST (compiler: GNU GCC Compiler)---------------
windres.exe -I"C:\Users\Jonne\Omat ohjelmat\wxWidgets-2.9.4\include" -I"C:\Users\Jonne\Omat ohjelmat\wxWidgets-2.9.4\lib\gcc_lib\mswu" -J rc -O coff -i C:\Users\Jonne\DOCUME~1\CODEBL~1\TEST\resource.rc -o obj\Debug\resource.res
gcc: error: ohjelmat\wxWidgets-2.9.4\include: No such file or directory
gcc: error: ohjelmat\wxWidgets-2.9.4\lib\gcc_lib\mswu: No such file or directory
windres.exe: preprocessing failed.
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings (0 minutes, 0 seconds)
Here is also a picture where you can see Build options, global variables and build log on my CodeBlocks:
NOTICE FUTURE READERS: Install wxWidgets to a directory without whitespace in the path name. The problems in this post was because the directory path had spaces in it
When you create a wxWidgets project.Have you did this?
File->New->Project->wxWidgets Project->Click Go->Click on Next->click on the suitable wxWidgets 2...version->click Next->Give project Name->Click on Next->Click on Next
After that the Following below Screen comes in the Wizard. Give the wxWidgets Location(Path where You installed the wxWidgets 2.9.4)
After that click on Finish.
For Environment Variable Path Setting
Follow the Below Steps:
Right click on MyComputer->Click on Advanced Systems settings->click on Environment Variables->click on New->Give variable name=Path and variable value="C:\Program Files (x86)\CodeBlocks\MinGW\bin" -> click ok
`
Try The Following Steps.It will work.
Updates about Build settings:
I am having the same problem as this and I somehow solved my problem.
I transfer my wxWidget folder to another location path that don't have white space name on it's path. For example above, "C:\Users\Jonne*Omat ohjelmat*\wxWidgets-2.9.4\include"
the path has white space between Omat ohjelmat. Try transfering it where the path contains no white spaces. For me, I put it on C:\wxWidgets-3.1.2

What needs to be done to get a distributable program from Eclipse?

I’ve produced a C++ program in Eclipse running on Redhat, which compiles and runs fine through Eclipse.
I thought that to run it separately to Eclipse you use the build artifact which is in the directory set via the project’s properties.
However this executable doesn’t run (I know it’s an executable as I’ve set it to be an executable via the project’s properties and it shows up as such via the ls command and the file explorer).
When attempting to run it using the executable’s name, I get the error:
bash: <filename>: command not found
When attempting to run it as a bash file:
<filename>: <filename>: cannot execute binary file
And when running it with "./" before the file name, nothing happens. Nothing new appears in the running processes and the terminal just goes to the next line as though I’d just pressed enter with no command.
Any help?
You've more or less figure out the first error yourself. when you just run <filename> , it is not in your PATH environment variable, so you get "command not found". You have to give a full or relative path when to the program in order to run it, even if you're in the same directory as the program - you run it with ./<filename>
When you do run your program, it appears to just exit as soon as you start it - we can't help much with that without knowing what the program does or see some code.
You can do some debugging, e.g. after the program just exits run echo $? to see if it exited with a particular exit value, or run your program using the strace tool to see what it does (or do it the usual way, insert printf debugging, or debug it with gdb)