问题
I have a set of Eclipse c projects that will all refer to a common shared base of code (a mix of .c and .h files in the same folder) but will be built that code differently on a per project basis.
The common code base may be edited from within each project but these edits will be fixes to be carried across all the projects. The common code will no diverge per project except for build options through defines.
If I create a project for this library it implies a library build with is not what I need. I need the resulting object files to land in the project that they are being built for. So a c/c++ project does not make sense.
The common code will be checked in to a subversion repo (as will each project). I could use "New folder -> Linked resource" but I would prefer to keep the projects independent of the directory structure the developer happens to be using.
Is there a clean way to do this?
Thanks.
回答1:
I'm not sure this will work for your version of Eclipse, or for CDT (I tested it with Java), but it seems you should create a second source folder. Since a source folder are usually private to the project it exists in, you have to create a linked folder... (from your description above I think perhaps you've already done that, but for completeness of the answer I include the steps below).
I did it this way:
- Create a new item in your project
- Select folder (not a source folder but a simple folder)
- In the folder creation dialog click the "Advanced >>" button and check the "Link to folder in file system" check box
- Click "Browse" and select the folder of common source files
- Click finish
You now have a simple folder, but in order to include the files in the folder in your compilation (at least in Java it works this way) you need to create a source folder:
- Create a new item in your project
- Select "Source folder"
- Click "Browse" next to the "Folder name" text box
- Select your newly created linked folder
Now, in my version of Eclipse, and in Java, this folder is included in compilation of the code. It hopefully works the same way in CDT...
If you run an OS with real symbolic links (Linux, OSX?) you may also use a symlinked folder in your project for the extra source folder, and then you should be able to just do the "Source folder"-creation steps above.
If your version of Eclipse do not have a "Browse"-button in the Source Folder creation dialog, try just typing the same name in the text box.
Regards,
/E
来源:https://stackoverflow.com/questions/1907275/in-eclipse-cdt-shared-resource-folder-that-is-built-differently-for-the-project