Gradle C plugin: how to solve references between multiple modules - c

I have a c language program that has the following structure:
src/main/c/main.c
src/main/headers/main.h
src/module_1/c/module_1.h
src/module_1/headers/module_1.h
...
src/modulen/c/module_n.c
src/module/headers/module_n.h
In the gradle script I have defined:
components {
module_1(NativeLibrarySpec)
...
module_n(NativeLibrarySpec)
main(NativeExecutableSpec){
sources{
c.lib library: "module_1", linkage: "static"
...
c.lib library: "module_n", linkage: "static"
}
The reason of using this structure is to facilitate creating unit tests for each module separately.
The problem comes with the inclusion of the .h files from the modules in the main or in other modules (there are some dependencies between them). I haven't found a way to make the headers of a module available to other modules. I would actually like to make them all "global" to the project (that is, automatically added to the source set for any module).
Thanks in advance

I do not know gradle but may give you some general advise.
I haven't found a way to make the headers of a module available to other modules.
You could make a central directory (repository) for all .h files of your project, for example src/include. The header files of each module can be placed there (in the version of the curent baseline).
I would actually like to make them all "global" to the project (that is, automatically added to the source set for any module).
The above repository can support that. However, including a header in a source file is a manual task. It is also wise not to include all headers into a source file; it may only need a few.

Related

What is the difference between lib/src and /bin in dart?

I know that lib/ is where we put all our library files and /bin is where we put our entrypoint for our command-line app. I know both of them are public lib/ and bin but i'm unable to understand the convention of using lib/src which according to the official docs should contain: implementation code
lib/ is the directory that contains shareable code.
It can be shared
to other top-level directories like bin/, web/, example/, test/, tool/, ... in the same package
to other packages that have this package as a dependency.
lib/src by convention contains the private implementation of the public API exposed by lib/ or lib/xxx where xxx is not src.
bin is reserved for command line apps and contains the Dart entry point scripts to execute them (the files that contain main() {...}).
In pubspec.yaml you can define executables https://www.dartlang.org/tools/pub/pubspec#executables that allows you to run scripts from bin/ by just executing foo to have dart somePath/bin/foo.dart executed (using pub global activate my_package_with_foo).
See Pub Package Layout Conventions - Implementation files
The libraries inside lib are publicly visible: other packages are free to import them. But much of a package’s code is internal implementation libraries that should only be imported and used by the package itself. Those go inside a subdirectory of lib called src. You can create subdirectories in there if it helps you organize things.
You are free to import libraries that live in lib/src from within other Dart code in the same package (like other libraries in lib, scripts in bin, and tests) but you should never import from another package’s lib/src directory. Those files are not part of the package’s public API, and they might change in ways that could break your code.
When you use libraries from within your own package, even code in src, you can (and should) still use package: to import them.

Ufft example compilation

I want to run the example project which is available for free from this link. It is a simple FFT library and needs no compiler. In it, there is an example c file with its required header files and .c files.
When I try to run it in Vivado SDK I get errors of multiple definitions of fft and ifft. How can I run this example inside SDK?
What I had done is created an empty application project and then imported all these files inside src folder and then selected build the project option but didn't succeed in building and running the project.
I guess, looking at the ufft.zip archive, that you've tried to link files issued form the compilation of fft-dit.c and fft-dif.c.
Both files define ftt functions using differents method (see README).
You have to choose betwen using ftt-dif.c or ftt-dit.c, not both.
This is the same for itt-dif.c and itt-dit.c, choose one, not both.

Using external static library in LPCXpresso

I am using the LPCXpresso IDE to program my microcontroller to use the libjpeg library for a particular application. However, I cannot seem to get the LPCXpresso IDE to recognize libjpeg. The way I see it, there are two options:
1) Take the jpeglib.a file, include it as an external library, and then attempt to import jpeglib.h. I have tried this, at the IDE still does not recognize jpeglib.h.
2) Create a new static library from the libjpeg source code. Is this my only option? It seems a bit excessive.
Any tips regarding adding/linking external libraries in LPCXpresso would be greatly appreciated. Thanks!
You can easily add a library to Eclipse/LPCXpresso by creating a new project (not a C project or a LPCXpresso project but a 'normal' project) by clicking File->New->Project. Name is as you wish, let's say 'JPEG'. Add your library file to it under the folder 'lib' (you have to create the folder first). Call the library file 'libJPEG.a'. Also include the header file under the folder 'inc'. It is not mandatory to create these folders by the way, but it makes it all more organised.
The edit the properties of the project that's needs to include the header and library. Right click the project and choose properties. Go to C/C++ Build->Settings->MCU C compiler->Includes and add the include path of the inc folder of the library project. The go to C/C++ Build->Settings->MCU Linker->Libraries and add the library file WITHOUT the lib in front of the file name, hence just JPEG. Also add the library search path below (point to the lib folder).
That's all!

