# unresolved external symbol "public: static struct QMetaObject const" when linking to a shared Q\_OBJECT

**URL:** https://discourse.cmake.org/t/unresolved-external-symbol-public-static-struct-qmetaobject-const-when-linking-to-a-shared-q-object/5338
**Category:** Usage
**Created:** [March 31, 2022, 2:56am UTC](https://discourse.cmake.org/t/unresolved-external-symbol-public-static-struct-qmetaobject-const-when-linking-to-a-shared-q-object/5338 "2022-03-31T02:56:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [March 31, 2022, 2:56am UTC](https://discourse.cmake.org/t/unresolved-external-symbol-public-static-struct-qmetaobject-const-when-linking-to-a-shared-q-object/5338/1 "2022-03-31T02:56:06Z")

</div>

I want to make two QObject libraries using cmake on windows: ProA & ProB, where ProB depend on ProA.

I want to make two QObject libraries using cmake on windows: ProA & ProB, where ProB depend on ProA.

The code of ProA looks like:

```auto
class ProA_Export ProA: public QWidget
{
    Q_OBJECT
public:
    ...
};

```

The CMake script of ProA looks like:

```auto
set(CMAKE_AUTOMOC ON)

```

The ProB links ProA in CMake: `target_link_libraries(ProB ProA)`.

Then, when I `#include "ProA.h"` in ProB, it reproted:

```auto
unresolved external symbol "public: static struct QMetaObject const ProA::staticMetaObject"

```

And, I can seee `mocs_compilation_Debug.cpp` in the vs, and the content `of mocs_compilation_Debug` is `#include <EWIEGA46WW/moc_ProA.cpp>`. I also find `moc_ProA.cpp` in `build\autogen\include_Debug\EWIEGA46WW\moc_ProA.cpp`

If I remove the `Q_OBJECT` from ProA, everything is OK except that the signal-slot of QT do not work.

So, how can I solve the `unresolved external symbol` problem caused by `Q_OBJECT`?

Any suggestion is appreciated~~~

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 7, 2022, 3:08pm UTC](https://discourse.cmake.org/t/unresolved-external-symbol-public-static-struct-qmetaobject-const-when-linking-to-a-shared-q-object/5338/2 "2022-04-07T15:08:22Z")

</div>

I think figuring out why the `moc` bits are not being included in the `ProA` library would be the first place to start. Do you have the link line used for it handy?
