Configure Eclipse to build & run different applications - c++

I've got my project separated into folders. Two of this folders are src and tests.
src contains main.cpp and its own makefile
tests contains tests.cpp and its own makefile
Up until now, I only compiled and ran tests.cpp, but now I need to be able to compile main.cpp and run it, as a separate program. How do I achieve this?

1.Please refer this link to create, manage and run configuration for C++ programs.
2. To manage the property of the program refer this link
3. To make target refer this link.
You can define configuration in your eclipse and run them separately.
Go to Run-> Run Configuration and declare your own configuration depending on nature of the applicaiton. The image below specified how to create a new configuration for Java program. You can do the same for c++ program as well.
Once you have that dialog box. You need to do right click to create a new configuration.

You can do so by adding a target for each file that you want to compile and then add them to the build settings of your project.
Have a look at the following link about using makefiles in Eclipse:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/reference/cdt_u_create_make_target.htm

Related

CLion import existing cmake projects with dependencies

I'm testing CLion to check if it will adapt to our needs.I have like 9 different projects in C++ and we generate makefiles using CMake. I read that CLion works well with this kind of projects. I'm trying to create a workspace including these 9 modules in a big project in CLion. The reason is that some of them have dependencies and could be great if we can navigate from one module to other one. I Tried to import them using the option "import project from sources". This detects all my modules but create a huge CMakeLists.txt in the root folder and this is not working for me.
I Would like to have this workspace with these modules and compile them independently but having their dependencies for navigation. I searched a lot but I didn't find anything. Can this be done in CLion?
Thank you
To create a root CMakeList.txt, which includes all sub-projects/modules is the way-to-go with CMake. If you want to compile a single submodule you only need to make a single target: make [target].
I think there is a Tool Window in CLion, where you can see all your targets and compile each independently (similar to the Maven Tool-Window in IntelliJ).
Alternativly you can create Run Configurations..
(I will append my answer later, to back it with facts.. No CLion at work..)
Unfortunately I was wrong about the Tool Window.. But CLion is creating automatically a Run/Debug Configuration for each target it has found. You can select them by clicking on the Drop-Down Menu in the upper right corner. You can either choose Build All or a specific target. Next to this menu are 3 buttons - Compile, Run and Debug - to trigger any actions.

Eclipse: add a run configuration in a makefile project

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 ?

Build project has encountered a problemm Eclipse C++.

Details are saying I have two different tools of the same compiler. I'm not sure where to go from here to fix this so I can build my project. Any ideas?
This is the detailed message:
Errors occurred during the build.
Errors running builder 'CDT Builder' on project '263_Hw'.
Internal error building project 263_Hw configuration Debug
Generated resource conflict:
two resources of the same name: /263_Hw/Debug/main.o
generated by different tools
tool1: GCC C++ Compiler
tool2: GCC C++ Compiler
Generated resource conflict:
two resources of the same name: /263_Hw/Debug/main.o
generated by different tools
tool1: GCC C++ Compiler
tool2: GCC C++ Compiler
Internal error building project 263_Hw configuration Debug
Generated resource conflict:
two resources of the same name: /263_Hw/Debug/main.o
generated by different tools
tool1: GCC C++ Compiler
tool2: GCC C++ Compiler
Generated resource conflict:
two resources of the same name: /263_Hw/Debug/main.o
generated by different tools
tool1: GCC C++ Compiler
tool2: GCC C++ Compiler
The most likely situation: you have two source files with the same name but different file extensions. In your case, that would likely indicate you have something like
main.c
main.cpp
in your project tree. Could be tricky to see, especially if you have a lot of nested folders. I'd go to your source root and do a search for main.*
In Ecplise, right Click on project -> Properties -> C\C++ Build -> Tool Chain Editor. In the 'Current Builder' select box, select 'Gnu make builder' -> Apply (or Ok).
Try building the project again.
If you've exhausted all other options try using the gcc make tool directly:
1) Open the command line
2) cd to the folder containing the Make files (i.e. # cd 'C:\Path\To\MakeFile')
3) Assuming you have a typical MINGW windows install, run the command # C:\MinGW\bin\mingw32-make.exe all
4) the above command can be shorter if you have the MinGW folder set as a path variable.
5) The output binaries should be found in the bin folder in the same location.
Hope this helps anyone.
I have seen this same problem before but i don't remember what i did about it! For starters one way to try to solve it is by checking if you have more than one MinGW folder installed on your computer (I am assuming you use MinGW)! Also Check your project properties->c/c++ General->Paths and symbols->Includes and making sure that there are links to only one minGW folder! (It may look something like this (except for you they may start with "c:/mingw/...":
My solution was to delete the project (not the source code, just remove the project from Eclipse) and recreate it from scratch and setting up the include paths and linker paths again. Then it compiled properly.
This happened to me after I deleted a project from the workspace. I reimported the project with the same name to the same workspace, and when I tried to rebuild I got this error.
What I did was to delete the project from the workspace again, and then check my local directory where the workspace folder is. Voila, the deleted project is still in the workspace folder. So I deleted that project folder, then reimported the project again. It worked for me this way ;)

