Results 1 to 16 of 16

Thread: Qwt with CMake

  1. #1
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Qwt with CMake

    I have downloaded and built qwt-6.2.0 and installed it in /usr/local/qwt-6.2.0/
    I have verified that the Qwt installation is sound by compiling and running the exampled provided, using Qt Creator 9.02.
    qmake --version reports Qt version 5.15.3, which I believe is the version Kubuntu 22.04 is built on.
    I am trying to use Qwt as part of a program built with Qt6, using KDevelop / cmake, but I have not been able to configure CMakeLists.txt correctly.
    I have found several discussions of this issue, but suspect that they might be deprecated. Anybody that knows about an up to date CMakeLists.txt for Qwt?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt with CMake

    You can build and install Qwt for Qt6 exactly the same way like for Qt5 - there is no difference beside that you use a qmake from a Qt6 installation.
    I recommend to do it from the command line - simply: /your/path/to/Qt6/bin/qmake qwt.pro.

    The way how Qwt has been installed does not prevent you from using your preferred build system of choice ( f.e. cmake ) in your project.

    Out of my head I would expect, that you have to:

    1. set the QWT_DLL define for the preprocessor
    2. add the path to the headers
    3. add the lib, when linking

    More or less what you have to do for almost any other 3rd party library.

  3. #3
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    QWT_DLL? I am on Ubuntu 22.04.
    I can find the qwt .h-files using
    include_directories(/usr/local/qwt-6.2.0/include)
    But cmake does not find the libs in
    /usr/local/qwt-6.2.0/lib
    (the libs are there) I have tried
    set(CUSTOM_LIBRARY_PATH /usr/local/qwt-6.2.0/lib )
    set(CMAKE_PREFIX_PATH /usr/local/qwt-6.2.0/lib)
    but all I get is:
    /usr/bin/ld: cannot find -lqwt: No such file or directory
    collect2: error: ld returned 1 exit status

    Running
    ld -lqwt --verbose
    in a shell returns failure, but that is perhaps a different environment?

    It seems I am misunderstanding how cmake works, but what am I doing wrong?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    Can you post your CMakelists.txt file for your project? If it is too big or you can't, then create a CMake project from one of the Qwt example programs (simpleplot maybe) and post your complete CMakelists.txt file for that.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    It looks like this:

    Qt Code:
    1. cmake_minimum_required(VERSION 3.22)
    2.  
    3. project(plottapp)
    4. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread")
    5.  
    6. # Find includes in corresponding build directories
    7. set(CMAKE_INCLUDE_CURRENT_DIR ON)
    8.  
    9. # Instruct CMake to run moc automatically when needed
    10. set(CMAKE_AUTOMOC ON)
    11.  
    12. # Find the QtWidgets libraries
    13. find_package(Qt6Widgets CONFIG REQUIRED)
    14. find_package(Qt6Charts)
    15.  
    16. include_directories(/usr/local/qwt-6.2.0/include) # works
    17. set(CUSTOM_LIBRARY_PATH /usr/local/qwt-6.2.0/lib) # does not work
    18. set(CMAKE_PREFIX_PATH /usr/local/qwt-6.2.0/lib) # does not work
    19.  
    20. set(plottapp_SRC
    21. main.cpp
    22. plottapp.cpp
    23. mslider.cpp
    24. etc.
    25. etc.
    26. )
    27.  
    28. qt6_wrap_ui(plottapp_SRC plottapp.ui)
    29. add_executable(plottapp ${plottapp_SRC})
    30. target_link_libraries(plottapp Qt6::Widgets Qt6::Charts qwt ) # <-- Chokes on qwt here
    31.  
    32. # Install the executable
    33. install(TARGETS plottapp DESTINATION bin)
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 2nd March 2023 at 20:27. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    Instead of using the CUSTOM_LIBRARY_PATH or CMAKE_PREFIX_PATH, you should probably use the find_library() command, something like this:

    Qt Code:
    1. find_library( QWT NAMES qwt qwt6 PATHS /usr/local/qwt-6.2.0/lib REQUIRED )
    2.  
    3. target_link_libraries( plottapp Qt6::Widgets Qt6::Charts ${QWT} )
    To copy to clipboard, switch view to plain text mode 

    However, your problem all along could be that the library might not be named "qwt" but "qwt6"

    In any case, find_library() is a better solution than changing CMake variables, which could have unintended consequences.

    With Microsoft compilers, the order of libraries does not matter. In linux and gcc, the libraries might have to be listed in dependency order, i.e. (plottapp ${QWT} Qt6::Charts Qt6::Widgets)
    Last edited by d_stranz; 2nd March 2023 at 20:42.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    That got me a bit further, as the libries are now found. However, I get a page full of linking errors, that I cannot make sense of. The order I list the libraries in target_link_libraries doen't seem to make a difference, and the errors are the same whether I compile for Release or Debug:
    Qt Code:
    1. [100%] Linking CXX executable plottapp
    2. /usr/bin/ld: /usr/local/qwt-6.2.0/lib/libqwt.so: undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<QVariant>::metaType@Qt_6'
    3. /usr/bin/ld: /usr/local/qwt-6.2.0/lib/libqwt.so: undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<bool>::metaType@Qt_6'
    4. /usr/bin/ld: /usr/local/qwt-6.2.0/lib/libqwt.so: undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<QSize>::metaType@Qt_6'
    5. .
    6. .
    7. .
    8. /usr/bin/ld: /usr/local/qwt-6.2.0/lib/libqwt.so: undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<QTime>::metaType@Qt_6'
    9. collect2: error: ld returned 1 exit status
    10. make[2]: *** [CMakeFiles/plottapp.dir/build.make:591: plottapp] Error 1
    11. make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/plottapp.dir/all] Error 2
    12. make: *** [Makefile:136: all] Error 2
    13. *** Failure: Exit code 2 ***
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    Finding Qt6Widgets is supposed to also bring in the dependencies (Qt6Gui and Qt6Core) but maybe you need to add those. Those errors look like there is a low level Qt library that is not being linked in. Maybe try putting ${QWT} at the beginning of the link libraries list, followed by Charts, Widgets, Gui, and Core. I think that is the correct dependency order.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  9. #9
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    I tried adding Qt6Gui and Qt6Core, and all kinds of reordering, but to no avail. I have no problem using Qt Charts, so the issue must be related to Qwt.

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    Are you sure you are building qwt against your Qt6 installation? Can you successfully use qwt in a project built with QtCreator? (I know these are "Have you checked to see if it is plugged in?" questions, but I've done things like this in the past, where I have had mismatched builds and nothing seems to work).

    It is MOC that results in all of the QMetaType references so something could be wrong with your qwt build.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  11. #11
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    I am not absolutely sure I am building Qwt corectly. I built Qwt thus:
    /usr/bin/qmake qwt.pro
    make
    sudo make install

    The strange thing is that all the examples supplied with Qwt works perfectly when build by QtCreator.

    The file qwtconfig.pri starts of with:
    QWT_VER_MAJ = 6
    QWT_VER_MIN = 2
    QWT_VER_PAT = 0
    QWT_VERSION = $${QWT_VER_MAJ}.$${QWT_VER_MIN}.$${QWT_VER_PAT}
    which looks correct to me.

    I do not know if it is relevant, but qwt.pro has this information at the start:
    lessThan(QT_MAJOR_VERSION, 5) {

    lessThan(QT_MINOR_VERSION, 8) {
    error(Qt >= 4.8 required.)
    }
    }

    include( qwtconfig.pri )

    The version 5 here probably refers to Qt 5.15.3 used by Kubuntu 22.04?
    qmake --version
    returns
    QMake version 3.1
    Using Qt version 5.15.3 in /usr/lib/x86_64-linux-gnu

    I noticed that there is also qmake6, which returns:
    qmake6 --version
    QMake version 3.1
    Using Qt version 6.2.4 in /usr/lib/x86_64-linux-gnu

    So I tried:
    make clean
    /usr/bin/qmake6 qwt.pro
    make
    sudo make install
    but the problem persists.

  12. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    What do you see when you run this?
    Qt Code:
    1. ldd -d -r libqwt.so
    To copy to clipboard, switch view to plain text mode 
    Does it show dependencies on any of the Qt6 libraries?

    How about opening the qwt.pro file in QtCreator and ensuring that you are building using a Qt6 kit?

    I am afraid I am not really a linux developer, so this is getting to the limits of my knowledge and experience.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  13. #13
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    I see:
    Qt Code:
    1. ldd: ./libqwt.so: No such file or directory
    To copy to clipboard, switch view to plain text mode 
    Q
    I then created a link:
    Qt Code:
    1. ln -s /usr/local/qwt-6.2.0/lib/libqwt.so.6.2.0 libqwt.so
    To copy to clipboard, switch view to plain text mode 
    but it made no difference. But output like
    Qt Code:
    1. /usr/bin/ld: /usr/local/qwt-6.2.0/lib/libqwt.so: undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<QVariant>::metaType@Qt_6'
    To copy to clipboard, switch view to plain text mode 
    indicated that the lib is found. It also indicates that qwt v. 6.2.0 is used, as well as Qt6, so it appears that there isn't a version mismatch. Also, I can build the qwt examples with Qt Creator, so libqwt.so seems to be OK.

  14. #14
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    Well. sorry, but I am at the end of my ideas. I think qmake creates a Makefile, right? (I use Visual Studio on Windows for all my development, which does not use Makefiles). Maybe take a look at one of those for your qwt examples and see if there is something in the linking that is missing from your CMakelists file. Otherwise, I don't know what else to suggest.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  15. #15
    Join Date
    Jan 2020
    Posts
    53
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qwt with CMake

    Yes, cmake creates a makefile, but I don't find any clues there. There is a file called CMakeCache.txt, which includes:
    Qt Code:
    1. Name Value
    2. QWT /usr/local/qwt-6.2.0/lib/libqwt.so
    To copy to clipboard, switch view to plain text mode 
    which is the correct path. Anyway, don't spend more time on this problem. I will keep scratching my head though. One thing I haven't thought about before: does qmake use hard-coded paths?

  16. #16
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qwt with CMake

    cmake creates a makefile
    No, I meant qmake. Check the Makefile from that to see if there are any ideas about what could be wrong with the cmake configuration.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qt Creator Qt SDK 1.1.3 and CMake on Mac OS X 10.7.1 / Lion
    By agarny in forum Qt Tools
    Replies: 2
    Last Post: 3rd August 2012, 08:56
  2. Cmake
    By R.CH in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2010, 17:06
  3. QT linguist Cmake
    By _Jack_ in forum Qt Programming
    Replies: 1
    Last Post: 18th September 2010, 11:29
  4. using moc with cmake
    By Isaac in forum Newbie
    Replies: 2
    Last Post: 29th May 2008, 03:10
  5. CMake and pthreads
    By Matt Smith in forum General Discussion
    Replies: 5
    Last Post: 3rd September 2006, 20:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.