programming: compiling qt4 on raspi(2) ( troubleshooting )

preview_player
Показать описание
@undefined reference to QApplication
solved by: building on raspberry pi directly instead of cross compile

@virtual call inside the ctor and dtor
2. compiling that newly generated cpp file
3. add this moc.o to the linking list

@makfile: IMPORTANT:
always put one TAB in front of a command. Saves you 30 minutes google


@Qt5 to Qt4 "conversion":
- change "QStringLiteral" into "QString::fromUtf8" (inside the ui_* file ( files created from the qt gui to create the gui))
- create a symbolic link: sudo ln -s /usr/include/qt4/QtGui /usr/include/qt4/QtWidgets

- I didn't need to use qmake

- Tutorial I was using:
For the first steps I did:
site, that explains crazy makefile stuff like $MMM:

makefile content:
IMPORTANT: I replace the sharp open bracket with MMM, as they are not allowed on youtube
##############################################################
##############################################################
##############################################################
TEMPLATE = app
#TARGET = qmakefile
DEPENDPATH += .
INCLUDEPATH += .
QT += core gui

CXX=arm-linux-gnueabihf-g++

INCLUDEDIR = ./
INCLUDEDIR += /usr/include/qt4/
INCLUDEDIR += /usr/include/qt4/QtGui
INCLUDEDIR += /usr/include/qt4/Qt
INCLUDEDIR += /usr/include/qt4/QtCore
INCLUDEDIR += /usr/include/qt4/QtCor

LIBRARYDIR = /usr/lib/arm-linux-gnueabihf
LIBRARYDIR +=/usr/local/lib
LIBRARY += QtCore QtGui
XLINK_LIBDIR = /lib/arm-linux-gnueabihf
#XLINK_LIBDIR += /usr/local/lib
XLINK_LIBDIR += /usr/lib/arm-linux-gnueabihf
#XLINK_LIBDIR += /usr/local/lib/

INCDIR = $(patsubst %,-I%,$(INCLUDEDIR))
LIBDIR = $(patsubst %,-L%,$(LIBRARYDIR))
LIB = $(patsubst %,-l%,$(LIBRARY))
XLINKDIR = $(patsubst %,-Xlinker -rpath-link=%,$(XLINK_LIBDIR))
CPPSTD = -std=c++11
OPT = -O0
DEBUG = -g
WARN= -Wall
PTHREAD= -lpthread
#GPIO = -lwiringPi
QTGUI = -lQtGui
#QTNETWORK = -lQtNetwork
QTCORE = -lQtCore
QT += core gui widget
QT += opengl

CXXFLAGS= $(OPT) $(DEBUG) $(WARN) $(INCDIR) $(CPPSTD)
LDFLAGS= $(LIBDIR) $(LIB) $(XLINKDIR) $(PTHREAD) # $(QTNETWORK) $(GPIO) $(CPPSTD)

#INC = qttest.h

EXECUTABLE = executable

# OBJ = $(SRC:.cpp=.o) $(INC:.h=.moc.o)

#all: $(OBJ)
# $(CXX) $(LDFLAGS) $(OBJ) -o $(EXECUTABLE )

#### compiling every file per hand ####
NPD=numberplacedoc
NPV=numberplaceview

OBJ_FILES = $(NPD).o $(NPV).o main.o $(NPV).moc.o

all: $(OBJ_FILES)
$(CXX) $(LDFLAGS) $(OBJ_FILES) -o $(EXECUTABLE)

$(NPD).o: $(NP_CPP) $(NPD).h
$(CXX) $(CXXFLAGS) $(NPD).cpp -c

$(NPV).o: $(NPV).cpp $(NPV).h
$(CXX) $(CXXFLAGS) $(NPV).cpp -c

#################

# original content
# $@ = The file name of the target of the rule
# $% = target name, if target is archive member
# $MMM = The name of the first prerequisite. - normalerweise steht als erstes die cpp datei, deswegen kann das als input-datei parameter benutzt werden
# $? = The names of all the prerequisites that are newer than the target
# moc-qt4 $MMM -o $@ #$@ = target-file
#%.o: %.cpp
# $(CXX) $(CXXFLAGS) -c $MMM

# remove:
# - all object files
# - all files, that end with ~ (backupfiles on emacs)
# - the executable itself
# - "\" tells, that rm should not complain about anything
# if "clean" exists as a file, this code might be break, because the
# target should actually be a file(?)
# call: "make clean" for using this:
clean:
\rm *.o $(EXECUTABLE)

##############################################################
##############################################################
##############################################################
Рекомендации по теме
visit shbcf.ru