Eclipse: add a run configuration in a makefile project - c++

I have an Eclipse project that builds a library, with my own build script (that basically sets some variables, then calls a Makefile). I have set the Build Configuration to run this script, everything is OK: I can compile by just clicking on the Build button.
Now, I would like to test some parts of this lib. In the same project, I have created a C++ source file, with a little main(). I would like to create a run configuration to execute this small test program, but Eclipse tells me that "the binary does not exist" (of course, since I want to build it...).
What is the solution ?

Related

Eclipse GDB can't find source files

My workspaces are located in my home directory.
I am currently trying to debug python code which loads a shared C++ library, using Eclipse Oxygen and PyDev. I can debug the Python files just fine.
I run the program (pytest unit test if that matters) with a breakpoint somewhere in the test before the shared library is called (but after it is loaded) and then run a C/C++ Attach to Application debug and attach to the paused python thread. I then set a breakpoint in my C++ code and resume python, and get this from the GDB console output:
No source file named /home/myname/.../models/sourcefile.cpp
Doing an ls /home/myname/.../models clearly shows that that file exists.
I'm not sure if this matters but my library was compiled with CMake where the source and build directory are siblings. E.g. workspace is ~/dev and source is in ~/dev/sourceFolder and build files are in ~/dev/buildFolder
Update:
I was able to attach to the running Python debug thread manually in the console using gdb python <thread_number>. This works and finds my source files just fine, allowing me to debug manually in the console. It would still be much faster and less cumbersome if I were able to get it to work in Eclipse.
Things I've tried in the C++ debug config settings:
In preferences, changing C/C++ -> Debug -> Source Lookup to have
absolute file path first, profile first, and relative file path
first
In CppDebug settings debugger tab, manually added build and source directory to shared libraries
In CppDebug settings source tab, manually added source directory in source lookup path
None of these seemed to do much.
For cmake projects:
The launch configuration can default to the wrong executable, so go to launch configuration => main and check the "C/C++ Application"
Change it from this: build/default/
to this: build/cmake.debug.linux.x86_64/
(you can do this with the "Search Project" button.
This will then pick up the correct debug version and all your source will be found when you debug.

How to properly specify external make script for existing project with makefile in eclipse c++ ide?

I am using Eclipse for C++ Luna. I have created a project in eclipse using New->Makefile Project with Existing Code. Then I set up targets for this project and they build fine without any changes. Now, instead of running make, I need to run a script that takes the same arguments as make. So I went to project properties and changed C/C++ Build->Builder Settings to use a specific build command: /home/mydir/mycode/mymake.sh. I also set Build Directory to /home/mydir/mycode/.
So when I click on target1, in the Eclipse console I see:
10:08:48 **** Build of configuration Default for project mycode ****
/home/mydir/mycode/mymake.sh target1
10:08:48 Build Finished (took 60ms)
So Eclipse can find the script, but in fact the script was not executed (I did check). Could you point me to what I need to do for script to execute from Eclipse? thanks.

Eclipse won't change output type in C++

I started an Eclipse project as an executable. It worked correctly. Then I changed it to a DLL in Project Properties -> C/C++ Build -> Settings -> Build Artifact -> Artifact Type. It still worked. (this was all with basically Hello World functionality)
So I included a bunch of stuff in my project file to actually move toward the app I want to build. I couldn't get it to quite compile, but I've included a lot of paths and libraries that I don't want to have to re-enter (or I'd just start a new project). Just to find out if I could still compile Hello World with all these includes, I changed it back to an executable in the same spot as above. It seems to work, in that it changes it on that screen; and it even changes the file extension that it feeds to the /OUT parameter of the linker. But it's still passing the /DLL parameter to the linker, as well, and I can't find the project property page where I can remove this.
Note that, when I copy-paste the command line that the Eclipse console spits out, to the command prompt and remove the /DLL parameter manually, it links properly and forms an executable that produces the correct functionality. But when I try to run the exe from the IDE, or whenever it tries to rebuild, it gives me a message box error saying my process has encountered a problem.
Error starting process.
Cannot run program "C:\Users\2659\workspace\MoreStuff\Debug\MoreStuff.exe": Launching failed
Cannot run program "C:\Users\2659\workspace\MoreStuff\Debug\MoreStuff.exe": Launching failed
Cannot run program "C:\Users\2659\workspace\MoreStuff\Debug\MoreStuff.exe": Launching failed
How can I remove this /DLL flag so that I can have actual control over what my project is outputting?
I just had a similar problem: I created a new C++ project with shared artifact nature and wanted to test it by adding a main function and a new executable build option.
In order to successfully change the nature you have also to go to Project Properties -> C/C++ Build -> Settings -> G++ Linker -> Shared Library Settings and (in the proper configuration) uncheck the Shared option.
It worked for me.

