0

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?

user3817250
  • 1,003
  • 4
  • 14
  • 27
  • What about putting your common files into a library project that makes a static or shared library? Then your other projects would link with that library. The include path just tells the project where the headers are. You still have to link with something to resolve the symbols in those headers. – indiv Jul 16 '14 at 15:32
  • I'm not familiar enough with using projects as resources to be comfortable doing this. My worry is that my compiled code could end up a little more bloated than necessary. – user3817250 Jul 16 '14 at 16:21

1 Answers1

0

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.

user3817250
  • 1,003
  • 4
  • 14
  • 27