eclipse include custom files (c)

Not sure how to phrase the question.
I've created a few files for my c project that I would like to use for multiple projects.
Project root: ~/workspace/myproject
Files :
~/workspace/myproject/customlib/myfile.h
~/workspace/myproject/customlib/myfile.c
I was able to move them from my eclipse (Code Composer Studio) workspace and replace them with symlinks to their new location.
Custom lib dir: ~/myfiles/customlib
This is working fine but I'd rather not use the symlinks as it becomes necessary to add those symlinks to any project where I want my customlib files. Also when copy/pasting a project in eclipse it doesn't seem to understand the symlink and creates a copy of the file rather than the symlink.
I've set up an include path to ~/myfiles/ but when I compile I get a bunch of unresolved symbol errors.
My custom files depend on files from other include paths as well. (if that might be a hint as to why things are breaking)
Is there another way I can link in these files?
I figured out how I can do what I'm looking for but can't actually post the answer for 8 hours so I'll answer it here.
I was able to add the .c files as "Linked Resources" to my project.
So in the end I had an include path to ~/myfiles and a linked resource ~/myfiles/customlib/myfile.c.
Linked Resources can be found under Project Properties -> Resource -> Linked Resources -> Linked Resources(tab)
Unfortunately, my environment, Code Composer Studio 6 on Ubuntu would not allow me to actually add a linked resource through the IDE.
As a workaround I added the linked resource directly to the .project file.
~/workspace/myproject/.project
Under the section labeled "natures" I added
<linkedResources>
<link>
<name>myfile.c</name>
<type>1</type>
<locationURI>$%7BPARENT-2-PROJECT_LOC%7D/myfiles/customlib/myfile.c</locationURI>
</link>
</linkedResources>
The "$%7BPARENT-2-PROJECT_LOC%7D" refers to ~/workspace/myproject/../../ (a.k.a. ~/). The 2 tells it how many ../'s
In case you don't get the locationURI right the first time you should be able to edit the file path from Project Properties -> Resource -> Linked Resources -> Linked Resources(tab)
You can use any defined build variables for the locationURI. Here is another way to write the location URI. PROJECT_LOC/../../myfiles/customlib/myfile.c
Since this is an eclipse project file it will be overwritten with whatever eclipse decides is the proper format for locationURI
You can place the linked resource into a folder in your project by modifying the tag. projectsubfolder/myfile.c. This will create a folder projectsubfolder under your project directory. ~/workspace/myproject/projectsubfolder
Unfortunately this isn't an optimal solution as I will need to add linkedresource entries for every source file I create in my custom lib. CCS fumbles the linked resources when doing a project copy/paste, requiring you to add the linked resources again to your copied project.
In the end it feels like a solution but it really doesn't have much benefit over symlinked files. The only one being that when I copy/paste a project I will know the project isn't using the correct files when it doesn't compile. (symlinking will make a working project with copies of the files instead of the originals)
I imagine I will need to learn about creating .lib files to make the inclusion a little more pain free.

Preserving Header Directory Structure in Xcode for Static Library

I'm developing a static library in C++ using Xcode. I have an Installation Directory set where it copies all of my public header files, but when I compile it just copies all the headers into one directory. Is there a way to tell Xcode to preserve the directory structure of my header files? Thanks in advance!
I also needed to preserve the header file directory structure for a C++ library project and I finally managed to do it. It is ridiculously complicated with XCode, compared to the simple nature of the task. The key is to create "folder references" at first, then to copy the header folders in an extra build phase and afterwards to delete .c/.cpp-files from these exported header folders with a script, because XCode will not only copy the .h-files.
I've written a blog post here on how to all achieve that, because it's more tricky in detail. You might also want to check out an example XCode project that I've pot on github.
When you add files to your project, you have to choose next parameter on an additional window "Create folder references for any added folders". And then all your files will have fixed path for your files and will save structure after compilation.

Resources