How to compile and run a C++ program from Eclipse?

I am trying to write, compile and execute a "HelloWorld" C++ program using Eclipse. I have managed to install and run Eclipse, create a new project and write the HelloWorld program. Now I would like to compile it and to run.
I did not find "Compile" option in Eclipse, but I found "Build Project" option in the "Project" menu. I assume that Build is what I call "compilation". After I clicked this options, Eclipse generated "Debug" folder, containing "src" sub-folder as well as 3 files: "sources.mk", "objects.mk" and "makefile". First, I do not know what these files mean (and which of them is my "executable"). Second, I still need to execute my program. I tried to click "Run" option in the "Run" menu. As a result I got an error message: "Launch failed. Binary not found".
Can anybody, please, help me to compile and run my code using Eclipse.
Eclipse being an IDE is meant to create projects not restricted to just one file as a result multiple files exists which have to be linked and compiled so as to work in sync as per the methods implemented in the project.To run the project or a particular program a binary of that particular project is required which gets created only if the build is successful .So a successful build is must for binary creation which in turn is responsible for running the project or program.
So first build the project using Ctrl+B after succesfull build then run the project.
This simple question was asked nine years ago, so I don't know if it is still active. Anyway, one thing not mentioned in the responses so far that might be helpful to others is that Eclipse requires a "Run Configuration" to run programs. From the original post, if the "Build Project" command returned successfully, then the "Debug" folder should also contain a file called "HelloWorld" at the same folder level as "makefile" and "objects.mk". That is your executable. To run it, go to Run -> Run Configurations, which should produce a popup containing a field called "C/C++ Application". Click the "Browse" button, find, and select the "HelloWorld" executable in the "Debug" folder. Click "Run" in the lower right and you should see your output.

Eclipse CDT build/run on file basis

In my scenario I have a C++ project in CDT Eclipse. This projects however is rather a collection of individual (helper) programs than one complex application. Consequently I want to be able to build and run them individually.
My project structure is very simple and looks like:
src/app1.cpp
src/app2.cpp
src/...
Note that I do not have common header files or libraries. However I want to be able to add programs to this project just by creating e.g. src/appx.cpp
Ideally I want to have shortcuts for
"Build currently opened .cpp"
"Run binary of currently opened .cpp"
Any suggestions on how to achieve this behaviour, if possible without additional plugins?
The straightforward way to succeed what you aim is to create a Makefile project with CDT and add a new target rule for each of your applications inside your Makefile. You can even use SCons or other build systems with a CDT Makefile project and obtain the same effect.
You can also trick the managed build to create executables instead of object files. Remove -c option from Other flags of C++ compiler settings inside project properties. This will produce a separate application file for each of your source files.
Application files which are created inside the build directory will have the object file extension and they will not be executable. To solve this, you can add a post build script in your project directory such as:
postbuild.sh for Linux:
chmod +x *.o
rename -v 's/\.o$//' *.o
or postbuild.bat for Windows:
rename *.o *.exe
After adding ../postbuild.sh or ../postbuild.bat as a post build command in your build settings, you applications will be ready to run. Right click on any of these executable files and choose Debug As or Run As and a new Run configuration will be created.
Also you will have to stop the linker of the managed build to prevent errors. This can be achieved with changing the linker command to true (Linux) or true.exe (Windows, msys).