Project dependency in Eclipse CDT

I'm using eclipse for the first time. I'm a seasoned VisualStudio user, so I'm trying to find similar functionality in eclipse. I have two projects, A and B. Project A spits out libA.a when it's done compiling. Project B links against libA.a. Here is my problem.
I compile project A then project B, everything is fine.
I make a code change to project A that requires a build of project A.
I try to build project B, but it states that no changes have been detected.
How do I make project B aware of the output of project A?? Currently I'm having to do a clean build of project B for it to re-link against libA.a.
Thanks.
EDIT: In my ProjectB->Path and Symbols->References tab, I have project A checked. This doesn't relink after project A is rebuilt.
Try the below settings:
Go to properties of Main Project → C/C++ General → Paths and Symbols → References
Tick all the dependencies.
You go into Project Properties of Project B, select Project References and make it reference (depend) on Project A.
Edit, appears to be a known bug
One can work around this problem by using the touch command.
In Eclipse, as part of C/C++ Build/Settings is the tab 'Build Steps'. In the pre-build steps command line, enter touch filename.
filename is any file in your application. This could be the file with main(). This could be a special file just for this workaround, touchdummy.c, which can be a tiny file, which compiles quickly.
When the application builds, even if you didn't change any sources, the touch command causes make to rebuild the application. If the library was rebuilt, then the application gets rebuilt with the new library.
One can read about how touch affects the date/time of the file here.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html
Edit: The exact command in Eclipse would be touch ${ProjDirPath}/src/main.c
Edit: This command should work, but it appears that if the 'main' project did not change, the pre-build step is not executed. Also the touch command causes eclipse to prompt to reload the file it touched. A large annoyance.
Eclipse projects depend on each other by virtue of the checkbox in the project's properties (dependent projects?) which is how Eclipse decides which to build. You can set this yourself, but it's usually set when you change your Java build path.
By default at least with QNX C++ projects, it WILL NOT check for changes in other projects.
Right click on the project, and expand "check dependencies on/off"->"check user headers only"
It seems to work, roughly...
It appears to do a makedepends on the code, and adds *.d files to the output folder which are simply depends file that list the header files.
Note: these do not appear to get regenerated, and get out of date - I do not know how to regenerate them.
For Project A (library):
Properties>C/C++ Build>Settings>Build Steps>Post-build steps> touch -m ${ProjDirPath}/source/build/build_updated.cpp
You should create folder "source/build" firstly and don't add in that folder any other files.
For Project B:
Properties>Project References> check Project A
Properties>С/С++ General>Paths and Symbols>Source Location>Link Folder>Link to folder in the file system> find and pick "source/build" folder which you created for project A before.

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).