<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep 30, 2018 at 3:12 AM Kim Walisch <<a href="mailto:kim.walisch@gmail.com">kim.walisch@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>I have recently found out about CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which allows</div><div>to easily build a shared library i.e. DLL on Windows. It works great and it is an awesome</div><div>feature however I have run into a warning on Windows (using cmake, ninja, MSVC) because</div><div>my CMakeLists.txt builds both a static and shared library.</div><div><br></div><div>Here is what my CMakeLists.txt does:</div><div><br></div><div><div>if(WIN32)</div><div> set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)</div><div>endif()</div></div><div><br></div><div>add_library(mylib SHARED ${LIB_SRC})<br></div></div></div></div></div></div></div></blockquote><div>make this 'mylib-sh' </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div>...</div><div>add_library(mylib STATIC ${LIB_SRC})<br></div></div></div></div></div></div></div></blockquote><div>make this 'mylib-st' </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div>...</div><div><br></div><div>This works without any issues on all Unix-like OSes. However on Windows with MSVC I found</div><div>out that building the shared library creates both mylib.dll and mylib.lib. And building the static</div><div>library also creates mylib.lib which causes ninja to issue the following warning:</div><div><br></div><div>ninja: warning: multiple rules generate mylib.lib. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]<br></div><div><br></div><div>So my question is how to best deal with this warning:</div><div><br></div><div>1) Should I ignore it?</div></div></div></div></div></div></div></blockquote><div>you need the .lib to later link to the .dll so no... </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div>2) Should I use add_library(... MODULE ...) instead of SHARED on Windows? The ninja</div><div>maintainer's have suggested this when another user reported the issue here:</div><div><a href="https://github.com/ninja-build/ninja/issues/1128#issuecomment-207058115" target="_blank">https://github.com/ninja-build/ninja/issues/1128#issuecomment-207058115</a><br></div><div><br></div><div>One issue I see with this approach is that apparently when building a shared library using</div><div>add_library(... MODULE ...) one should avoid using target_link_libraries(binary mylib)<br></div><div>as mentioned in this stackoverflow answer: <a href="https://stackoverflow.com/a/4968940/363778" target="_blank">https://stackoverflow.com/a/4968940/363778</a></div><div>However the author of the stackoverflow answer also mentions that on Windows you</div><div>could probably still use target_link_libraries(binary mylib)!?</div><div><br></div><div>3) Or is there another known workaround for this issue.</div></div></div></div></div></div></div></blockquote><div>Could just use unique names.</div><div>There's little use in practice in linking against both... if you really want to do both and have it be either</div><div>just use add_library and let the user of the library deside if static or shared should be enabled. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div>Thanks,</div><div>Kim</div></div></div></div></div></div></div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div></div>