I am trying to make two QObject libraries, using cmake on windows, where one depend on the other. If i build them both as STATIC libraries it works, but now that i need to build them as SHARED libraries, i keep getting compile errors.
- error LNK2001: unresolved external symbol "public: static struct QMetaObject const A::staticMetaObject"
I am compiling using Visual Studio 19.
A small example of the problematic code:
First Library:
#include <QObject>
class A: public QObject
{
Q_OBJECT
public:
A(const QString& name){}
public Q_SLOTS:
void ASlot(){}
};
Second Library
#include "A.hpp"
class B: public A {
Q_OBJECT
public:
B():A("A"){}
private Q_SLOTS:
void BSlot(){}
};
CMakeLists.txt:
project(test)
cmake_minimum_required(VERSION 3.10)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Modules")
find_package(Qt5Core REQUIRED)
set(CMAKE_AUTOMOC ON)
add_library(A SHARED A.hpp)
target_link_libraries(A ${Qt5Core_LIBRARIES})
set_target_properties(A PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
add_library(B SHARED B.hpp)
target_link_libraries(B A ${Qt5Core_LIBRARIES})
The code has been verified to work on linux, so i am guessing it might be a problem with how the dll symbols are exported. I have tried using the qt5_wrap_cpp() instead of automoc, but the result does not differ.
I hope someone can help me with the problem.