linking the libmodbus to Qt creator

  • Does anyone know how to use the modbus library known as libmodbus with Qt Creator 5.5. I have dropped the src file into my project folder but I can't access any of the methods or classes that are provided. I keep getting this error

    error: LNK2019: unresolved external symbol __imp__modbus_connect referenced in function...

    this is my .pro file where I link the library

    QT += core
    QT += network
    QT -= gui

    TARGET = SocketTest
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS +=

    LIBS+= -LC:/Users/amccaugh/Documents/NOVOS App Projects/SocketTest/ThirdParty/src/modbus.c -lmodbus

    any help would be greatly appreciated. Thanks

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Where is your modbus.lib file located ?
    Also, since you have spaces in your path you should at least quote it otherwise the linker won't have the correct path to search in.

    By the way, Qt now proposes the QtSerialBut module that you might be interested in.

  • Hi thank you for your response

    our client has limited us to Qt Creator 5.5 for now. QtSerialBus isn't available until 5.6

    the modbus library isn't a .lib file its a folder containing c files and headers.

    here's the link for you to check out the download

    I basically copied the necessary files and placed them into my project folder.
    I Included the appropriate header files to access the function I need but it keeps giving me an "unresolved external symbol" error.

    when I hover over the function Qt creator understands where I'm calling the method from as it shows the right file path so I have no idea what I'm missing.

    let me know if you would like to see anything specific

  • Lifetime Qt Champion

    Don't mix Qt and Qt Creator, those are two separated project and their version number are not related.

    Since you copied the libmodbus files in your project folder, I suppose you want to built them also with your project, right ?

    If so, then your LIBS line is useless. However you should fix your SOURCES and HEADERS variable. you are missing a backslash at the end of all concerned lines.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.