frankaemika / libfranka

C++ library for Franka research robots
https://frankaemika.github.io
Apache License 2.0
221 stars 147 forks source link

using libfranka with Qt yields 'undefined reference' error #139

Closed sdfzz closed 11 months ago

sdfzz commented 11 months ago

Hi all,

I'm trying to use libfranka with Qt.

I've installed libfranka as described in "https://frankaemika.github.io/docs/installation_linux.html" following "building libfranka", and I can run examples without any problems.

However, when I try to write my own code in Qt, I get the following error:

/root/Projects/TEST/frankaTest/mainwindow.cpp:-1: error: undefined reference to `franka::Robot::Robot(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, franka::RealtimeConfig, unsigned long)'

I've added libfranka/include folder to my ".pro" file and I can import all headers alright.

My header:

#include <franka/duration.h>
#include <franka/exception.h>
#include <franka/model.h>
#include <franka/robot.h>

My source:

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    try{
        franka::Robot robot("127.0.0.1");
    } catch(franka::Exception const& e){
        qDebug() << e.what();
    }
}

Any help would be greatly appreciated

Sincerely,

Steve

sdfzz commented 11 months ago

I'm happy to post the solution to my own question.

To use libfranka on Qt,

  1. Install libfranka library, follwoing "building libfranka" of "https://frankaemika.github.io/docs/installation_linux.html" . I did not build/install deb package.
  2. Create a new qt project, open .pro file, right click, select 'add library'. Choose 'external library' and select libfranka.so file in libfranka/build folder
  3. Add the following to .pro: INCLUDEPATH += /path_to_libfranka/include/

Now I can build the code above. Hope this helps other qt newbies like me.

Sincerely,

Steve