0

I am trying to build my c++ project using this make file :

CXX=g++  -std=c++11 
LD=g++
DEFINES       = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NO_VERSION_TAGGING
CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
CXXFLAGS      = -m64 -pipe -O2 -std=gnu++0x -Wall -W -D_REENTRANT -fPIC $(DEFINES)
INCPATH       = -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64
QMAKE         = /usr/lib/x86_64-linux-gnu/qt5/bin/qmake
DEL_FILE      = rm -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p
COPY          = cp -f
COPY_FILE     = cp -f
COPY_DIR      = cp -f -R
INSTALL_FILE  = install -m 644 -p
INSTALL_PROGRAM = install -m 755 -p
INSTALL_DIR   = cp -f -R
DEL_FILE      = rm -f
SYMLINK       = ln -f -s
DEL_DIR       = rmdir
MOVE          = mv -f
TAR           = tar -cf
COMPRESS      = gzip -9f
LINK          = g++
LFLAGS        = -m64 -Wl,-O1
LIBS          = $(SUBLIBS) -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread 
AR            = ar cqs
RANLIB        = 
SED           = sed
STRIP         = strip
LIBS= $(SUBLIBS) -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
INCPATH= -I. -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64
LDFLAGS=-Wall -fPIC -Wextra -O3 -fopenmp -L/usr/X11R6/lib -lX11 -lSDL -lrt -lpthread -lXft -L/usr/local/lib/mysql -lmysqlclient -lXpm  -L./ -lMyTestLicense
FREETYPE_CFLAGS=$(shell freetype-config --cflags )
FREETYPE_LDFLAGS=$(shell freetype-config --libs)

####### Output directory

OBJECTS_DIR   = ./

####### Files

SOURCES=$(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=test
QMAKE_TARGET  = test
DESTDIR       = 
TARGET        = test



####### Build rules

$(TARGET):  $(OBJECTS)  
    $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)




all:$(EXECUTABLE)
$(EXECUTABLE):  $(OBJECTS)  
        $(LD)  $(FREETYPE_LDFLAGS) $(OBJECTS) $(LDFLAGS) -o $@
####### Compile

.cpp.o: 
    $(CXX) $(FREETYPE_CFLAGS)  $(CXXFLAGS)  $(INCPATH)  -c -Wno-write-strings -g  -fpermissive $< -o $@

clean: 
    rm -rf *o test

i did not try to create make file using qmake because of special library that i need in my own project, So i decided to write my own makefile, and this is the only class(testmain.cpp) in my source code that i use QT library in it,thi is testmain.cpp:

#include <QtWidgets>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QWidget qWin;
    QGridLayout qGrid;
    qGrid.addWidget(new QLabel("UTF-8:"), 1, 0);
    QByteArray string = "شهاب حسینی";
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QString encodedString = codec->toUnicode(string);  
    qGrid.addWidget(new QLabel(encodedString), 1, 1);
    qWin.setLayout(&qGrid);
    qWin.show();

    return app.exec();
}

but when I try to make my project ,executable test will not produce and i face with this errors which part of my make file is wrong ?

> In function `QTypedArrayData<char>::deallocate(QArrayData*)':
> /usr/include/x86_64-linux-gnu/qt5/QtCore/qarraydata.h:222: undefined
> reference to `QArrayData::deallocate(QArrayData*, unsigned long,
> unsigned long)' testmain.o: In function `QTypedArrayData<unsigned
> short>::deallocate(QArrayData*)':
> /usr/include/x86_64-linux-gnu/qt5/QtCore/qarraydata.h:222: undefined
> reference to `QArrayData::deallocate(QArrayData*, unsigned long,
> unsigned long)' 
Unix2000
  • 41
  • 6
  • You can create a simple .pro file, run qmake once to generate the Makefile and then modify it for your needs. But to be honest, I don't really understand why you need it. Why don't you want to extend the qmake project file for your needs? Or use cmake? It will be much easier to use and maintain. – jubnzv Feb 27 '21 at 13:04
  • I tried your advice and created a make file with this .pro file : TEMPLATE = app TARGET = test INCLUDEPATH += . QT += widgets # Input SOURCES += *.cpp, and change it with my libraries , again i face whith this errors : undefined reference to `QApplication::QApplication(int&, char**, int)' – Unix2000 Feb 27 '21 at 13:24
  • Hmm, I tried your .pro file with a source code from your post. It builds well, but without any modifications. So, probably, the problem is in your changes in Makefile. Try to change generated Makefile gradually, e.g. check that each change does not break the build. – jubnzv Feb 27 '21 at 13:44
  • I have other classes so i need other libraries for example i should have : $(CXX) $(FREETYPE_CFLAGS) $(CXXFLAGS) $(INCPATH) -c -Wno-write-strings -g -fpermissive -o sample1.o sample1.cpp – Unix2000 Feb 27 '21 at 13:49
  • You can add libraries to qmake project file using LIBS and INCLUDEPATH https://stackoverflow.com/a/31246360/2079189 – mugiseyebrows Feb 28 '21 at 12:47

0 Answers0