Search code examples
c++visual-studiolinkerexe

is it possible to link an exe file as a lib file to another project?


The question is in the title.

I have coded an .exe project, I would like to use one of the function of this project in another project.

Maybe it is a silly question, but if it is possible this would limit the number of projects in my solution...

I have given a simple try, I get an LNK1107 error.

I would say it is not possible, but it is hard to find a clear answer on the net.


Solution

  • No, it is not possible.

    An executable is a standalone entity. It is the result of linking object files together to produce a self-contained, well, executable.

    Linking two executables together will, at best, result in duplicate definitions of main (in reality it's a little more complicated, but…).

    What you want to do is share the object files before they become an executable, and this is typically accomplished by moving your shared/common code into a "library" then link the library into both projects.

    Alternatively, you could keep the executables all separate, but share the code at the version-control level, e.g. with SVN externals.