0

I have a Visual Studio solution with multiple C++ projects, and I find managing the linker dependencies a bit cumbersome.

Every time I include a header file from an other project, I need to explicitly add the corresponding .obj file in the linker settings. I.e. in Properties>Linker>Input>Additional Dependencies:

..\Project1\$(Platform)\$(Configuration)\Obj1.obj
..\Project1\$(Platform)\$(Configuration)\Obj2.obj
..\Project2\$(Platform)\$(Configuration)\Obj3.obj
..\Project2\$(Platform)\$(Configuration)\Obj4.obj

Using wildcard characters would greatly simplify this task:

..\Project1\$(Platform)\$(Configuration)\*.obj
..\Project2\$(Platform)\$(Configuration)\*.obj

But unfortunately this also includes the two main.obj files from Project1 and Project2.

Is there a way to exclude these files from the linker input?

I tried to use the standard(?) Windows file-search options like this:

"..\Project1\$(Platform)\$(Configuration)\*.obj"-"..\Project1\$(Platform)\$(Configuration)\main.obj"
"..\Project2\$(Platform)\$(Configuration)\*.obj"-"..\Project2\$(Platform)\$(Configuration)\main.obj"

but apparently they are not supported here. In fact, it seems simply adding quotes around a valid linker path breaks everything.

I've also seen this question, and sure, I could do something like this, renaming or deleting the undesired files by a custom script, but I'd prefer to avoid it. What I want to do seems like a fairly reasonable thing; every project having its own main.obj makes sense to me, linking some but not all .objs makes sense to me as well. There must be some standard VS way to say "link everthing, except for this one" to the linker.

But feel free to correct me of course, that's why I'm here. Thanks in advance.

p.s.: I'm currently using VS2012, but I'm interested in answers for any VS version, even for older ones (I won't downgrade just for this, but I am interested).

szmate1618
  • 1,545
  • 1
  • 17
  • 21
  • Have you tried `..\Project1\$(Platform)\$(Configuration)\O*.obj`? – Yuval Ben-Arie Jul 22 '17 at 14:41
  • Yes, that would be a good solution for the concrete example I specified, but unfortunately my actual filenames are more diverse, like Geometry.obj and AbstractPartitioner.obj. But I'd be fine with this approach. Do you know if there are other wildcard characters allowed? Could I write something like ?????*.obj to exclude filenames shorter than 5 characters? Or do you know where could I find a list of allowed wildcards? – szmate1618 Jul 22 '17 at 14:51
  • Usually the other object files will be part of a library, and you link against that. Otherwise you can add the .cpp file to the new project, without moving it from its original place. That way it will be included automatically. – Bo Persson Jul 22 '17 at 14:52
  • Hm... so that's what I'm doing wrong. Thank you for your help, I guess I'm gonna link against a lib then. – szmate1618 Jul 23 '17 at 13:32

1 Answers1

1

VS2013:

I believe the way this is normally achieved by adding a reference to the other project which is building as a StaticLibrary or DynamicLibrary.

This is done by right clicking on the parent project in the Solution Explorer and navigating to Here

Add->References...

then selecting

Add New Reference...

and selecting the checkbox.

You can then break up your code into different Static and Dynamic libraries based on what you need.

I hope this helps, I do not usually manually reference object files in the project files.

  • Thanks for the help! I'd prefer to keep this question open for a little longer if you don't mind, but I'm gonna accept your answer unless I get an other one that directly solves my problem. – szmate1618 Jul 23 '17 at 13:34
  • There is always more than one way to make something work :) – Garrett Sickles Jul 23 '17 at 16:10