simulton / QSchematic

A library that allows creating diagrams such as flowcharts or even proper engineering schematics within a Qt application.
https://simulton.com
MIT License
231 stars 60 forks source link

error: libqschematic.so with undefined references #24

Closed noctice007 closed 3 years ago

noctice007 commented 3 years ago

Hi there :) I've built the library and tried to link it with my qt application, I'm using qmake to build my project I've added LIBS += -lgpds -lqschematic to my .pro file When I compile the project it gives me tons of linker errors of undefined references Here are few: /usr/bin/ld: /usr/local/lib/libqschematic.so: undefined reference to typeinfo for QSchematic::Item' /usr/bin/ld: /usr/local/lib/libqschematic.so: undefined reference toQSchematic::Node::sizeChanged()' /usr/bin/ld: /usr/local/lib/libqschematic.so: undefined reference to vtable for QSchematic::Connector' /usr/bin/ld: /usr/local/lib/libqschematic.so: undefined reference toQSchematic::Scene::itemRemoved(std::shared_ptr)' . .

Am I missing something I've built the library with the instructions provided from the README.me file with DEPENDENCY_GPDS_DOWNLOAD enabled and extra sudo make install to install it on my system

Thanks in advance

Tectu commented 3 years ago

Hey,

I haven't used qmake in a very long time. However, the LIBS += line seems remotely familiar. What I can tell you is that integrating the library into another cmake project using find_package() works. However, this does not mean that there isn't any bug/problem in the library itself that you're experiencing.

From your output it would seem that the library itself is found by the compiler/linker. I'm wondering whether this has to do with missing export declarations. Can you inspect the libqschematic.so to look for the presence of exported symbols such as QSchematic::Item and so on?

Unfortunately, I am unable to create a qmake project for testing this myself right now.

noctice007 commented 3 years ago

Okay I made a small project with cmake, part of the CMakeLists.txt is:

find_package(QT NAMES Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(gpds REQUIRED)
find_package(QSchematic REQUIRED)

set(PROJECT_SOURCES
        main.cpp
        MainWindow.cpp
        MainWindow.hpp
        MainWindow.ui
)
add_executable(testWitCmake
    ${PROJECT_SOURCES}
)

target_link_libraries(testWitCmake PRIVATE Qt${QT_VERSION_MAJOR}::Widgets qschematic::qschematic-shared)

The same undefined references errors occurred

Then I checked the symbols of libqschematic.so with nm -u | c++filt to check the undefined symbols(It's a long list) but what I've noticed is that it has some methods from the standard Qt included like a lot of QGraphicsItem, QGraphicsView...etc

U QSchematic::ItemMimeData::staticMetaObject
U QSchematic::Item::movedInScene(QSchematic::Item&)
U QSchematic::Item::settingsChanged()
U QSchematic::Item::highlightChanged(QSchematic::Item const&, bool)
U QSchematic::Item::staticMetaObject
U QSchematic::Item::moved(QSchematic::Item&, QVector2D const&)
U QSchematic::Item::rotated(QSchematic::Item&, double)
U QSchematic::Node::sizeChanged()
U QSchematic::View::modeChanged(QSchematic::View::Mode)

U QGraphicsItem::clearFocus()@Qt_5
U QGraphicsItem::itemChange(QGraphicsItem::GraphicsItemChange, QVariant const&)@Qt_5
U QGraphicsItem::setVisible(bool)@Qt_5
U QGraphicsItem::setRotation(double)@Qt_5
U QGraphicsItem::setSelected(bool)@Qt_5
U QGraphicsItem::unsetCursor()@Qt_5

and more
Tectu commented 3 years ago

Which compiler are you using?

I am using this library successfully in two different applications. Albeit both of these applications are cmake based and use GCC 10.

noctice007 commented 3 years ago

I'm using Gcc 11.1

Tectu commented 3 years ago

I think I managed to reproduce the problem - will continue investigating.

Tectu commented 3 years ago

Could you have a look at the current master branch and inspect the built shared object again? Also: It would be wonderful if you could test the static library as well.

Tectu commented 3 years ago

I've put some work into this. It turns out that one should not build the shared & static library variants from cmake's object library. Please checkout release 1.0.2 and report back!

Tectu commented 3 years ago

I'm going to close this due to inactivity. Release 1.1.0 is known to have fixed this issue and also builds out of the box on MSVC.