[Interest] CMake AUTOMOC & Windows linking

Andy asmaloney at gmail.com
Fri May 15 20:36:15 CEST 2020


OK. I don't know why my cmake code to show the SOURCES wasn't showing them,
but when I looked in the ninja json files, A's headers were in the
"sources" section.

The problem turned out to be this:

target_sources( libA
    PUBLIC
    ...

It needs to be:

target_sources( libA
    PRIVATE
    ...

The PRIVATE vs. PUBLIC on target_sources() didn't make sense to me before,
but with this concrete example I think I understand it better. :-)

Thanks for pointing me in the right direction Thiago!

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>



On Fri, May 15, 2020 at 2:15 PM Matthew Woehlke <mwoehlke.floss at gmail.com>
wrote:

> On 15/05/2020 11.17, Andy wrote:
> > I'm running into a link problem on Windows. I only have Windows on CI, so
> > debugging this is... challenging.
> >
> > - cmake 3.10+
> >
> > - AUTOMOC is ON for the project in the top level cmake file
> >
> > - Dynamic Library "A":
> >    class LIB_IMPORT_EXPORT Foo
> >    {
> >        Q_OBJECT
> >        ...
> >
> >     where LIB_IMPORT_EXPORT uses Q_DECL_EXPORT/Q_DECL_IMPORT properly
> > depending on who's building.
>
> This isn't necessarily your problem, but if you're using CMake, I would
> recommend using generate_export_header to define your ABI decoration
> symbols rather than rolling your own using Q_DECL_EXPORT/Q_DECL_IMPORT.
>
> --
> Matthew
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200515/2de00f5e/attachment.html>


More information about the Interest mailing list