[CMake] Can two executables share one object file?

Clark J. Wang dearvoid at gmail.com
Fri Jun 8 23:34:32 EDT 2007


On 6/9/07, Stuart Herring <cmake at stuartherring.com> wrote:
>
> On 6/9/07, Clark J. Wang <dearvoid at gmail.com> wrote:
> >
> > but it failed to cmake. So how can I let two executables share one
> single
> > object file?
> >
> You don't really want to.
> The cost of compiling the same source file twice is minimal, and it's
> much safer to compile them separately - it means that if you later
> need to add different compile flags for the two executables that you
> can without worry of one contaminating the other.


This makes sense. Thank you.

However, you could always build a static library and create the
> executable from that:
>
> ADD_LIBRARY(hellomain STATIC main.c)
> ADD_EXECUTABLE(hello1 hello1.c)
> ADD_EXECUTABLE(hello2 hello2.c)
>
> TARGET_LINK_LIBRARIES(hello1 hellomain)
> TARGET_LINK_LIBRARIES(hello2 hellomain)


This really works but I prefer not using it. ;-)

Regards,
> Stuart.
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070609/c950f268/attachment.htm


More information about the CMake mailing list