View Full Version : QT Application gives Multiple Definition Link Error

6th April 2011, 08:24
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 \
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)'

6th April 2011, 08:50
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.

6th April 2011, 08:59
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);

6th April 2011, 10:41
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?

10th March 2015, 04:52
I am a developer of barcode reader (http://www.businessrefinery.com/products/barcode_reader_net/barcodes/data-matrix.html) of datamatrix (http://businessrefinery.com/knowledge/data_matrix.html).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

#ifndef DATE_H
#define DATE_H

#include <string>

/* A class representing an earth day.*/

class Date{

/*construct a new day, initially assigned at Jan.1st.2000*/

/* take three numbers to create the date.*/
Date(int cmonth,int cday, int cyear);

/*clean up memory allocated to this data type*/

int year;
int month;
int day;

#endif // DATE_H
And this is the Cpp file.

#include "date.h"


Date::Date(int cmonth,int cday, int cyear){

/*clean up memory allocated to this data type*/
Sample Error Message: D:samplepath\date.cpp:3: error: multiple definition of `Date::Date()'

One possible main cpp that could induce the error (basically anything):

#include <iostream>
using namespace std;

int main() {
int sum=0;
return 0;
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.

SOURCES += $$files($$PWD/*.cpp)\
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.