Search code examples
c++visual-studio-2010visual-c++-2010

Is there any way to add a source file through a pragma?


Is there any way, via a pragma directive, to add a source file to the list of files to be compiled in Visual Studio 10? That way header files could bring their implementation files along with them whenever they are included.


Solution

  • As far as I know there is no such thing. It would make it awfully complicated to keep track of project dependencies if something like that was supported.

    But there is something like that for libraries. Say you have a library called library.lib and a header file that declares the symbols for this library called library.h. You can include the following pragma in library.h:

    #pragma comment(lib, "library.lib")
    

    And then any project that includes library.h will link against library.lib automatically.

    This option is described on this page on MSDN.