Results 1 to 5 of 5

Thread: QT Application gives Multiple Definition Link Error

  1. #1
    Join Date
    Apr 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation QT Application gives Multiple Definition Link Error

    Hi All,

    I am working on a nokia qt appliation development which uses zxing library.
    zxing provides support for decoding both qrcode and data matrix codes.

    There are specific directories for qrcode and data matrix libraries but the problem is that both have the files with the same names.
    eg: zxing/datamatrix/Version.cpp \
    zxing/datamatrix/decoder/BitMatrixParser.cpp \
    zxing/datamatrix/decoder/DataBlock.cpp \
    zxing/datamatrix/decoder/DecodedBitStreamParser.cpp \
    zxing/datamatrix/decoder/Decoder.cpp \
    zxing/datamatrix/detector/Detector.cpp \
    and
    zxing/qrcode/Version.cpp \
    zxing/qrcode/decoder/BitMatrixParser.cpp \
    zxing/qrcode/decoder/DataBlock.cpp \
    zxing/qrcode/decoder/DecodedBitStreamParser.cpp \
    zxing/qrcode/decoder/Decoder.cpp \
    zxing/qrcode/detector/Detector.cpp \


    When I include both of the above folders path in .pro SOURCE += variable, i get multiple definition errors because the .o files generated for qrcode are having the same names as that of data matrix files.
    And thus i get multiple definition errors.
    I have tried using .pri file for and also tried playing around with OBJECTS_DIR qt variable but to no success.


    Can anyone please provide any help on this. How to separate these 2, and still be able to use both libraries?


    Example of the errors am getting:
    version.cpp:: error: multiple definition of `zxing::qrcode::ECB::ECB(int, int)'
    version.cpp:: error: multiple definition of `zxing::qrcode::ECB::ECB(int, int)'

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT Application gives Multiple Definition Link Error

    Why are you including source files in your project in the first place? Isn't this library organized as...a library? In that case, you only need the header files and the path to the compiled library - not the source files.

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT Application gives Multiple Definition Link Error

    If you are not going to change the sources of the library, don't include it in your project, compile it to two separate .dll or .lib and use it as it's meant to be used - as a library (headers + linked code);
    Last edited by stampede; 6th April 2011 at 08:00. Reason: SixDegrees was faster ;)

  4. #4
    Join Date
    Apr 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QT Application gives Multiple Definition Link Error

    Thank you for replies guys. The problem here is that zxing comes as the source code and not as a lib.
    Secondly, we have done some changes to the lib code as well, so as to currently make it work for QRCode.

    As per the options suggested by you guys, we should complile the lib code separately, but that in itself will require too many changes to the lib code.

    Isn't there any option available in QT where in i can specify the OBJECTS_DIR for qrcode related files to be different from those of data matrix related files?

  5. #5
    Join Date
    Feb 2015
    Posts
    2
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QT Application gives Multiple Definition Link Error

    I am a developer of barcode reader of datamatrix.I am a greenhand of QT applications and i met some problems.I have to come here for help.
    I was defining a simple class called "date" in C++. The IDE I'm using is QT creator. When I'm compiling, the compiler said that every function in this class has "multiple definition." Below is the Cpp and header file. Fisrt this is the header date.h
    Qt Code:
    1. #ifndef DATE_H
    2. #define DATE_H
    3.  
    4. #include <string>
    5.  
    6. /* A class representing an earth day.*/
    7.  
    8. class Date{
    9.  
    10. public:
    11. /*construct a new day, initially assigned at Jan.1st.2000*/
    12. Date();
    13.  
    14. /* take three numbers to create the date.*/
    15. Date(int cmonth,int cday, int cyear);
    16.  
    17. /*clean up memory allocated to this data type*/
    18. ~Date();
    19.  
    20. private:
    21. int year;
    22. int month;
    23. int day;
    24. };
    25.  
    26. #endif // DATE_H
    To copy to clipboard, switch view to plain text mode 
    And this is the Cpp file.
    Qt Code:
    1. #include "date.h"
    2.  
    3. Date::Date(){
    4. year=2000;
    5. month=1;
    6. day=1;
    7. }
    8.  
    9. Date::Date(int cmonth,int cday, int cyear){
    10. month=cmonth;
    11. day=cday;
    12. year=cyear;
    13. }
    14.  
    15. /*clean up memory allocated to this data type*/
    16. Date::~Date(){
    17. //automatic
    18. }
    To copy to clipboard, switch view to plain text mode 
    Sample Error Message: D:samplepath\date.cpp:3: error: multiple definition of `Date:ate()'

    One possible main cpp that could induce the error (basically anything):
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3.  
    4. int main() {
    5. int sum=0;
    6. cout<<sum<<endl;
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 
    I've made sure that I avoided a few basic errors associated with this message, namely:

    I didn't put any implementation in the header.
    I used the #ifndef for protection
    I did a global search on keyword "date" and did not find any conflict.
    I always use a new build to compile

    Every function in this class have a "multiple definition of" error, but I can't tell what went wrong. Currently I'm doing an all-limb quadruple face palm. Any help would be greatly appreciated.

    Update: As it turns out, this is indeed a linker error. In the .pro file of Qtcreator, I included the source file twice with the following code.
    Qt Code:
    1. SOURCES += $$files($$PWD/*.cpp)\
    2.   date.cpp
    To copy to clipboard, switch view to plain text mode 
    The second line of code "data.cpp" was actually automatically added here by QTcreator, if you create the new class through its menu. Many thanks to all the guys here for your generous help.

Similar Threads

  1. qmake - multiple definition ?
    By zaphod77 in forum Installation and Deployment
    Replies: 3
    Last Post: 6th April 2011, 12:11
  2. multiple definition error - NokiaQtSDK maemo
    By raedbenz in forum Newbie
    Replies: 2
    Last Post: 21st July 2010, 08:03
  3. Multiple definition of a variable?
    By T0bi4s in forum Newbie
    Replies: 5
    Last Post: 14th January 2010, 22:13
  4. Replies: 3
    Last Post: 19th February 2008, 13:10
  5. Getting multiple definition error from qatomic_x86_64.h
    By markcole in forum General Programming
    Replies: 1
    Last Post: 30th August 2007, 19:39

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.