Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Help with Project References
Help with Project References [message #213984] Tue, 15 April 2008 15:39 Go to next message
Eclipse UserFriend
Originally posted by: mikedeskevich.gmail.com

I don't think I'm understanding how project references are working in CDT
4.0.3.

Background - I'm coming from the world of Visual Studio, I only rarely
touch makefiles. I was hoping that CDT would insulate me from makefiles.

I just downloaded the CDT for a new cross-platform project I'm starting.
To learn how the CDT works, I created two projects;

Project 1 - Executable that depends on the static library created in
Project 2
Project 2 - A simple library that provides functions that Project 1 needs

So I set it up where Project 1 references Project 2 with the "Project
Reference" checkbox. I figured this is just like in Visual Studio where I
say Project 1 depends on Project 2.

Now, in Project 1, I need to include something from Project 2, so I have
something like:

#include "project2.h"

When compiling Project 1, I can't get it to see project2.h. First, I
thought that since I set up Project 2 as a reference, it would find it.
Then I found in the project settings that I can add directories (and other
workspace projects) to the "-I" option, which seems right, and that
doesn't work either. Likewise, when I add Project to to the "-L" option
in Project 1, it doesn't find the libraries either. It just seems that
the -I and -L directories never get passed on to the complier.

I guess my question is how do I set up projects so that I can have the
includes and libs built in one project be accessible in another? I know
this is a simple question, but I'm just having a real hard time getting it
to work. I hope I'm not missing something stupid.

Thanks,
Mike
Re: Help with Project References [message #214069 is a reply to message #213984] Wed, 16 April 2008 09:05 Go to previous messageGo to next message
Tracy Miranda is currently offline Tracy MirandaFriend
Messages: 16
Registered: July 2009
Junior Member
Hi Mike,

Setting up a project reference in Eclipse/CDT is a little tricky/confusing,
particularly as there are two 'Project Reference' pages.
(The Properties->Project References page is not the best one to use).

Try this:
1. Set up a reference between projects, using the page Properties->C/C++
General->Paths and Symbols->References
You should see there that if you are referencing another managed project,
you can choose the configuration (defaults to 'Active').
By setting up this reference, the following should happen:
- A reference is created between the projects so Project 1 is always built
before Project 2
- The library project is automatically added to the 'Include' (-I) path e.g.
"${workspace_loc:/project2}"
- The library project is automatically added to the 'Libraries' (-L) path
e.g "${workspace_loc:/project2/Debug}"
(Double check the latter 2 have been done, otherwise you will need to do
them yourself)

2. One thing that is not set up is a reference to the library name itself.
You can add this in yourself,
C/C++ Build->Settings->Linker->Libraries-> Libraries (-l). Add in the name
of your library, e.g.if your library file is libutilities.a, then
add in "utilities".

Once this is done, building your exe project should build the library
project too, as well as find headers
and source code that are part of the library project.

Also fyi, the Properties->Project References is an Eclipse rather than
CDT-specific page - all that does is makes the referenced
project build before the main project, but it knows nothing about build
settings, configurations, etc.

Hope this helps.

Tracy

"Mike" <mikedeskevich@gmail.com> wrote in message
news:7d7517a5ca07214333679c5e716ff07a$1@www.eclipse.org...
>I don't think I'm understanding how project references are working in CDT
>4.0.3.
> Background - I'm coming from the world of Visual Studio, I only rarely
> touch makefiles. I was hoping that CDT would insulate me from makefiles.
>
> I just downloaded the CDT for a new cross-platform project I'm starting.
> To learn how the CDT works, I created two projects;
>
> Project 1 - Executable that depends on the static library created in
> Project 2
> Project 2 - A simple library that provides functions that Project 1 needs
>
> So I set it up where Project 1 references Project 2 with the "Project
> Reference" checkbox. I figured this is just like in Visual Studio where I
> say Project 1 depends on Project 2.
>
> Now, in Project 1, I need to include something from Project 2, so I have
> something like:
> #include "project2.h"
>
> When compiling Project 1, I can't get it to see project2.h. First, I
> thought that since I set up Project 2 as a reference, it would find it.
> Then I found in the project settings that I can add directories (and other
> workspace projects) to the "-I" option, which seems right, and that
> doesn't work either. Likewise, when I add Project to to the "-L" option
> in Project 1, it doesn't find the libraries either. It just seems that
> the -I and -L directories never get passed on to the complier.
>
> I guess my question is how do I set up projects so that I can have the
> includes and libs built in one project be accessible in another? I know
> this is a simple question, but I'm just having a real hard time getting it
> to work. I hope I'm not missing something stupid.
>
> Thanks,
> Mike
>
Re: Help with Project References [message #214534 is a reply to message #214069] Mon, 21 April 2008 08:57 Go to previous messageGo to next message
james soh is currently offline james sohFriend
Messages: 28
Registered: July 2009
Junior Member
Hi Tracy,

can I set the CDT project references programmatically? if yes, any hints
for me on which class to look at?

Is there a way to remove the Eclipse project reference page from CDT, dual
project reference page were confusing to me too.

Thanks
8)
Re: Help with Project References [message #214630 is a reply to message #214534] Mon, 21 April 2008 13:28 Go to previous messageGo to next message
Tracy Miranda is currently offline Tracy MirandaFriend
Messages: 16
Registered: July 2009
Junior Member
You should be able to set it programmatically. Try searching the codebase
for
ICConfigurationDescription.setReferenceInfo();

One nice example to follow might be in the test source, see
org.eclipse.cdt.projectmodel.tests.ProjectModelTests -> testReferences
method.

As for removing the Eclipse project reference page, the only way I know to
do that would involve changing the plugin.xml
file to add a filter to not show it for cprojects - but this would involve
changing core Eclipse plugins so not sure it is advisable unless you are
committed to rebuilding Eclipse core.

Tracy

"James Soh" <zeroin23@gmail.com> wrote in message
news:c83a12c15cb980273f7472d5f5da6bd9$1@www.eclipse.org...
> Hi Tracy,
> can I set the CDT project references programmatically? if yes, any hints
> for me on which class to look at?
> Is there a way to remove the Eclipse project reference page from CDT, dual
> project reference page were confusing to me too.
> Thanks 8)
>
>
Re: Help with Project References [message #214983 is a reply to message #214630] Thu, 24 April 2008 13:37 Go to previous messageGo to next message
james soh is currently offline james sohFriend
Messages: 28
Registered: July 2009
Junior Member
Tracy Miranda wrote:
> You should be able to set it programmatically. Try searching the codebase
> for
> ICConfigurationDescription.setReferenceInfo();
>
> One nice example to follow might be in the test source, see
> org.eclipse.cdt.projectmodel.tests.ProjectModelTests -> testReferences
> method.

wonderful, with this setReferenceInfo, I managed to shorten my codes
significantly. Though there is a catch, it doesnt set the -l library
name option which I also want.

>
> As for removing the Eclipse project reference page, the only way I know to
> do that would involve changing the plugin.xml
> file to add a filter to not show it for cprojects - but this would involve
> changing core Eclipse plugins so not sure it is advisable unless you are
> committed to rebuilding Eclipse core.
>
> Tracy

thanks, I also found the bug report #173302 in org.eclipse.platform
which discuss about to hid or not in CDT.

>
> "James Soh" <zeroin23@gmail.com> wrote in message
> news:c83a12c15cb980273f7472d5f5da6bd9$1@www.eclipse.org...
>> Hi Tracy,
>> can I set the CDT project references programmatically? if yes, any hints
>> for me on which class to look at?
>> Is there a way to remove the Eclipse project reference page from CDT, dual
>> project reference page were confusing to me too.
>> Thanks 8)
>>
>>
>
>
Re: Help with Project References [message #215073 is a reply to message #214983] Mon, 28 April 2008 15:16 Go to previous messageGo to next message
Tracy Miranda is currently offline Tracy MirandaFriend
Messages: 16
Registered: July 2009
Junior Member
> wonderful, with this setReferenceInfo, I managed to shorten my codes
> significantly. Though there is a catch, it doesnt set the -l library name
> option which I also want.

Glad it improves your code. Yes, it would be nice if the library name was
automatically added in too.
I created an enhancement request for this
https://bugs.eclipse.org/bugs/show_bug.cgi?id=229085


> thanks, I also found the bug report #173302 in org.eclipse.platform which
> discuss about to hid or not in CDT.

Great, I'd not seen that bug. Seems like one worth voting for, then maybe it
will get finalized!!

Tracy

"James Soh" <zeroin23@gmail.com> wrote in message
news:fuq2ef$a81$1@build.eclipse.org...
> Tracy Miranda wrote:
>> You should be able to set it programmatically. Try searching the codebase
>> for
>> ICConfigurationDescription.setReferenceInfo();
>>
>> One nice example to follow might be in the test source, see
>> org.eclipse.cdt.projectmodel.tests.ProjectModelTests -> testReferences
>> method.
>
> wonderful, with this setReferenceInfo, I managed to shorten my codes
> significantly. Though there is a catch, it doesnt set the -l library name
> option which I also want.
>
>>
>> As for removing the Eclipse project reference page, the only way I know
>> to do that would involve changing the plugin.xml
>> file to add a filter to not show it for cprojects - but this would
>> involve changing core Eclipse plugins so not sure it is advisable unless
>> you are
>> committed to rebuilding Eclipse core.
>>
>> Tracy
>
> thanks, I also found the bug report #173302 in org.eclipse.platform which
> discuss about to hid or not in CDT.
>
>>
>> "James Soh" <zeroin23@gmail.com> wrote in message
>> news:c83a12c15cb980273f7472d5f5da6bd9$1@www.eclipse.org...
>>> Hi Tracy,
>>> can I set the CDT project references programmatically? if yes, any hints
>>> for me on which class to look at?
>>> Is there a way to remove the Eclipse project reference page from CDT,
>>> dual project reference page were confusing to me too.
>>> Thanks 8)
>>>
>>>
>>
Re: Help with Project References [message #1407380 is a reply to message #214983] Tue, 12 August 2014 13:30 Go to previous message
Anitha Mising name is currently offline Anitha Mising nameFriend
Messages: 28
Registered: February 2010
Junior Member
I know this is a pretty old mail chain, but this is exactly where i am stuck in my code. I am trying to add project references in CDT's Paths and Symbols and in Eclipse Project References. I am doing the following:

private void setProjectDependencies(IWorkspaceRoot root, IProject project,
IProjectDescription description) {
try {
Map <String, String> refMap = new HashMap<String, String>();
IProject[] depProjects = new IProject[projDependencies.length]; // projDependencies is a String array of dependent project names
for (int i=0; i< projDependencies.length; i++) {
depProjects[i] = root.getProject(projDependencies[i]);
refMap.put(projDependencies[i], ""); // Active Configuration
}
description.setReferencedProjects(depProjects);

// Set in CDT's Paths and Symbols too
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescription desc = coreModel.getProjectDescription(project);
ICConfigurationDescription[] cDescriptions = desc.getConfigurations();
for (ICConfigurationDescription cfgDesc : cDescriptions) {
cfgDesc.setReferenceInfo(refMap);
}

project.setDescription(description, null);

} catch (CoreException e) {
// TODO: Throw error
}
}


Let me know what i am doing wrong here. Thanks.
Previous Topic:Using custom C compilers
Next Topic:Re-Generating makefile every build selected file
Goto Forum:
  


Current Time: Fri Mar 29 12:04:42 GMT 2024

Powered by FUDForum. Page generated in 0.04671 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top