How to make multiple subdirectories in Eclipse from existing code - c

I am using Windows 10 and Eclipse Mars edition 32 bit. Programming in C
I am trying to learn C from a Lynda.com course C Essential Training. The course provides a zipped directory with many .c and files and a few others like .h files as you can see below.
However in the video he managed to get each .c file and related source code into its own directory structure.
I've tried numerous type of imports and I also used a batch file to put each .c file in its own folder and tried importing that. I was able to get the Eclipse IDE project window to look like the instructors, but as soon as I tried to compile individual .c programs the project kept looking in the primary workspace folder which for me is C:\Source\Testing\workspace and error'd out.
Is there an import option to create this type of subdirectory structure automatically? I want to go through the tutorial and build and execute each .c file individually. However what I have had to do is put the .c file into a single folder build it and run it one at a time. I then have to delete the source and debug folder and start over for each lesson. There must be a better way.

Eclipse workspace is streigh connected to FS.
This means that your workspace in Eclipse is a folder on your hard disk or where it is stored.
What you can simply do is to create a new folder using right-click-popup-menu within Eclipse Project Explorer and then copy/move files into the new folder.
Or you can create a new folder into your workspace directory and copy/move file inside, then you must refresh Eclipse workspace.

Related

Git-Ignore in Xcode

I am using X-Code 10 as a C IDE. I am doing a group project and we must use GitLab to share the code. To work in Xcode there are a lot of files to make Xcode work, but none that I need to share with my partners who are using their own IDE and who just need the .c files we are working on. How do I make Git not upload ALL files and just the .c?
There are ways to handle the excludes for a git project. There is the .gitignore file where you can create rules for what files should be excluded from your project. This file will be tracked by git, so you and your teammates will be sharing this file.
For your own personal excludes, you can put them into the .git/info/exclude file. This will not be tracked by git and will affect only your own local repository. This is a good place put rules that are specific to your own workflow.

Eclipse: C project folder structure

I have an existing C project with the following folder structure:
bin
proj
src
inc
doc
conf
When i launch Eclipse and create a new project the root project folder is polluted with:
.cproject
.project
Also the parent folder with:
.metadata
RemoteSystemsTempFiles/
A want to continue use Eclipse as an C IDE with a my custom makefile (or not) but I want all Eclipse related files and folders to be put inside the proj directory. I need Eclipse to debug ARM targets.
Is it possible? If not what is the next best thing?
I made a promise to myself to start a smooth transition from IDEs to vim with a custom makefile. I still need Eclipse to help me for debugging.
One step at a time...
The files .project and .cproject (and the .settings folder if it exists) contains the Eclipse-specific (general and C/C++) project configuration.
The .metadata folder is a kind of cache/temp folder (to store error/warnings markers, local file history, etc.) and also used to store your workspace preferences (most of Window > Preferences).
Files in a project are tracked and can cause changes in the .metadata folder. If the .metadata folder would be located in a project, this could end in an infinite loop.
You could use the workspace folder of Eclipse (which contains the .metadata folder) as part of your overall project folder and link instead of copy all files and folder that you want to see in Eclipse or that are required by Eclipse into your Eclipse project (you can also mark some files and folders as derived to stop them from being tracked and to make them less visible in Eclipse).
Note, do not share or move the .metadata folder (and derived resources). In contrast, .project, .cproject and .settings are intended to be shared.

CDT API to attach header files to a C project in Eclipse CDT

We made an Eclipse CDT plugin in order to create a C project layout that follow certain standard set across our organization. We maintain some sort of XML files that define the project/product dependencies. That means, every product will have an XML file that defines what source files/headers goes into that product.
So, when importing a C project in Eclipse CDT, instead of following the standard CDT project setup, our plugin takes product name as the input and parses the product's XML to generate a C project with appropriate source files.
We were able to attach source files to the C project using the following API and Linked Resources concept in Eclipse.
org.eclipse.core.resources.IFolder
org.eclipse.core.resources.IFile
We were also able to attach header files to the same C project using the following class.
org.eclipse.cdt.core.model.IIncludeEntry
Note: We created IIncludeEntry instances with the inlcude directories
as the input. Eclipse's scanner discovery mechanism is identifying the
individual source files inside each directory and showing them under
"Includes" tag in C project.
Now the source files are shown under "Source" tag and the header files are shown under "Includes" tag in the C project. We could modify and build the source files without any issues.
However, we couldn't edit any of the header files. If I manually add an external header file thru Project >> Properties >> C/C++ General >> Paths and Symbols everything works fine, we can edit the files.
I also tried to use org.eclipse.cdt.core.model.IIncludeFileEntry instead of IIncludeEntry by giving individual header file paths to IIncludeFileEntry. But Eclipse isn't identifying anything with IIncludeFileEntry.
What's the CDT API to create/attach header files to a C project? How Eclipse CDT creates them?

Add external source files from a library to the project in Eclipse-CDT

I have a project which I try to compile with Eclipse-CDT. The project depends on a library with header files and source files. How can I configure the project in Eclipse such that it will compile the needed source files from the library with the project?
With a makefile I use:
SRC+=lib_source.c
You can add linked source file.
Choose project properties and in the left panel choose c++ general.
Under it choose path and symbols.
Now in the right panel tabs choose source location and add linked source folder.
Include you need to define in "include" (under c++ build you will find settings)
Another approach is to use the operating system to add your libraries to the project. Eclipse then treats all source files (including library files) as part of the project, and therefore compiles any that need it even if they are in the libraries. This set-up allows keeping the library sources in a separate git repository from the project source code. You can record the git commit of a library to provide library version control so that improving the library in one project does not break all the others. The setup relies on the operating system's capability to link directories in a way that is entirely transparent to eclipse--in windows using the mklink command.
In windows the steps are
put your library files in a clean workspace not mixed with .git (you can have .git in the parent directory as egit sets it up)
use cmd window in administrator mode to add a link from your project directory to your library directory.
from eclipse press F5 t make sure your project matches what is on disk, then set up git to ignore your library directory.
set up your library file properties for read only access unless you are still tweaking that library.
set up your project include path to include the project sub-directory in your project.
I can't remember why I abandoned eclipse linked directories; i think it was that the includes kept breaking. The mklink approach has worked flawlessly so far.
I have a pdf tutorial of how to set this up--but I'm new to the forum and don't see how to attach a file.

Eclipse CDT c project setup for a specific structure

i recently moved to a C project and i want to use eclipse CDT as my IDE. The project layout is a bit annoying. the header files are located
main_component/sub_comonent/include/ folder
However, in the c source file. they are referenced as #inlcude<main/subcomonent/sample.h>.
In eclipse, if i put include folder into my path, but in the source file will be referenced as #inlcude<sample.h> instead of #inlcude<main/subcomonent/sample.h>.
if i put the root of project into the path the real path will be #inlcude<main/subcomonent/includesample.h> instead of #inlcude<main/subcomonent/sample.h>.
so how can i configure eclipse to just have#inlcude<main/subcomonent/sample.h>.
thanks
It seems there is no better way. I finally decided to copy all the header files out to one folder by a bash.

Resources