A clean build approach is *always required* on Windows when switching between building shared and static libraries because the __declspec export stuff gets built into every single .obj file referencing any header with such decorations in it.
<br><br>(But Visual Studio does not consider the obj files out of date when those settings change... it&#39;s only looking at the time stamps.)<br><br>Similarly for other compiler flags -- implying that if you change an ADD_DEFINITIONS in a CMakeLists or do anything manually with CMAKE_CXX_FLAGS, it&#39;s in your best interest to do a clean build. Anything else (in my opinion) is simply a waste of time trying to work around potential mismatch issues that arise from trying an incremental build anyway.
<br><br>Patience is still a virtue. ;)<br><br>HTH,<br>David<br><br><br><div><span class="gmail_quote">On 11/16/07, <b class="gmail_sendername">Stephen Collyer</b> &lt;<a href="mailto:scollyer@netspinner.co.uk">scollyer@netspinner.co.uk
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Bill Hoffman wrote:<br><br>&gt; If you want to change all the libraries in your project to shared, you
<br>&gt; can use the global variable BUILD_SHARED_LIBS, and use add_library<br>&gt; without specifying shared or static.<br>&gt;<br>&gt; $ cmake --help-command add_library<br>&gt; cmake version 2.4-patch 7<br>&gt;&nbsp;&nbsp; ADD_LIBRARY
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add a library to the project using the specified source files.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADD_LIBRARY(libname [SHARED | STATIC | MODULE]<br>&gt; .....&nbsp;&nbsp;If no keywords appear as the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;second argument, the type defaults to the current value of
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BUILD_SHARED_LIBS.&nbsp;&nbsp;If this variable is not set, the type<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;defaults to STATIC.<br><br>Thanks for that. I&#39;d read it but I misunderstood it - I didn&#39;t<br>realise that it meant that the SHARED/STATIC thing could be omitted.
<br><br>However, I&#39;ve now run into another problem. I&#39;m trying to set up<br>a build system so that I can build all libraries in the source<br>tree either statically or shared, and link all exes statically<br>or shared. Under Linux, this works fine. I can run (in an
<br>out-of-source build tree)<br><br>cmake ../..<br><br>to get a static build and:<br><br>cmake -DBUILD_SHARED_LIBS=ON ../..<br><br>to get a shared build. However in Win32, something odd happens<br>with VS. If I run the same &quot;cmake -DBUILD_SHARED_LIBS=ON ..\..&quot;
<br>in a command line window, then fire up VS and do a build on the<br>ALL_BUILD target, the link of the exes fails because no .lib file<br>is generated for the .dll. If however, I then build the clean<br>target for ALL_BUILD, and then do a build, the .lib file is built
<br>and the link of the exe succeeds.<br><br>This implies to me that for some reason, on the first pass after<br>I build in a command line, the appropriate \D is not being passed<br>to switch on my _declspec(dllexport) define appropriately.
<br><br>In the top level cmake list file I have:<br><br>IF (BUILD_SHARED_LIBS)<br>&nbsp;&nbsp;&nbsp;&nbsp;ADD_DEFINITIONS(&quot;-DBUILD_SHARED_LIBS&quot;)<br>ENDIF (BUILD_SHARED_LIBS)<br><br>and in a .h file to support the build of a library called Test,
<br>I have:<br><br>#ifndef _TESTEXPORT<br>#define _TESTEXPORT<br><br>#if defined (WIN32) &amp;&amp; defined (BUILD_SHARED_LIBS)<br>#pragma warning(disable: 4251)<br>&nbsp;&nbsp;#if defined(Test_EXPORTS)<br>&nbsp;&nbsp;&nbsp;&nbsp;#define TEST_EXPORT __declspec(dllexport)
<br>&nbsp;&nbsp;#else<br>&nbsp;&nbsp;&nbsp;&nbsp;#define TEST_EXPORT __declspec(dllimport)<br>&nbsp;&nbsp;#endif /* Test_EXPORTS */<br>#else&nbsp;&nbsp;&nbsp;&nbsp;/* defined (_WIN32) &amp;&amp; defined (BUILD_SHARED_LIBS)&nbsp;&nbsp;*/<br>#define TEST_EXPORT<br>#endif<br><br>#endif&nbsp;&nbsp; /* _TESTEXPORT */
<br><br>and something like:<br><br>class TEST_EXPORt Test { ... }<br><br>in the code for the class.<br><br>Do you have any clue why this clean/build approach is needed ?<br>It may be down to my misunderstanding of what is happening the
<br>first time I&#39;m running cmake in the command line window.<br><br>--<br>Regards<br><br>Steve Collyer<br>Netspinner Ltd<br>_______________________________________________<br>CMake mailing list<br><a href="mailto:CMake@cmake.org">
CMake@cmake.org</a><br><a href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>