Ask Your Question
0

Error: Threads Multiple Definition of

asked 2016-06-07 13:55:51 -0500

Geaper gravatar image

updated 2016-06-07 14:30:21 -0500

I have two GUI exactly the same except a few alterations. I copy-paste the code and changed only the node.

Code:

  #include "tum_ardrone_gui.h"
#include "RosThread.h"
//#include "PingThread.h"
#include "time.h"
//#include "../HelperFunctions.h"

#include "ros/ros.h"
#include "ros/package.h"

#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <string.h>

int getdirtxt (std::string dir, std::vector<std::string> &files)
{
    DIR *dp;
    struct dirent *dirp;
    if((dp  = opendir(dir.c_str())) == NULL) {
        std::cout << "Error(" << errno << ") opening " << dir << std::endl;
        return errno;
    }

    while ((dirp = readdir(dp)) != NULL) {
        std::string f = dirp->d_name;
        if(f.size() > 4 && f.substr(f.size()-4) == ".txt")
            files.push_back(std::string(dirp->d_name));
    }
    closedir(dp);
    return 0;
}

tum_ardrone_gui::tum_ardrone_gui(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);
    rosThread = NULL;
    sensGaz = sensYaw = sensRP = 1;
    currentControlSource = CONTROL_NONE;
    useHovering = true;

    for(int i=0;i<8;i++)
    {
        isPressed[i] = false;
        lastRepeat[i] = 0;
    }


    QObject::connect( this, SIGNAL(setCountsSignal(unsigned int,unsigned int,unsigned int,unsigned int) ),
                       this, SLOT( setCountsSlot(unsigned int,unsigned int,unsigned int,unsigned int) ) );

    QObject::connect( this, SIGNAL( setPingsSignal(int, int) ),
                       this, SLOT( setPingsSlot(int, int) ) );

    QObject::connect( this, SIGNAL( setControlSourceSignal(int) ),
                       this, SLOT( setControlSourceSlot(int) ) );

    QObject::connect( this, SIGNAL( addLogLineSignal(QString) ),
                       this, SLOT( addLogLineSlot(QString) ) );

    QObject::connect( this, SIGNAL( setAutopilotInfoSignal(QString) ),
                       this, SLOT( setAutopilotInfoSlot(QString) ) );

    QObject::connect( this, SIGNAL( setStateestimationInfoSignal(QString) ),
                       this, SLOT( setStateestimationInfoSlot(QString) ) );

    QObject::connect( this, SIGNAL( setMotorSpeedsSignal(QString) ),
                       this, SLOT( setMotorSpeedsSlot(QString) ) );

    QObject::connect( this, SIGNAL( closeWindowSignal() ),
                       this, SLOT( closeWindowSlot() ) );


    std::vector<std::string> files = std::vector<std::string>();
    getdirtxt(  ros::package::getPath("tum_ardrone") + std::string("/flightPlans/"),files);

    ui.comboBoxLoadFile->addItem(QString(""), QVariant());
    for(unsigned int i=0;i<files.size();i++)
        ui.comboBoxLoadFile->addItem(QString(files[i].c_str()), QVariant());

}



tum_ardrone_gui::~tum_ardrone_gui()
{
}

// clicked functions
void tum_ardrone_gui::LandClicked()
{
    rosThread->sendLand();
}

void tum_ardrone_gui::TakeoffClicked()
{
    rosThread->sendTakeoff();
}
void tum_ardrone_gui::ToggleCamClicked()
{
    rosThread->sendToggleCam();
}
void tum_ardrone_gui::FlattrimClicked()
{
    rosThread->sendFlattrim();
}
void tum_ardrone_gui::EmergencyClicked()
{
    rosThread->sendToggleState();
}

void tum_ardrone_gui::ClearClicked()
{
    rosThread->publishCommand("c clearCommands");
}
void tum_ardrone_gui::SendClicked()
{
    QStringList l = ui.plainTextEditSendCommand->toPlainText().split('\n');
    for(int i=0;i<l.length();i++)
    {
        std::string s = l[i].trimmed().toStdString();

        if(s.size() > 0)
            rosThread->publishCommand(std::string("c ")+s);
    }
    setControlSource(CONTROL_AUTO);
}
void tum_ardrone_gui::ClearSendClicked()
{
    ClearClicked();
    SendClicked();
}
void tum_ardrone_gui::ResetClicked()
{
    setControlSource(CONTROL_NONE);
    ClearClicked();
    rosThread->publishCommand("f reset");
}


