LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2009, 11:50 AM   #1
echelon89
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
"Multiple definition of" and "undefined reference to" in QT Creator with QJson lib


Hi!
I'm new to Qt and I am trying to use the QJson Library.
I haven't compiled it, I've just imported QJson files in the QT Creator's project with "Add existing file" and added the
Code:
#include "json_driver.hh"
in my .h file.
Everything seems to be ok, but when I try to compile I get these errors:
Code:
Running build steps for project project...
Creating gdb macros library...
Configuration unchanged, skipping QMake step.
Starting: C:/Qt/2009.01/mingw/bin/mingw32-make.exe debug -w 
mingw32-make: Entering directory `C:/Documents and Settings/username/My Documents/project'
C:/Qt/2009.01/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Documents and Settings/username/My Documents/project'
Makefile.Debug:209: warning: overriding commands for target `debug/json_driver.o'
Makefile.Debug:172: warning: ignoring old commands for target `debug/json_driver.o'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2009.01\qt\include\QtCore" -I"c:\Qt\2009.01\qt\include\QtGui" -I"c:\Qt\2009.01\qt\include" -I"c:\Qt\2009.01\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2009.01\qt\mkspecs\win32-g++" -o debug\widget.o widget.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\decifratore.exe debug/main.o debug/widget.o debug/json_driver.o debug/jsonconverterthread.o debug/json_scanner.o debug/json_parser.o debug/json_driver.o debug/moc_widget.o debug/moc_jsonconverterthread.o  -L"c:\Qt\2009.01\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Documents and Settings/username/My Documents/project'
mingw32-make: Leaving directory `C:/Documents and Settings/username/My Documents/project'
debug/json_driver.o: In function `ZN10JSonDriverC2Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: multiple definition of `JSonDriver::JSonDriver()'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: first defined here
debug/json_driver.o: In function `ZN10JSonDriverC1Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: multiple definition of `JSonDriver::JSonDriver()'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: first defined here
debug/json_driver.o: In function `ZN10JSonDriverD2Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: multiple definition of `JSonDriver::~JSonDriver()'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: first defined here
debug/json_driver.o: In function `ZN10JSonDriverD1Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: multiple definition of `JSonDriver::~JSonDriver()'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: first defined here
debug/json_driver.o: In function `ZN10JSonDriverD0Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: multiple definition of `JSonDriver::~JSonDriver()'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: first defined here
debug/json_driver.o: In function `ZN10JSonDriver8setErrorE7QStringi':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:40: multiple definition of `JSonDriver::setError(QString, int)'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:40: first defined here
debug/json_driver.o: In function `ZN10JSonDriver5parseEP9QIODevicePb':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:47: multiple definition of `JSonDriver::parse(QIODevice*, bool*)'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:47: first defined here
debug/json_driver.o: In function `ZN10JSonDriver5parseERK7QStringPb':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:83: multiple definition of `JSonDriver::parse(QString const&, bool*)'
debug/json_driver.o:C:/Documents and Settings/username/My Documents/project/json_driver.cc:83: first defined here
debug/json_driver.o: In function `ZN10JSonDriverC2Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverC1Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverD2Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverD1Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverD0Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: undefined reference to `_imp___ZTV10JSonDriver'
debug/jsonconverterthread.o: In function `ZN19JSonConverterThread3runEv':
C:/Documents and Settings/username/My Documents/project/jsonconverterthread.cpp:37: undefined reference to `_imp___ZN10JSonDriverC1Ev'
C:/Documents and Settings/username/My Documents/project/jsonconverterthread.cpp:38: undefined reference to `_imp___ZN10JSonDriver5parseERK7QStringPb'
debug/json_parser.o: In function `ZN2yy11json_parser5errorERKNS_8locationERKSs':
C:/Documents and Settings/username/My Documents/project/json_parser.yy:201: undefined reference to `_imp___ZN10JSonDriver8setErrorE7QStringi'
debug/json_driver.o: In function `ZN10JSonDriverC2Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverC1Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:27: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverD2Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverD1Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: undefined reference to `_imp___ZTV10JSonDriver'
debug/json_driver.o: In function `ZN10JSonDriverD0Ev':
C:/Documents and Settings/username/My Documents/project/json_driver.cc:35: undefined reference to `_imp___ZTV10JSonDriver'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\decifratore.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project project
When executing build step 'Make'
widget.h and widget.cpp are mine.
Here's their code:

widget.h
Code:
#ifndef WIDGET_H
#define WIDGET_H

#include <QtGui>
#include <QVBoxLayout>

#include <QVariant>
#include "json_driver.hh"

namespace Ui
{
    class WidgetClass;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = 0);
    ~Widget();

private:
    QLineEdit *test;
...
private slots:
    void f();
...
};

#endif // WIDGET_H
widget.cpp
Code:
#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    test=new QLineEdit("\"Tmax\":\"24\",");
...
}
Widget::~Widget()
{

}

void Widget::f()
{
    QString str = test->text();
    JSonDriver driver;
    bool status;
    QVariantMap result = driver.parse(str, &status).toMap();
    if (status) {
        qFatal("An error occured during parsing");
        exit (1);
    }
    QMessageBox::about(this, tr("Test"), result["encoding"].toString());
}
Could you help me?

Thanks in advance

Last edited by echelon89; 04-30-2009 at 11:51 AM.
 
Old 05-01-2009, 06:48 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I've never worked with JSon, and I have very little experience with Qt, however it is possible that the issue is coming from your Makefile.

Can you please explain why json_driver.o appears twice in this statement?
Code:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\decifratore.exe debug/main.o debug/widget.o debug/json_driver.o debug/jsonconverterthread.o debug/json_scanner.o debug/json_parser.o debug/json_driver.o debug/moc_widget.o debug/moc_jsonconverterthread.o  -L"c:\Qt\2009.01\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
Also, other than json_driver.o, is it necessary to link all of the other JSon object files with your code?

Lastly, and this is no big deal, but if you are not using the JSonDriver in your widget.h header file, you really should move in the #include "json_driver.hh" statement to widget.cpp.
 
  


Reply

Tags
c++, compilation, cpp, definition, error, multiple, qt, reference, undefined



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't locate object method "splitpath" via package "PACK001" at /usr/lib/perl5/5.8.8/ sajigeorge Linux - Software 1 01-11-2009 06:33 AM
Can someone give me the definition of "Kernel Symbol" and "EXPORT_SYMBOL" ?? Raynus Programming 2 08-30-2008 07:19 PM
Undefined Screen " XFree86" reference by serverLayout "XFree86 Configured" comox *BSD 7 01-17-2005 05:47 PM
Compromised? Files "/usr/lib.hwm", "/usr/lib.pwd", "/usr/lib.pwi" Klaus Pforte Linux - Security 4 09-28-2004 11:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration