Handling different build scenarios in Eclipse for C project - c++

I am working on embedded c project. Till now I was using batch files and cmd prompt to compile the source files. Now I am planning to use Eclipse IDE for editing the code and compilation. The folder structure is as follows (refer the image)
Delivery folder remains same for all build scenarios since it contains the main module source files.
Test_Setup folder contains the test cases. Each TAxx had src and inc folder. In each TAxx_src folder, there is a .c file containing main function and and test functions. Currently using batch files for testing there is a batch file for each TAxx folder (in this case 4 batch files) which will compile the Delivery folder and the corresponding TAxx folder.
In eclipse I want to keep the same folder structure. But if I give build, eclipse will throw multiple "main" error. Hence I am unable to give build directly.
There is also a possibility of creating build configurations in eclipse. But since TAxx can be in 100s it will be difficult to create so many build configurations and maintain it.
How to effectively handle such a build scenario in eclipse. My task is to keep the folder structure same and while giving build, I must be able to select which TAxx folder I want to use for build.
Keeping the same folder structure, how can I compile Deliver folder and anyone TAxx folder?
Is there an option to create build configurations automatically?
After project is successful and all test cases are executed, the source code in moved to configuration management, but the eclipse project is not stored. Is there an option to export build configurations in a file so that it can be used when the project is again loaded in Eclipse?
Regards
Manoj

Left click in the Project Explorer tab -> New -> C Project
A C projet will be created with 2 build configurations as default: Debug and Release.
Left click on your project just created.
Right click -> New -> Folder
This way add all your folders according to your Project structure.
Go to Properties -> C/C++ General -> Source location tab -> Add folder button
Then select both folders available resulting in the following Project layout:
Go to Properties -> C/C++ General -> Includes tab -> GNU C Language -> Add button
And finally add all your include paths resulting as follows:
To select which folders to be used for compilation, you rather have to select the folders that will be excluded from build. To do this right click on folder to exclude -> Resource Configurations -> Exclude From Build -> select the build configuration
This way building is acomplished as required in your bullet 1 and 2 questions.
Bullet 3 - It is possible through makefiles, although it's trickier then letting eclipse manage the build process.
Bullet 4 - Build configurations are already stored in the Project, so when you load it again will be there available again.
If you want to creat more build configurations right click in the Project, Build Configurations -> Manage -> New -> Copy settings from Existing Configuration
But in my opinion you don't need to create hundreds of build configurations in your case. Maybe just the 2 regular ones, Release and Debug are enough. Selection is made by choosing which TAxx folder will not be excluded from build.

Related

Selecting C++ main function to build in eclipse

I've a C++ project in eclipse which is version managed with git. I've a git submodule, which is another project I've written in C++. The submodule has its main function and my project has its own.
Eclipse chooses other main (from the submodule) to compile when I press build. Is there a way to choose which main to build in eclipse?
Update: I'm still working on the issue. Excluding resources from the project didn't help either. Will answer the question when I solve it.
Update 2: Solved at last. See my answer.
I have solved the problem, at last. The solution is not a simple and straightforward one, so I'm writing step by step:
First set your toolchain correctly from Properties -> C/C++ Build -> Tool Chain Editor -> Current toolchain. It's MacOSX GCCor Linux GCC for me.
Set your correct project source path. I've symlinked the files from projects I imported as submodules to my project, so setting the correct source directory didn't exclude any required files from my project. Setting is at Properties -> C/C++ General -> Paths & Symbols -> Source Location. Make sure you exclude the other submodules and symlink the required files to your project.
Change the name of the artifact (binary, library, etc.) to something different than the ${projName}, because when you have submodules, you will have a directory named as ${projName} inside your build folder. Setting is at Properties -> C/C++ Build -> Settings -> Build Artifact -> Artifact name.
After making these changes, your project should build automatically. Looks like eclipse makes all necessary checks during build, but doesn't warn you about the problems. I had to see all these problems with running make --always-build inside the Debug folder.

OpenCV setup in eclipse

I setup eclipse IDE to use openCV. I followed the tutorial provided on openCV website. However, there is this extremely annoying issue am facing every time I create a new project. It seems I need to redo the entire process of pasting the library files in GCC C++ linker for every project that I create. Is there anyway of making them persistent for all new projects ? Or to at least be able to export the settings so that I can import them which will save time.
Thanks
I may have misunderstood the question, but if you just don't want to set up the project each time, you can save a build configuration in Eclipse.
To use another projects build configuration:
Project -> Properties -> C/C++ Build
Click Manage Configurations and create a new config (call it opencv or whatever).
Then set up your Includes, GCC linker etc as you have done before. Then hit Apply.
Now if you ever want to set up a new project with these configs, select your new project:
Project -> Properties -> C/C++ Build -> Manage Configurations
Click New and select 'Import from projects' and select your 'opencv' configuration. This will import the build set-up into the your new project.
Then just select it from the Configuration drop-down.
To export the build configuration as an XML file:
Right click project -> Export...
Select C/C++ -> C/C++ Project Settings
Select the Configuration you want to export and save it somewhere.
To import it into a project:
Right click project -> Import... -> C/C++ Project Settings
and browse for your config file
Hope this helps!

The program file specified in the launch configuration does not exist

I am facing some problems regarding eclipse for c/c++. I am trying to create a new project, I provide the code, and after running the code I get this error:
The program file specified in the launch configuration does not exist
C:\Users\elisabeth\workspace\mm\Debug\mm.exe not found
Please notice that I am working with spice toolkit; I set the path for the "include" files and the libraries, but still I can not have a result.
What causes this error and how can I resolve it?
Right click on your project --> Properties
Run/Debug settings
Delete whatever is set as "launch configuration for '........'
Project --> Clean
Project --> Build Project
You can create a run configuration. Go to Run > Run Configurations. Click New button, fill C/C++ Application field, i.e., insert path to your executable. The new configuration will appear in the list which appears when you click to the arrow next to run button.
Of course this assumes your can build without problems, otherwise you won't see an executable to point to.
You can clean the project, build it again and run it as a local C/C++ application. Simplified steps as follows,
Right click on the project
Clean Project
Again Right click on the project
Build Project
Again Right click on the project
Run As ->
Local C/C++ Application
As the error reads:
C:\Users\elisabeth\workspace\mm\Debug\mm.exe not found
First of all you need to check whether there is an executable "mm.exe" in your Debug folder. (Of course, it is not there and that is why the error)
Go to Project > Clean
and you should see some files being deleted from your Debug folder
Go to Project > Build Project
and you should see some new files being generated e.g. mm.d, mm.o, mm. This "mm" is probably the executable you're looking for
Now that you know what your executable is, you should tell eclipse what file to execute instead of mm.exe. Go to Project properties and in run debug settings create a new configuration (or edit an existing configuration, if there is one already). In this configuration, in main tab, in C/C++ Application specify a full path to "mm". Which, in your case is - "C:\Users\elisabeth\workspace\mm\Debug\mm"
A better way to do this in eclipse is:
${project_loc}/"your folder"/"your executable file"
e.g.${project_loc}/Debug/mm
what worked for me is file->refresh
then do the Debug configuration again by choosing the right c/c++ binary again.
Avoid troubles with configuration by going into Project properties > C/C++ build > Refresh Policy and specify your project folder. The configuration option "Search project" will show a correct folder then and you will see whatever you build there - Debug, Release or both. You don't want to specify the folder using Browse option every time you import project or switch configurations.
As this is the first SO discussion that appears for this topic on Google and none of the answers solved the problem my students were having, I would like to mention the solution we eventually found from this answer:
Open project properties (Right click on your project, choose Properties on the menu)
C/C++ Build -> Settings
Click on Binary Parsers tab and check PE Windows Parser
Keep clicking Move Up until it is at the top
This had been set to Elf, even though we were using a freshly downloaded Windows version of Eclipse.
sometime missed closing curly brace can be part of a problem. Make sure prototype your function at the beginning of the file. Then right click your project in the left side bar. click clean project. then click build project and finally run project
I encountered similar issues and their related problems a few days ago. Finally, I found out that, just because I had moved my project folder (workspace folder of Eclipse) to another place so Eclipse could not find what its need as usual.
Solution: I just set the workspace to my new place (Hey Eclipse, my workspace now is here) :
Menu "File" -> "Switch workspace" -> "Other..." -> click "Browse..." button and point to new place then click "Select Folder" button and click "Launch" button.
Nice day.

How can I setup Visual C++ 2010 Express to copy some folders during the build process?

I'm not a regular C++er, so this question might be fairly trivial: Can anybody please tell me what I need to do that during the build process some folders will get copied to the output directory?
My project is currently structured somewhat like this:
Projects
-> ProjectName
-> .cpp and .h files
-> Folder1
-> Folder2
-> Debug
-> Release
Folder1 and 2 contain some files that are required during runtime, so they need to be shipped with my application - how do I get those into Debug/Release while building the project? Or is there any other recommended method to deal with such situations?
Under the projects properties, use build events, and on the command line enter the equivalent command codes to copy the files.

How do you compile Box2D for Code::Blocks/MinGW32 under Windows?

I've found similar questions across the internet, none of which helped me. The Code::Blocks workspace and project files included DO generate .a files, and I've moved them to Codeblocks/MinGW/lib, and I've moved the Box2D folder to Codeblocks/MinGW/include and yet the HelloWorld.cpp example still gives me these errors.
Looks like the project files you used to build the .a were missing some files. The file mentioned in the error message is one that was removed from Box2D after v2.1.2, so I'm guessing you are using 2.1.2 source code (or thereabouts) with project files from some other source?
In any case, setting these up yourself is really simple. In the 'Management' panel, right click the 'Engine' project, select Remove files and click OK to remove everything.
Now do the same and select Add files recursively, choose the folder that contains Box2d.h file:
Click OK a few times, and you're done.
In your case, since you had it building already I would expect this to be ok now but for anyone arriving here wanting to setup a project file from scratch, you'll also need to specify the search path for the Box2D headers.
To do this, in the same right-click menu choose: Properties -> Project settings tab -> Project's build options button -> Search directories tab -> Add button. Now choose the parent folder of the one you just chose above.