views:

212

answers:

2

I have a situation where another developer is including source files from a project that I maintain in a project that he maintains. The nature of the files is such that each source file registers a "command" in an interpretive environment so all you have to do is link in a new source file to register a new "command". We can't put these files in a static library because, unless the project makes explicit reference to the symbols in the file, the linker will optimise the file away.

It seems like a potential solution is to have a file external to both projects that "includes" a list of source file names in both projects. The problem is that I have no idea whether or how this could be done. Suggestions, anyone?

A: 

Could you simply write a source file containing nothing but #include directives? I'm not sure if VS checks whether the dependent files have changed if they're not in the project proper, though.

Thomas
I had considered this but there are static symbols (anonymous namespaces) that could collide if included in the same "compilation unit".
Jon Trauntvein
+1  A: 

There is no reason a source file can't be in multiple projects. Just add it as an 'existing item' in VS.

If you are using precompiled headers then both projects will need equivalent set ups for this to work.

You can also use a #pragma in a lib to force a symbol to be included when the linker would otherwise discard it.

#pragma comment(linker, "/include:__mySymbol")

See the MSDN document for #pragma comment and the include option

Rob Walker