[CMake] How can I compile and link modular code into a single DLL with MSVC?

Innokentiy Alaytsev alaitsev at gmail.com
Thu Jun 28 03:44:19 EDT 2018


Hello!


Jason Heeris wrote
> The only problem I encountered was that the final shared library complains
> about having "NO SOURCES given to target: module3_dll". I can add
> "module3.c" as a source, even though technically the static lib should
> already contain everything from there. I'm not sure why that's an issue
> though.

The reason is that SHARED_LIBRARY targets must have sources to be built. The
fact that everything is already in the static library does not matter. In
this case, it may worth using OBJECT_LIBRARY targets, but in a different
way:  add an object library and provide it as sources for your target
<https://cmake.org/cmake/help/v3.5/command/add_library.html#object-libraries> 
. However, I did not succeed when I tried it on my own project (most likely
due to my own incompetence).


Jason Heeris wrote
> On Thu, 28 Jun 2018 at 04:16, Innokentiy Alaytsev <

> alaitsev@

> >
> wrote:
> 
>> Also, I have an important note about the structure of the project: It may
> be better to have all the dependencies defined before they are used, i.e.
> you should not be able to use the target_link_libraries() with an
> undefined
> target as a linked library.
> 
> I have no idea how I'd achieve this though, with so many subdirectories. I
> think CMake is perfectly happy to resolve these links at generate time
> rather than as the configuration is parsed though?

You may be right about CMake being happy to resolve everything by itself. As
I wrote "It may be better", so I may as well be plain wrong.




--
Sent from: http://cmake.3232098.n2.nabble.com/


More information about the CMake mailing list