Running the C++ app from the Eclipse IDE - c++

I am using eclipse IDE. I have here some basic source code including header file. Have been using cygwin as C++ compiler. It compiles my app and it does not produce any error. But I cannot see the output on IDE's console. When I run the executable file on its own it produces output. How to configure Eclipse IDE in order to redirect output to the IDE's console?
This is all I get:
15:40:11 **** Incremental Build of configuration Debug for project GetCompiled ****
make all
Building target: GetCompiled.exe
Invoking: Cygwin C++ Linker
g++ -o "GetCompiled.exe" ./Compiling.o
cygwin warning:
MS-DOS style path detected: D:\Aristotelis\C++\GetCompiled\Debug
Preferred POSIX equivalent is: /cygdrive/d/Aristotelis/C++/GetCompiled/Debug
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building target: GetCompiled.exe
15:40:12 Build Finished (took 702ms)
Selected app to run:
I tried to run the exe file from the IDE by selecting to run as an C++ app, but it does not produce any output.
Best regards

Eclipse/CDT does not automatically run your application after each build. You need to either go trough the menu Run->Open Run->Run or use the keyboard shortcut Crtl+F11, and then check the Console window again.
An advanced feature is to set your application as a post-build event. For that, go to your Build Settings and find the appropriate submenu and type the name of your application.exe there (haven't got Eclipse at my fingertips right now). With this setting, the application will be launched automatically after each successful build. This comes in handy if you do automated unit testing.

Related

Qt Creator remote debugging

I have an application that I run on an Embedded Linux device.
In Eclipse, I can run remote debugging using the eclipse-cdt-launch-remote plugin where I point a binary to run, and where to put it on the device with some environment variables to be exported before running the application.
The application is a C++ application with a custom Makefile for building the application as an ELF file.
The application is deployed on the device via SSH, using login with user and password. And then, I can debug from Eclipse using stepping and so on.
(I am also using the MentorGraphics crosscompiler for arm-none-linux-gnueabi-2014.05)
My question is: How do I mimic the same functionality in Qt Creator since I like coding with Qt Creator more than coding with Eclipse?
I know that an easy fix would be to code in Qt Creator, and then debug using Eclipse, but I really want to debug using Qt Creator.
Edit: Solved it by hours of testing and reading up on the Qt Creator
IDE.
Imported my project that was an Makefile project.
Then I went in to Options under Tools and added my Device that used SSH.
After that I added a debugger, I used gdb-multiarch since the one provided in the prebuilt toolchain binary did not support python.
Then I added my custom toolchain pointing the compiler path to the toolchains binary g++. And set the ABI to
arm-linux-generic-elf-32bit. Although I dont actually see the
compiler settings being used during debug.
I created a new kit using my Device, Debugger, and Compiler. And set device type to Generic Linux Device. Pointing to my sysroot that
I extracted when using buildroot for the filesystem. These were the
only options I set in the kit.
Closed the options menu, and went into Projects where I added my new kit
Changed the build settings and set the build directory and build steps for the application.
Changed the run settings to use some custom commands, like moving the newly built .elf application to target. And then I set where the
local executable was and where the remote executable was. The remote
executable is the one I moved to the target using custom command from
host.
Voila! I could now run remote debugging on my target from Qt Creator.
Qt Creator has built-in support for automatic deploy on remote devices.
On the Embedded Linux device:
Create a login password for the root user
Install the openssh-server and gdb-server packages
On Qt Creator:
Enter Tools > Options > Devices and create a new device specifying address (i.e. IP and port numbers) and credentials (i.e. root and password). Further information available here.
Enter Tools > Options > Build & Run > Compilers and add the gcc cross-compiler path (further information available here)
Enter Tools > Options > Build & Run > Debuggers and add the gdb cross-debugger path (further information available here)
As the last step, finally enter Tools > Options > Build & Run > Kits and link compiler, debugger and device into a single Kit, also specifying the sysroot (i.e. local copy of the embedded Linux root filesystem).
Set the build target to Debug.
In the Qt project, check that all deploy steps are selected (e.g. transfer file to the remote device) and add any needed argument (e.g. -qws for touchscreen on Qt 4.x)
In general, have a look at the guide here.

Via Windows command line, how can we compile a Netbeans C/C++ application?

Let's take this simple C/C++ application Netbeans project folder.
In Netbeans IDE, we just hit build button on the toolbar to build the application.
I want to do that automatically via Windows command line, how can I do that?
I did google, and found some related posts though not very helpful for me except telling me to call ant dist - though I don't have the build.xml in my Netbeans 8 project.
p.s. I have hundreds of student submissions and need to verify which one is compilable.
I also post on Netbeans forum here.
I want to do that automatically via Windows command line, how can I do that?
NetBeans uses Makefile-based projects as default for C/C++ projects, so you can use make to build your project:
cd <Project dir>
make
It's also possible to build other make-targets (eg. make all or make test (builds / runs tests)).
Note: The Cygwin bin dir (CYGWIN_HOME\bin) must be in system PATH - same applies to other environments (MinGW, Gcc etc).

OS X Eclipse C++ Launch Failed - Binary Not Found

I am quite troubled as this shouldn't be causing me such a headache. I've downloaded the most recent Eclipse Indigo and all CDT C++ plugins for MAC OS X 10.7.1/
Upon restarting after installing the above CDT plugins, I've developed a simple 'hello world' c++ application and have tried running the application, "Launch failed. Binary not found." error message. I've read multiple fixes but none have worked. I tried adding the -arch i386 flag to the linker and compiler commands, still no luck.
Has anyone successfully gotten Eclipse C++ running on 10.7.1?????? This blows my mind. I can simply write the same program in VIM and compile it just fine via the terminal and execute just fine. ECLIPSE DOESN'T WANT TO PLAY ALONG.
I will be deeply indebted to anyone who can help!!!!!
EDIT: compiler output
**** Build of configuration Debug for project HelloWorld ****
make all Building file: ../main.cpp
Invoking: GCC C++ Compiler g++ -I/Developer/SDKs/MacOSX10.6.sdk/usr/include -O0 -g3 -Wall -c -fmessage-length=0 -arch i386 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: libHelloWorld
Invoking: MacOS X C++ Linker g++ -arch i386 -dynamiclib -o "libHelloWorld" ./main.o
Finished building target: libHelloWorld
**** Build Finished ****
I am using Eclipse Juno with CDT on a 2007 Macbook running Snow Leopard. I have the two symptoms:
No Binaries folder in Project Explorer, and
The 'Launch failed. Binary not found' error.
I have spent hours searching on Google for an answer, long enough to ascertain that these two symptoms are indicative of any number of problems which have been reported for not quite a decade without adequate resolution. That is a problem right there because after a decade there should have been more than enough input data to provide one troubleshooting procedure somewhere which walks the user step by step through the elimination of all possible causes.
Instead, for hours I have read about a multitude of people, many of whom have resolved their particular problem but all of them seeming to have had to do something slightly different to get there.
This should not be that difficult to resolve. Particularly in cases such as mine [but I am not the only one] when the Console view displays a Build with no errors yet the user can copy the binary file [which Eclipse bizarrely says it can not find] to the Desktop and run it without any problems from either Finder or a bash terminal session.
All of this seems to be pointing rather emphatically toward the lack of adequate indicators in the Mach0 64 binary parser which should be designed to tell us exactly what it needs which it is not seeing.
Admittedly, this is exacerbated in the case of MacBooks like mine which are running a 64bit OS [Snow Leopard] on a 64bit CPU which the manufacturer, unfortunately, hamstrung with a 32-bit bootup kernel. But, be forewarned, I have already tried the -arch i386 g++ switch, and the relinking of g++ to g++-4.0 without any change in the symptoms.
ADDENDUM ADDED 10/07/2012:
I am adding this checklist in the hope of clarifying a Way for the undoubtedly many others who will ask this question in the years to come. This Way reflects what I found to be necessary when using Eclipse Juno with a Mac running Snow Leopard:
1) Go to Preferences->C/C++->New CDT Project Wizard, and under Preferred Toolchains, make sure all the Executable project types are set to MacOSX GCC.
2) This is a biggie. I was able to get a Binaries folder in Project Explorer, and hence be able to run the project after building it, by using a Project name which does not contain dots ['.']. This I learned from another answer here, edited a few hours after my previous message. This requirement is easy to miss, hence a common one particularly if you are Eclipse experienced but only with other languages, because tutorials for other language plugins [such as with PyDev or for Java] frequently have you create Projects with dots in the name. If you have developed that habit with other languages, break it when using CDT for C/C++. Be forewarned, however, that it is not enough to just do a Right-Click and Rename an existing project name this time not using dots. The simplest Way is to delete your old project and create a new one with a name without dots.
3) There are many websites cautioning you to make sure you either use the -arch i386 compiler switch or change the links for /usr/bin/gcc and /usr/bin/g++ to point to gcc-4.0 and g++-4.0 instead of gcc-4.2 and g++-4.2. I created a bash script to ease switching back and forth and investigated if this was necessary. It was not, at least not with my Macbook. Based on what I read at one site from a Mach-O developer, I suspect that the current version of Mach-0 64 goes both ways. Which is a good segue to ...
4) In the Project Properties, not Preferences, go to C/C++ Build->Settings and under Binary Parsers make sure Mach-O 64 Parser is checked. Make sure this, and not the deprecated Mach-O parser, is checked.
5) At this point, after you build your project, several things should be evident in the Project Explorer:
6) There should now be a Binaries folder under project's folder.
7) Within that Binaries folder should now be your executable file. It should have [x86_64/le] next to it if, like me, your Mac is effectively 32bit. Now is not the best time to get into the confusing topic of whether your Mac is effectively 32bit or 64bit. If you do not know, and a lot folks don't because Apple does make it confusing, check out the little app which can be downloaded from http://www.ahatfullofsky.comuv.com/English/Programs/SMS/SMS.html which will tell you What Is Truth. It is free, but the 'price' is that you have to scroll pass the ads at the top of the page reflecting the programmer's political disposition.
For those of you that are new to programming/eclipse/IDEs and get the same error but the solutions above don't work, I solved my "Launch Failed. Binary Not Found." error by doing the following: Simply be sure to build your project ("Project" > "Build All") before attempting to run or debug. I was thinking that the IDE would do the building when I clicked debug or run, but that is not the case (obviously, in retrospect). Newbie lesson learned. Once you build you should see a "Binaries" and "Debug" folder under the root directory of the project.
I was using OS X 10.7.3, if it matters, though I assume the mistake I made is fundamental and any eclipse distro would give the same error.
on mac:
Make sure you have xcode installed. Test it by writing "info g++" you must see proper information about the compiler.
Build your project.
Go to the folder of your project. You should see an executable file in Debug or realise folder, depending to your building configurations. If you d-click on the executable file you should see the result on the terminal.
Back to Ecliipse, from Run/Run Configurations... and then browse to the folder that you have the executable file - one you already found - you can also change build configurations as you wish in that window. And make build automatic for each run.
Run again it should work.
Good luck !
I had the same problem, then I found a solution on this site.
Let me explain shortly;
Create your c++ project,
Have a look at project properties(⌘I),
Select Mach-O parser under binary properties,
Write your codes down,
Do not forget building your project (⌘B) before run.
You should change the settings for your project to build an executable instead of a dynamic library:
Invoking: MacOS X C++ Linker g++ -arch i386 -dynamiclib -o "libHelloWorld" ./main.o`
Go to project properties -> C/C++ Build -> Settings -> Build artifact, and select Executable in the first drop down list.
I am using Eclipse Oxygen and the following fixed my problem:
Right-click on your project and go to properties. Navigate to C/C++ Build > Tool Chain Editor and select MacOSX GCC in the Current toolchain, and Apply and Close.
Build your project with CMD+B and then run it.
I was having the same problem. The answer can be hard to find as the "binary not found" issue has cropped up several times before, with different causes and solutions (selecting the 64-bit parser, etc.).
It turns out that, in my case, the fix was simple: you have to do a manual build, just once, for every new project you create. After that, works as usual.
Details: using a fresh fresh install of Eclipse Indigo Service Release 1 on Mac OS 10.7.2.
If your project name contains a "." (dot), the binary file will not be generated on building project.
Remove all the "."(dots) from the project name and rebuilt it or try creating a new project.
Happy coding!
If you can successfully built but when try to run it getting error:
Possible solution could be adding new configuration with full path to your binary output file
(Run->Run Configuration...->Main->C++ Application):
I solved a similar problem with Eclipse by creating a "Launch Configuration". I am using the Indigo release of Eclipse on OSX Lion with CDT (C/C++ dev environment). I found the option to create a new launch configuration in Project->Properties->Run/Debug Settings.
I encountered this problem after creating and building an empty "Hello World Ansi C Autotools Project". The build process created a working executable as src/a.out. I could run a.out successfully from the terminal but Eclipse did not understand that this was an executable for my project until I created a launch configuration pointing to it. Once I did that I was able to run a.out as usual using the green run button.
I had the same problem, even when i had set the artifact to executable. It was because the shared lib setting was ticked and this causes a dylib to be made even though you have specified an executable.
I go this to run by setting the Builder Type to Internal Builder on the C/C++ Build tab, in the project properties dialog.
No matter which approach to take to solve this issue on your workspace, this problem seemed to have become native to the project that I had created. Neither using the arguments or making sure the gcc version for linking did not work. I did find an intuitive solution. Here it is:to the "...binary not available..." error.
Do the following:(remember the following steps are after you have taken either of the above routes and none of those have solved the issue.
1.) delete everything - the project and the files.
2.) create new project and source files
I had the similar issue but code was different. In File.h file make sure
virtual ~Destructor () {}; //Don't forget Curly braces {}
Above statement shows destructor initialized () and defined with curly braces { } . In my code I forgot to define Destructor.
Hope this helps
I was having the same problem, so I fiddled around a littpe bit and found out that if I clicked on the "profile" button (green play icon with a little clock under it), to the right of the "run" button, my program would Run the next time I clicked on the Run button.
I actually dont know what that did, but it allowed me to run the code.
if anybody knows why this helped, and whether it is an actual solution or not dont hesitate to relpy!

Eclipse Project Run problem

I tried to create a C++ project in Eclipse Helios, it works fine for some simple "Hello World" projects (a single file etc..). However, now I have a little bigger project with several files, the project can still be built without any problems. Actually, when I get into the release folder, the makefile, object files, the actual binary executable are all there. And I could run the binary through the termainl. If I click the "Run/Debug" in Eclipse for this project, it always says "Launch Failed. Binary not found".
How could run the program in Eclipse? I would like to explore its debug features. In addition, I'm running eclipse in CentOS linux and I believe the basic g++, gdb setting etc.. should be all right, otherwise the daemon hello world won't work.
Warning: I have a very old version of eclipse and the CDT so the current procedure could have changed considerably.
In the C/C++ Project view, expand your project then expand the Binaries node. In there you should have a list of the built executables. Right-click on it and select the item Run As.. > Local C/C++ Application. This should automatically create a new run configuration which you can access from the green arrow icon and the little bug icon in your tool bar. Click on these to run normally or to run in debug mode.
If you want to tweak how programs are launched, goto to the Run configuration menu item of the green arrow icon. Select the configuration that you previously created or make a new one. You can then tweak the various launch settings like the executable to run, the arguments you want to pass, the required environment variables, etc.
Note that there's also a separate Debug configuration that can be accessed from the little bug icon in your toolbar. Within that dialog there's a Debugger tab which contains all the controls necessary to set up your debugger. Just randomly screw around with the controls until you find something that works for you.
I just had the same error, and here is what I did - proper binary parser must be selected so Eclipse can recognize the executable:
Select the project, then right click.
Project->Properties->C/C++ Build->Settings->Binary Parsers, PE Windows Parser
(or you can select Cygwin parser if you use Cygwin compiler, on Linux I use Elf parser).
That worked for me at least for Cross compiler (both on Windows 7 and Ubuntu 12.04)

How to correctly configure netbeans 6.7 and c++ on windows?

I have installed and configured NetBeans 6.7 for c++ according to the official manual:
http://www.netbeans.org/community/releases/67/cpp-setup-instructions.html#mingw
Configuration window looks like this:
Unfortunately, at 'compile' command following line is displayed:
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
BUILD SUCCESSFUL (total time: 642ms)
Since i'm on windows and it's no /usr/bin/make, no executable is compiled :(. How to correctly configure NetBeans so it will use make from it's config, not from /usr/bin?
Updated
Problem is only with mingw/msys toolchain. It works OK with cygwin (same /usr/bin/make message is displayed, but executable IS created). So the question can be changed to: Can Netbeans 6.7 work with mingw on Windows, or i'm limited to cygwin?
I had problems getting Netbeans 6.7.1/C++/MinGW working too. I don't know if this will help but I thought I'd describe my experience anyway.
I was having successful builds but Netbeans was unable to launch my executable. I was able to verify that the executable was being built and I could run it from an external command prompt. I was also unable to open the properties on my project.
After a day of searching the net, I found a tidbit of info that lead to the solution.
Basically, it all boiled down to not having the path to my build tools set in the windows environment path. After I set the path environment variable, I cleared all the Netbeans configuration so I could be sure about setting things up from scratch. You can do this by deleting the .netbeans folder in your user directory in c:/Documents and Settings.
That should all be done with Netbeans closed of course. Afterwards, start it up and setup your build configuration before you create any projects or load existing projects. Go to Tools/Options/C++ and point it at the build tools directory you added to your environment path (c:/MinGW/bin and c:/msys/1.0/bin) and the individual tools as required.
I have my msys stuff in the same directory as the MinGW stuff. As an extra precaution, you may want to make sure there are no same named programs in both bin directories that may cause grief.
I seem to have a C++ development environment now that I'm quite pleased with as I can use it in Windows and Linux. Hope something in there helps.
Can you check on the "project options" on your picture and look if the default platform is windows ?
Have installed netbeans on both linux and windows machines and it's strange that it didn't work "straight out of the box" after following the instructions..
You did double check everything right? As it seems that path variable isn't setup correctly in your environment.
The picture also says that the debugger is missing/invalid.. Did you follow these 16 steps (step 14 for installing debugger) or did you use something else?
Last but not least, your "error" message says that the build was successful. Where did you look for the .exe ? It should be under
dist/<Configuration>/<ToolChain>/