void tum_ardrone_gui::LoadFileChanged(QString val)
{
    if(val == "")
        ui.plainTextEditSendCommand->setPlainText("");
    else
    {
        std::string path = ros::package::getPath("tum_ardrone") + std::string("/flightPlans/") + val.toStdString();
        addLogLine("Load File "+ path);

        std::ifstream t;
        t.open(path.c_str());
        std::string buffer = "";
        std::string line;
        while(!t.eof())
        {
            std::getline(t, line);
            buffer = buffer + line + "\n";
        }
        t.close();

        ui.plainTextEditSendCommand->setPlainText(buffer.c_str());
    }
}
void tum_ardrone_gui::ToggledUseHovering(int val)
{
    useHovering = (val != 0);
}

void tum_ardrone_gui::ToggledPingDrone(int val)
{
    pingThread->measure = (val != 0);
}

// change control source functions
void tum_ardrone_gui::ControlSourceChanged()
{
    ControlSource s = CONTROL_NONE;

    if(ui.radioButtonControKB->isChecked())
        s = CONTROL_KB;
    if(ui.radioButtonControlNone->isChecked())
        s = CONTROL_NONE;
    if(ui.radioButtonControlJoy->isChecked())
        s = CONTROL_JOY;
    if(ui.radioButtonControlAuto->isChecked())
        s = CONTROL_AUTO;

    if(s != CONTROL_AUTO)
        rosThread->publishCommand("c stop");
    else
        rosThread->publishCommand("c ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-06-07 14:05:02 -0500

updated 2016-06-07 14:06:35 -0500

It looks like you are introducing some code in .h files that are included in different .cpp files. In .h files you only have to put definitions and forward declarations. The code goes inside the cpp files. Otherwise the assemble code of the code will be duplicated in different object files (generated from cpp files)

May be the problem in "HelperFunctions.h" or "PingThread.h"??

where are located functions like this? tum_ardrone_gui::setCountsSignal(unsigned int, unsigned int, unsigned int, unsigned int)

edit flag offensive delete link more

Comments

Thx for helping. In tum_ardrone_gui.h I will post it.

Geaper gravatar imageGeaper ( 2016-06-07 14:27:08 -0500 )edit

Already posted it.

Geaper gravatar imageGeaper ( 2016-06-07 14:28:54 -0500 )edit

you must not add code into any .h, only definitions. Is the cpp code you showed part of the tum_ardrone_gui.h?

Pablo Iñigo Blasco gravatar imagePablo Iñigo Blasco ( 2016-06-07 15:36:41 -0500 )edit

Everything works perfectly if I compile only one UINode. I just copy-pasted and renamed another folder to UINode2. But I cant compile UINode and UINode2 because it gives me the error above. tum_ardrone_gui.h is the header file. It only declares functions

Geaper gravatar imageGeaper ( 2016-06-07 18:35:38 -0500 )edit

It is hard to say what you have to say if we do not see the whole code and the cmake files and the contents of all the files you use. Anyhow what I can tell you is that your problem is a very typical linking problem in C++ project and it can essentially be solved through the guidelines I told you.

Pablo Iñigo Blasco gravatar imagePablo Iñigo Blasco ( 2016-06-08 12:33:33 -0500 )edit

Maybe I can give you the code and u fix it? I can pay via paypal. Thank you.

Geaper gravatar imageGeaper ( 2016-06-08 14:07:28 -0500 )edit

I can fix it, if it is easy to do I will do it just for help. You can find my contact in my linkedin webpage in my profile.

Pablo Iñigo Blasco gravatar imagePablo Iñigo Blasco ( 2016-06-08 14:10:51 -0500 )edit

Thank you. Anyhow I would like to pay you if u fix it. :D

Geaper gravatar imageGeaper ( 2016-06-08 14:20:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-07 13:55:51 -0500

Seen: 131 times

Last updated: Jun 07 '16