The compiler in Qt Creator does not support c++11. So in my .pro file I added QMAKE_CXXFLAGS += -std=c++11
So my .pro file now looks like this:
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
server.cpp \
Section.cpp \
mainwindow.cpp \
main2.cpp \
client.cpp \
Chapter.cpp \
Book.cpp
HEADERS += \
Year.h \
Term.h \
Student.h \
Section.h \
mainwindow.h \
Load.h \
List.h \
Course.h \
ContentManager.h \
client.h \
Chapter.h \
Book.h
OTHER_FILES += \
Makefile \
D2.pro.user
This is my makefile:
#############################################################################
# Makefile for building: D2
# Generated by qmake (2.01a) (Qt 4.8.1) on: Mon Nov 10 23:00:21 2014
# Project: D2.pro
# Template: app
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile D2.pro
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DQT_WEBKIT
CFLAGS = -pipe -g -Wall -W $(DEFINES)
CXXFLAGS = -pipe -std=c++11 -g -Wall -W $(DEFINES)
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I.
LINK = g++
LFLAGS =
LIBS = $(SUBLIBS)
AR = ar cqs
RANLIB =
QMAKE = /usr/bin/qmake-qt4
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
STRIP = strip
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp \
server.cpp \
Section.cpp \
mainwindow.cpp \
main2.cpp \
client.cpp \
Chapter.cpp \
Book.cpp
OBJECTS = main.o \
server.o \
Section.o \
mainwindow.o \
main2.o \
client.o \
Chapter.o \
Book.o
DIST = /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/common/gcc-base.conf \
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
/usr/share/qt4/mkspecs/common/g++-base.conf \
/usr/share/qt4/mkspecs/common/g++-unix.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/debug.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/declarative_debug.prf \
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf \
D2.pro
QMAKE_TARGET = D2
DESTDIR =
TARGET = D2
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$#" "$<"
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
{ test -n "$(DESTDIR)" && DESTDIR="$(DESTDIR)" || DESTDIR=.; } && test $$(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $$DESTDIR" -ex quit '$(TARGET)' && test -f $(TARGET).gdb-index && objcopy --add-section '.gdb_index=$(TARGET).gdb-index' --set-section-flags '.gdb_index=readonly' '$(TARGET)' '$(TARGET)' && rm -f $(TARGET).gdb-index || true
Makefile: D2.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \
/usr/share/qt4/mkspecs/common/linux.conf \
/usr/share/qt4/mkspecs/common/gcc-base.conf \
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf \
/usr/share/qt4/mkspecs/common/g++-base.conf \
/usr/share/qt4/mkspecs/common/g++-unix.conf \
/usr/share/qt4/mkspecs/qconfig.pri \
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
/usr/share/qt4/mkspecs/features/qt_functions.prf \
/usr/share/qt4/mkspecs/features/qt_config.prf \
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
/usr/share/qt4/mkspecs/features/default_pre.prf \
/usr/share/qt4/mkspecs/features/debug.prf \
/usr/share/qt4/mkspecs/features/default_post.prf \
/usr/share/qt4/mkspecs/features/declarative_debug.prf \
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \
/usr/share/qt4/mkspecs/features/warn_on.prf \
/usr/share/qt4/mkspecs/features/resources.prf \
/usr/share/qt4/mkspecs/features/uic.prf \
/usr/share/qt4/mkspecs/features/yacc.prf \
/usr/share/qt4/mkspecs/features/lex.prf \
/usr/share/qt4/mkspecs/features/include_source_dir.prf
$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile D2.pro
/usr/share/qt4/mkspecs/common/unix.conf:
/usr/share/qt4/mkspecs/common/linux.conf:
/usr/share/qt4/mkspecs/common/gcc-base.conf:
/usr/share/qt4/mkspecs/common/gcc-base-unix.conf:
/usr/share/qt4/mkspecs/common/g++-base.conf:
/usr/share/qt4/mkspecs/common/g++-unix.conf:
/usr/share/qt4/mkspecs/qconfig.pri:
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri:
/usr/share/qt4/mkspecs/features/qt_functions.prf:
/usr/share/qt4/mkspecs/features/qt_config.prf:
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/share/qt4/mkspecs/features/default_pre.prf:
/usr/share/qt4/mkspecs/features/debug.prf:
/usr/share/qt4/mkspecs/features/default_post.prf:
/usr/share/qt4/mkspecs/features/declarative_debug.prf:
/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf:
/usr/share/qt4/mkspecs/features/warn_on.prf:
/usr/share/qt4/mkspecs/features/resources.prf:
/usr/share/qt4/mkspecs/features/uic.prf:
/usr/share/qt4/mkspecs/features/yacc.prf:
/usr/share/qt4/mkspecs/features/lex.prf:
/usr/share/qt4/mkspecs/features/include_source_dir.prf:
qmake: FORCE
#$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile D2.pro
dist:
#$(CHK_DIR_EXISTS) .tmp/D21.0.0 || $(MKDIR) .tmp/D21.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/D21.0.0/ && (cd `dirname .tmp/D21.0.0` && $(TAR) D21.0.0.tar D21.0.0 && $(COMPRESS) D21.0.0.tar) && $(MOVE) `dirname .tmp/D21.0.0`/D21.0.0.tar.gz . && $(DEL_FILE) -r .tmp/D21.0.0
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) Makefile
check: first
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
####### Compile
main.o: main.cpp Course.h \
Year.h \
Term.h \
Student.h \
ContentManager.h \
Book.h \
List.h \
Chapter.h \
Section.h \
Load.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
server.o: server.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o server.o server.cpp
Section.o: Section.cpp Section.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Section.o Section.cpp
mainwindow.o: mainwindow.cpp mainwindow.h \
client.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
main2.o: main2.cpp mainwindow.h \
client.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main2.o main2.cpp
client.o: client.cpp client.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o client.o client.cpp
Chapter.o: Chapter.cpp Chapter.h \
List.h \
Section.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Chapter.o Chapter.cpp
Book.o: Book.cpp Book.h \
List.h \
Chapter.h \
Section.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Book.o Book.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
Unfortunately, I'm getting this error: [main.o] Error 1
This error was non-existent before adding c++11. I can't solve this problem. Can someone please help me here?
UPDATE:
Typing in gcc -v in the command line in Qt creator gave me:
Starting command 'gcc -v'
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
'gcc -v' finished
I think the compiler version is 4.6.3, which means it supports C++11
There's more to that error message than just [main.o] Error 1. Paste the whole error message.
However, some guesses as to your problem might include:
You use both $(OBJCOMP) and $(SUBLIBS) in your linker command, but neither of them is defined anywhere. Could this be the cause of the error?
Some old versions of g++ (for example, 4.6.3) spell the option -std=c++0x instead of -std=c++11. Depending on the output of g++ --version, you might need to use the older spelling.
You might need to add -std=c++11 to the LFLAGS as well as to the CXXFLAGS, to make sure that you're linking against the correct C++ library. (I don't know of any systems for which this matters, but I always try to get it right anyway.)
I got this error a few times as well.
I was frankly amazed at the lack of information in the error message, well, I mean, there is basically none.
Here is my interpretation of what the erro means:
main.o doesn't exist / can't be found / is entirely broken.
There are a few ways you could've ended up in this situation:
Location where main.o is supposed to be written is write protected. (You could try toggling shadowbuild in Qt creator)
You're out of space (I know, sounds absurd with 8TB HDDs on the market. This was what was happening for me tho.)
Your project is ill configured. (Sometimes there is a difference between / and \ in paths)
Your compiler is ill configured.
There is something very wrong with your code.
Unfortunately, I'm getting this error: [main.o] Error 1
.....
Believe me, that was the only error. I tried all your suggestions but none could solve the problem, unfortunately
Interestingly, Qt Creator does not remove your project's Makefile even if you do Cleaning and Rebuilding.
Those options does remove your output binary files (including .o files), but sometimes it can't be sufficient especially when you're editing the .pro file or .qrc file.
In most cases where the build error message is unclear and it's claimed, "Well it just worked before!" it's worth trying making sure that you're building it completely from the scratch all the way through by:
Going to your build directory such as:
../build-*
Deleting all relevant Makefile scripts and others if necessary,
Then re-building it again.
Related
This is my makefile in linux
.SILENT:
.SUFFIXES: .cpp
FLAGS_CC = -c -fPIC -DUNIX -DLINUX -D_HNAREL_=500 -D_TARGET__REL=0 -D_TARGET__DEBUG=1 -D_ILS_MACROS -I$(cer_incl)
FLAGS_CPP = -c -Wno-deprecated -fPIC -frtti -finline-functions -DUNIX -DLINUX -D_HNAREL_=500 -D_TARGET__REL=0 -D_TARGET__DEBUG=1 -D_ILS_MACROS -I$(cer_incl)
FLAGS_LINK = -m32 -fPIC -lm -lc -lrt -lpthread -ldl
FLAGS_LINKSHR = -m32 -lm -lc -shared -Wl,-no-undefined -lrt -lpthread -ldl
CC = gcc $(FLAGS_CC) $(__define) $(__build)
CPP = g++ $(FLAGS_CPP) $(__define) $(__build)
LINK = g++ $(FLAGS_LINK)
LINKSHR = g++ $(FLAGS_LINKSHR)
PRINT = echo
##
## The following environment variables are defined for your convenience.
##-----
## __srcdir - Project directory that contains the makefile and source code.
## __objdir - Project subdirectory that stores objects for the given platform
## and target combination.
## __libdir - Public directory that contains objects and shareable libraries.
## __exedir - Public directory that contains executables.
##-----
## Please do not delete the following line!
###makefile###
###makedep###
#my_project.o
FLAGS__MY_PROJECT =
DEFINES__MY_PROJECT =
my_project.o: $(__objdir)/my_project.o
$(__objdir)/my_project.o: \
my_project.cpp \
$(cer_incl)/srvimpl.h \
$(PRINT) "compiling - my_project.cpp"
[[ -d $(__objdir) ]] || mkdir -p $(__objdir)
$(CPP) $(FLAGS__MY_PROJECT) $(DEFINES__MY_PROJECT) -o $(__objdir)/my_project.o my_project.cpp
#aps_s200061.o
FLAGS__APS_S200061 =
DEFINES__APS_S200061 =
aps_s200061.o: $(__objdir)/aps_s200061.o
$(__objdir)/aps_s200061.o: \
aps_s200061.cpp \
aps_s200061.h \
$(cer_incl)/srvimpl.h \
$(PRINT) "compiling - aps_s200061.cpp"
[[ -d $(__objdir) ]] || mkdir -p $(__objdir)
$(CPP) $(FLAGS__APS_S200061) $(DEFINES__APS_S200061) -o $(__objdir)/aps_s200061.o aps_s200061.cpp
###makedep###
FLAGS_CPP += -D__RHEL6
FLAGS__APS_S200061 =
objects: my_project.o aps_s200061.o
my_project : objects
$(PRINT) "creating - my_project "
$(LINKSHR) \
-Wl,--version-script=$(__srcdir)/my_project.emap \
-o $(__objdir)/my_project \
$(__objdir)/my_project.o \
$(__objdir)/aps_s200061.o \
-Wl,--start-group \
-L$(__libdir) -lapsobj -lcernobj -lcontainerobj -lstringobj -li18n_common -lmsgutilobj -lmftmiscobj -lsrvcoreobj -lcrmobj -lthreadobj \
-Wl,--whole-archive -lsrvobj -Wl,--no-whole-archive \
-Wl,--end-group \
-L$(__exedir) -ldb -ldps -lsrv -lsec \
-lcclora -lreg -lmsgapi -ldate \
-llogical -lsrvcore -lcrm
copy:
$(PRINT) "copying - my_project"
cp $(__objdir)/my_project $(__exedir)
it: my_project copy
# shr:my_project
I want to remove the command cp $(__objdir)/my_project $(__exedir) from the above file.
When I try removing the line manually in a text editor and save it , the make file doesn't throw any errors.
But if I try removing the line programmatically , we get make: *** No rule to make target my_project.o', needed by objects'. Stop.
Sequence of commands we use is :
'makedep'
'make -f ${PWD##*/}.linux -r __target=rel _define="-D_TARGET=_TARGET__REL " __srcdir=$PWD __objdir=$PWD/linuxx86-64 __libdir=$abc_lib_rel __exedir=$abc_exe_rel __build="-O3" it'
I'm trying to compile a basic Qt program:
#include <iostream>
#include <QApplication>
int main(int argc, char** argv) {
QApplication app(argc, argv);
std::cout << "test" << std::endl;
}
To start a Qt-project I did the following:
Make a project.pro file:
TEMPLATE += app
QT += widgets gui
SOURCES += main.cpp
Run the qmake command.
Edit the following in the generated Makefile:
-mmacosx-version-min=10.15.3 in CXXFLAGS
remove the -c argument from the compiler
Than I ran make and got the following error output:
/Library/Developer/CommandLineTools/usr/bin/clang++ -pipe -stdlib=libc++ -O2 -std=gnu++11 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.15.3 -Wall -Wextra -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I/usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers -I/usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Headers -I. -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.14.1/lib -o main.o main.cpp
Undefined symbols for architecture x86_64:
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in main-96fd09.o
"QApplication::~QApplication()", referenced from:
_main in main-96fd09.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main.o] Error 1
I might have an idea what is causing this, when running make -v I get this output:
This program built for i386-apple-darwin11.3.0
clang++ --version generates this output:
Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
I think the Makefile is trying to compile my code for an older architecture and that's generating a conflict but I'm not sure. My system is a Macbook Pro running MacOS Catalina 10.15.3. Qt is version 15.4.1. Qmake is version 3.1.
Full Makefile:
#############################################################################
# Makefile for building: test.app/Contents/MacOS/test
# Generated by qmake (3.1) (Qt 5.14.1)
# Project: test.pro
# Template: app
# Command: /usr/local/Cellar/qt/5.14.1/bin/qmake -o Makefile test.pro
#############################################################################
MAKEFILE = Makefile
EQ = =
####### Compiler, tools and options
CC = /Library/Developer/CommandLineTools/usr/bin/clang
CXX = /Library/Developer/CommandLineTools/usr/bin/clang++
DEFINES = -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS = -pipe -O2 $(EXPORT_ARCH_ARGS) -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wall -Wextra -fPIC $(DEFINES)
CXXFLAGS = -pipe -stdlib=libc++ -O2 -std=gnu++11 $(EXPORT_ARCH_ARGS) -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.15.3 -Wall -Wextra -fPIC $(DEFINES)
INCPATH = -I. -I/usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers -I/usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Headers -I/usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Headers -I. -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang -F/usr/local/Cellar/qt/5.14.1/lib
QMAKE = /usr/local/Cellar/qt/5.14.1/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
QINSTALL = /usr/local/Cellar/qt/5.14.1/bin/qmake -install qinstall
QINSTALL_PROGRAM = /usr/local/Cellar/qt/5.14.1/bin/qmake -install qinstall -exe
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
TAR = tar -cf
COMPRESS = gzip -9f
DISTNAME = test1.0.0
DISTDIR = /Users/myName/School/C++/QtTest/.tmp/test1.0.0
LINK = /Library/Developer/CommandLineTools/usr/bin/clang++
LFLAGS = -stdlib=libc++ -headerpad_max_install_names $(EXPORT_ARCH_ARGS) -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wl,-rpath,#executable_path/../Frameworks
LIBS = $(SUBLIBS) -F/usr/local/Cellar/qt/5.14.1/lib -framework QtWidgets -framework QtGui -framework AppKit -framework Metal -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
AR = /Library/Developer/CommandLineTools/usr/bin/ar cq
RANLIB = /Library/Developer/CommandLineTools/usr/bin/ranlib -s
SED = sed
STRIP = strip
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES = main.cpp
OBJECTS = main.o
DIST = /usr/local/Cellar/qt/5.14.1/mkspecs/features/spec_pre.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/qdevice.pri \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/device_config.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/common/unix.conf \
/usr/local/Cellar/qt/5.14.1/mkspecs/common/mac.conf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/mac/rez.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/mac/asset_catalogs.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/testcase_targets.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/exceptions.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/yacc.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/lex.prf \
MORE FILES HERE
test.pro main.cpp
QMAKE_TARGET = test
DESTDIR =
TARGET = test.app/Contents/MacOS/test
####### Custom Variables
EXPORT_QMAKE_MAC_SDK = macosx
EXPORT_QMAKE_MAC_SDK_VERSION = 10.15.1
EXPORT_QMAKE_XCODE_DEVELOPER_PATH = /Library/Developer/CommandLineTools
EXPORT_VALID_ARCHS = x86_64
EXPORT_ACTIVE_ARCHS = $(filter $(EXPORT_VALID_ARCHS), $(ARCHS))
EXPORT_ARCH_ARGS = $(foreach arch, $(if $(EXPORT_ACTIVE_ARCHS), $(EXPORT_ACTIVE_ARCHS), $(EXPORT_VALID_ARCHS)), -arch $(arch))
EXPORT__PRO_FILE_ = /Users/myName/School/C++/QtTest/test.pro
include /usr/local/Cellar/qt/5.14.1/mkspecs/features/mac/sdk.mk
first: all
####### Build rules
test.app/Contents/MacOS/test: $(OBJECTS)
#test -d test.app/Contents/MacOS/ || mkdir -p test.app/Contents/MacOS/
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: test.pro /usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang/qmake.conf /usr/local/Cellar/qt/5.14.1/mkspecs/features/spec_pre.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/qdevice.pri \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/device_config.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/common/unix.conf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/exceptions.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/yacc.prf \
/usr/local/Cellar/qt/5.14.1/mkspecs/features/lex.prf \
test.pro \
/usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Resources/QtWidgets.prl \
/usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Resources/QtGui.prl \
/usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Resources/QtCore.prl
MORE FILES HERE
$(QMAKE) -o Makefile test.pro
/usr/local/Cellar/qt/5.14.1/mkspecs/features/spec_pre.prf:
/usr/local/Cellar/qt/5.14.1/mkspecs/qdevice.pri:
/usr/local/Cellar/qt/5.14.1/mkspecs/features/device_config.prf:
/usr/local/Cellar/qt/5.14.1/mkspecs/common/unix.conf:
/usr/local/Cellar/qt/5.14.1/mkspecs/common/mac.conf:
/usr/local/Cellar/qt/5.14.1/mkspecs/features/lex.prf:
test.pro:
/usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Resources/QtWidgets.prl:
/usr/local/Cellar/qt/5.14.1/lib/QtGui.framework/Resources/QtGui.prl:
/usr/local/Cellar/qt/5.14.1/lib/QtCore.framework/Resources/QtCore.prl:
MORE FILES HERE
qmake: FORCE
#$(QMAKE) -o Makefile test.pro
qmake_all: FORCE
test.app/Contents/PkgInfo:
#test -d test.app/Contents || mkdir -p test.app/Contents
#$(DEL_FILE) test.app/Contents/PkgInfo
#echo "APPL????" > test.app/Contents/PkgInfo
test.app/Contents/Resources/empty.lproj:
#test -d test.app/Contents/Resources || mkdir -p test.app/Contents/Resources
#touch test.app/Contents/Resources/empty.lproj
test.app/Contents/Info.plist:
#test -d test.app/Contents || mkdir -p test.app/Contents
#$(DEL_FILE) test.app/Contents/Info.plist
#sed -e "s,#SHORT_VERSION#,1.0,g" -e "s,\$${QMAKE_SHORT_VERSION},1.0,g" -e "s,#FULL_VERSION#,1.0.0,g" -e "s,\$${QMAKE_FULL_VERSION},1.0.0,g" -e "s,#TYPEINFO#,????,g" -e "s,\$${QMAKE_PKGINFO_TYPEINFO},????,g" -e "s,#BUNDLEIDENTIFIER#,com.yourcompany.test,g" -e "s,\$${PRODUCT_BUNDLE_IDENTIFIER},com.yourcompany.test,g" -e "s,\$${MACOSX_DEPLOYMENT_TARGET},10.13,g" -e "s,\$${IPHONEOS_DEPLOYMENT_TARGET},,g" -e "s,\$${TVOS_DEPLOYMENT_TARGET},,g" -e "s,\$${WATCHOS_DEPLOYMENT_TARGET},,g" -e "s,#ICON#,,g" -e "s,\$${ASSETCATALOG_COMPILER_APPICON_NAME},,g" -e "s,#EXECUTABLE#,test,g" -e "s,#LIBRARY#,test,g" -e "s,\$${EXECUTABLE_NAME},test,g" -e "s,#TYPEINFO#,????,g" -e "s,\$${QMAKE_PKGINFO_TYPEINFO},????,g" /usr/local/Cellar/qt/5.14.1/mkspecs/macx-clang/Info.plist.app >test.app/Contents/Info.plist
all: Makefile \
test.app/Contents/PkgInfo \
test.app/Contents/Resources/empty.lproj \
test.app/Contents/Info.plist test.app/Contents/MacOS/test
dist: distdir FORCE
(cd `dirname $(DISTDIR)` && $(TAR) $(DISTNAME).tar $(DISTNAME) && $(COMPRESS) $(DISTNAME).tar) && $(MOVE) `dirname $(DISTDIR)`/$(DISTNAME).tar.gz . && $(DEL_FILE) -r $(DISTDIR)
distdir: FORCE
#test -d $(DISTDIR) || mkdir -p $(DISTDIR)
$(COPY_FILE) --parents $(DIST) $(DISTDIR)/
$(COPY_FILE) --parents /usr/local/Cellar/qt/5.14.1/mkspecs/features/data/dummy.cpp $(DISTDIR)/
$(COPY_FILE) --parents main.cpp $(DISTDIR)/
clean: compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
distclean: clean
-$(DEL_FILE) -r test.app
-$(DEL_FILE) .qmake.stash
-$(DEL_FILE) Makefile
####### Sub-libraries
xcodeproj:
#$(QMAKE) -spec macx-xcode "$(EXPORT__PRO_FILE_)"
mocclean: compiler_moc_header_clean compiler_moc_objc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_objc_header_make_all compiler_moc_source_make_all
check: first
benchmark: first
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_moc_predefs_make_all: moc_predefs.h
compiler_moc_predefs_clean:
-$(DEL_FILE) moc_predefs.h
moc_predefs.h: /usr/local/Cellar/qt/5.14.1/mkspecs/features/data/dummy.cpp
/Library/Developer/CommandLineTools/usr/bin/clang++ -pipe -stdlib=libc++ -O2 -std=gnu++11 $(EXPORT_ARCH_ARGS) -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -mmacosx-version-min=10.13 -Wall -Wextra -dM -E -o moc_predefs.h /usr/local/Cellar/qt/5.14.1/mkspecs/features/data/dummy.cpp
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_moc_objc_header_make_all:
compiler_moc_objc_header_clean:
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_rez_source_make_all:
compiler_rez_source_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean: compiler_moc_predefs_clean
####### Compile
main.o: main.cpp /usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers/QApplication \
/usr/local/Cellar/qt/5.14.1/lib/QtWidgets.framework/Headers/qapplication.h
$(CXX) $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
Thanks!
I made a very basic mistake. Everything was working, but the Makefile outputted a main.o file. I tried to execute my application by using ./main.o. This is not possible.
The correct way to execute a Qt application is by using open main.app.
No need to alter the makefile.
Create a myApp.pro file
Example:
TEMPLATE += app
QT += widgets gui
SOURCES += myApp.cpp
Execute qmake
Execute make
Execute open myApp.app
I need to compile a C++ project which is going to use external libraries and headers from the project for linear programming COIN-OR. It contains two .cpp files. The main file, main-farmer, depends on pm.h.
pm.h has all the include lines main-farmer needs to use to call in the COIN-OR functions. This is is the code of pm.h:
#include "ClpSimplex.hpp"
#include "CoinHelperFunctions.hpp"
#include "CoinTime.hpp"
#include "CoinBuild.hpp"
#include "CoinModel.hpp"
I have a makefile provided by my teacher and modified to fit my own needs, but whenever I try to compile the project by running my Makefile I get the same error:
In file included from main-farmer.cpp:5:0: pm.h:14:26: fatal error:
ClpSimplex.hpp: No such file or directory compilation terminated.
make: *** [main-farmer.o] Error 1
This is the Makefile:
#
P=farmer
#
EXE=$(P)
OBJS=main-farmer.o model-farmer.o param-farmer.o pm.h
ADDLIBS=-D.
ADDINCFLAGS=-I.
SRCDIR=~/coin-projects
##########
CXX=g++
CXXFLAGS=-O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion
CXXLINKFLAGS=-Wl,--rpath -Wl,/installed/CoinAll/lib
CC=gcc
CFLAGS=-03 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall
COININCDIR=/installed/CoinAll/include/coin
# COIN-OR libs
COINLIBDIR=/installed/CoinAll/lib
# Clp
LIBS=-L$(COINLIBDIR) -lCbc -lCgl -lOsiClp -lOsi -lClp -lCoinUtils -lm \
`cat $(COINLIBDIR)/cgl_addlibs.txt` \
`cat $(COINLIBDIR)/clp_addlibs.txt` \
`cat $(COINLIBDIR)/coinutils_addlibs.txt`
CLEANFILES=\
addBits.o addBits \
addColumns.o addColumns \
addRows.o addRows \
decompose.o decompose \
defaults.o defaults \
driver2.o driver2 \
driver.o driver \
driverC.o driverC \
dualCuts.o dualCuts \
ekk.o ekk \
ekk_interface.o ekk_interface \
hello.o hello \
makeDual.o makeDual \
minimum.o minimum \
network.o network \
piece.o piece \
rowColumn.o rowColumn \
sprint2.o sprint2 \
sprint.o sprint \
testBarrier.o testBarrier \
testBasis.o testBasis \
testGub2.o testGub2 \
testGub.o testGub \
testQP.o testQP \
useVolume.o useVolume
# Part 3
#
all: $(EXE)
.SUFFIXES: .cpp .c .o .obj
$(EXE): $(OBJS)
bla=;
for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $# $$bla $(ADDLIBS) $(LIBS)
####
########
############
########
####
clean:
rm -rf $(CLEANFILES)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $# `test -f '$<' || echo '$(SRCDIR)/'`$<
.cpp.obj:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $# `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
.c.o:
$(CC) $(CFLAGS) $(INCL) -c -o $# `test -f '$<' || echo '$(SRCDIR)/'`$<
.c.obj:
$(CC) $(CFLAGS) $(INCL) -c -o $# `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
Note: ClpSimplex.hpp lives in the directory specified as COININCDIR.
Your Makefile defines COININCDIR which probably points to the parent directory of your .hpp headers. Those need to be found by the compiler, and as the variable is not used, it explains why they are not found.
If you add -I$(COININCDIR) to CXXFLAGS, the compiler will be able to locate them.
When I use the Makefile in the examples folder of Pythia8185 I get an error (ME below!):
ME: This is mymain.cc
#include "Pythia8/Pythia.h" // Include Pythia headers.
using namespace Pythia8; // Let Pythia8:: be implicit.
int main() { // Begin main program.
// Set up generation.
Pythia pythia; // Declare Pythia object
pythia.readString("Top:gg2ttbar = on"); // Switch on process.
pythia.readString("Beams:eCM = 7000."); // 7 TeV CM energy.
pythia.init(); // Initialize; incoming pp beams is default.
// Generate event(s).
pythia.next(); // Generate an(other) event. Fill event record.
return 0;
} // End main program with error-free return.
This is the Makefile before edit:
#
# Examples Makefile.
#
# M. Kirsanov 07.04.2006
# Modified 18.11.2006
# 26.03.2008 CLHEP dependency removed
SHELL = /bin/sh
-include config.mk
ifeq (x$(PYTHIA8LOCATION),x)
PYTHIA8LOCATION=..
endif
-include $(PYTHIA8LOCATION)/config.mk
# Location of directories.
TOPDIR=$(shell \pwd)
INCDIR=include
SRCDIR=src
LIBDIR=lib
LIBDIRARCH=lib/archive
BINDIR=bin
# Libraries to include if GZIP support is enabled
ifeq (x$(ENABLEGZIP),xyes)
LIBGZIP=-L$(BOOSTLIBLOCATION) -lboost_iostreams -L$(ZLIBLOCATION) -lz
endif
# There is no default behaviour, so remind user.
all:
#echo "Usage: for NN = example number: make mainNN"
# Create an executable for one of the normal test programs
main00 main01 main02 main03 main04 main05 main06 main07 main08 main09 main10 \
main11 main12 main13 main14 main15 main16 main17 main18 main19 main20 \
main21 main22 main23 main24 main25 main26 main27 main28 main29 main30 \
main31 main32 main33 main34 main35 main36 main37 main38 main39 main40 \
main80: \
$(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8.a
#mkdir -p $(BINDIR)
$(CXX) $(CXXFLAGS) -I$(PYTHIA8LOCATION)/$(INCDIR) $#.cc -o $(BINDIR)/$#.exe \
-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) -lpythia8 -llhapdfdummy $(LIBGZIP)
#ln -fs $(BINDIR)/$#.exe $#.exe
# Create an executable linked to HepMC (if all goes well).
# Owing to excessive warning output -Wshadow is not used for HepMC.
ifneq (x$(HEPMCLOCATION),x)
main41 main42: \
$(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8.a $(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8tohepmc.a
#mkdir -p $(BINDIR)
$(CXX) $(CXXFLAGS) -Wno-shadow -I$(PYTHIA8LOCATION)/$(INCDIR) -I$(HEPMCLOCATION)/include \
$#.cc -o $(BINDIR)/$#.exe \
-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) -lpythia8 -llhapdfdummy $(LIBGZIP) \
-lpythia8tohepmc \
-L$(HEPMCLOCATION)/lib -lHepMC
#ln -fs $(BINDIR)/$#.exe $#.exe
else
main41 main42:
#echo ERROR, this target needs HepMC, variable HEPMCLOCATION
endif
# Create an executable that links to LHAPDF
main51 main52 main53 main54: $(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8.a
#mkdir -p $(BINDIR)
$(CXX) $(CXXFLAGS) -I$(PYTHIA8LOCATION)/$(INCDIR) $#.cc -o $(BINDIR)/$#.exe \
-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) -lpythia8 $(LIBGZIP) \
-L$(LHAPDFLOCATION) $(LHAPDFLIBNAME) \
$(FLIBS)
#ln -fs $(BINDIR)/$#.exe $#.exe
# Create an executable that links to LHAPDF and HepMC
main61 main62 main85 main86 main87 main88: \
$(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8.a $(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8tohepmc.a
#mkdir -p $(BINDIR)
$(CXX) $(CXXFLAGS) -Wno-shadow -I$(PYTHIA8LOCATION)/$(INCDIR) -I$(HEPMCLOCATION)/include \
$#.cc -o $(BINDIR)/$#.exe \
-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) -lpythia8 -lpythia8tohepmc $(LIBGZIP) \
-L$(LHAPDFLOCATION) $(LHAPDFLIBNAME) \
-L$(HEPMCLOCATION)/lib -lHepMC \
$(FLIBS)
#ln -fs $(BINDIR)/$#.exe $#.exe
# Create an executable that links to Fastjet
# Owing to excessive warning output -Wshadow is not used for Fastjet.
# (Fixed as of Fastjet 3.0.1, so will be modified eventually.)
ifneq (x$(FASTJETLOCATION),x)
main71 main72: $(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8.a
#mkdir -p $(BINDIR)
# Note: $(CXXFLAGS) is after Fastjet flags as Fastjet includes
# optimisation/debug flags which may be unwanted (e.g. -g -O2)
$(CXX) -I$(PYTHIA8LOCATION)/$(INCDIR) $#.cc \
`$(FASTJETLOCATION)/bin/fastjet-config --cxxflags --plugins` \
$(CXXFLAGS) -Wno-shadow \
-o $(BINDIR)/$#.exe \
-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) -lpythia8 -llhapdfdummy $(LIBGZIP) \
-L$(FASTJETLOCATION)/lib \
`$(FASTJETLOCATION)/bin/fastjet-config --libs --plugins`
#ln -fs $(BINDIR)/$#.exe $#.exe
#rm -f $#.o
else
main71 main72:
#echo ERROR, this target needs Fastjet, variable FASTJETLOCATION
endif
# Create an executable that links to Fastjet, HepMC and LHApdf
# Owing to excessive warning output -Wshadow is not used for Fastjet.
# (Fixed as of Fastjet 3.0.1, so will be modified eventually.)
ifneq (x$(FASTJETLOCATION),x)
main81 main82 main83 main84: \
$(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8.a $(PYTHIA8LOCATION)/$(LIBDIRARCH)/libpythia8tohepmc.a
#mkdir -p $(BINDIR)
# Note: $(CXXFLAGS) is after Fastjet flags as Fastjet includes
# optimisation/debug flags which may be unwanted (e.g. -g -O2)
$(CXX) -I$(PYTHIA8LOCATION)/$(INCDIR) $#.cc \
`$(FASTJETLOCATION)/bin/fastjet-config --cxxflags --plugins` \
$(CXXFLAGS) -Wno-shadow \
-I$(PYTHIA8LOCATION)/$(INCDIR) -I$(HEPMCLOCATION)/include \
-o $(BINDIR)/$#.exe \
-L$(PYTHIA8LOCATION)/$(LIBDIRARCH) -lpythia8 \
-L$(LHAPDFLOCATION) $(LHAPDFLIBNAME) \
-lpythia8tohepmc \
-L$(HEPMCLOCATION)/lib -lHepMC \
-L$(FASTJETLOCATION)/lib \
-L$(LHAPDFLOCATION)/lib \
`$(FASTJETLOCATION)/bin/fastjet-config --libs --plugins`
#ln -fs $(BINDIR)/$#.exe $#.exe
#rm -f $#.o
else
main81 main82 main83 main84:
#echo ERROR, this target needs Fastjet, variable FASTJETLOCATION
endif
# Clean up: remove executables and outdated files.
.PHONY: clean
clean:
rm -rf $(BINDIR)
rm -rf *.exe
rm -f *~; rm -f \#*; rm -f core*
After edit I add mymain: just after main80 and then I write make mymain and get the error as follows:
I edit the Makefile and add mymain to the list:
# Create an executable for one of the normal test programs
main00 main01 main02 main03 main04 main05 main06 main07 main08 main09 main10 \
main11 main12 main13 main14 main15 main16 main17 main18 main19 main20 \
main21 main22 main23 main24 main25 main26 main27 main28 main29 main30 \
main31 main32 main33 main34 main35 main36 main37 main38 main39 main40 \
main80 mymain: \
as suggested in the worksheet example page 4.
Then when I write make mymain in the Terminal I get the following error:
*** No rule to make target `../lib/archive/libpythia8.a', needed by `mymain'. Stop.
It should be noted that everything worked fine yesterday, I really don't know how to proceed. I deleted all pythia folders and untarred them again but the problem remains. Anyone know what the solution might be? I'm on a MacBook.
Is there a way to uninstall something like pythia completely and reinstall it? It seems some file in some cache is the problem
This question already has answers here:
Qt Linker Error: "undefined reference to vtable" [duplicate]
(9 answers)
Closed 8 years ago.
I am a beginner to Qt programming and use codeblocks for my programming. I created 3 files communicate.h,commmunicate.cpp and main.cpp as follows:
communicate.h
#ifndef COMMUNICATE_H
#define COMMUNICATE_H
#include <QWidget>
#include <QApplication>
#include <QPushButton>
#include <QLabel>
class Communicate : public QWidget
{
Q_OBJECT
public:
Communicate(QWidget *parent = 0);
private slots:
void OnPlus();
void OnMinus();
private:
QLabel *label;
};
#endif
communicate.cpp
#include "communicate.h"
Communicate::Communicate(QWidget *parent)
: QWidget(parent)
{
QPushButton *plus = new QPushButton("+", this);
plus->setGeometry(50, 40, 75, 30);
QPushButton *minus = new QPushButton("-", this);
minus->setGeometry(50, 100, 75, 30);
label = new QLabel("0", this);
label->setGeometry(190, 80, 20, 30);
connect(plus, SIGNAL(clicked()), this, SLOT(OnPlus()));
connect(minus, SIGNAL(clicked()), this, SLOT(OnMinus()));
}
void Communicate::OnPlus()
{
int val = label->text().toInt();
val++;
label->setText(QString::number(val));
}
void Communicate::OnMinus()
{
int val = label->text().toInt();
val--;
label->setText(QString::number(val));
}
main.cpp
#include "communicate.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Communicate window;
window.setWindowTitle("Communicate");
window.show();
return app.exec();
}
and its showing errors as follows:
obj\Debug\main.o(.text$_ZN11CommunicateD1Ev[Communicate::~Communicate()]+0xb)||In function `ZN7QStringC1EPKc':|
C:\Qt\4.4.3\include\QtCore\..\..\src\corelib\arch\qatomic_windows.h||undefined reference to `vtable for Communicate'|
obj\Debug\main.o(.text$_ZN11CommunicateD1Ev[Communicate::~Communicate()]+0x17):C:\Qt\4.4.3\include\QtCore\..\..\src\corelib\arch\qatomic_windows.h||undefined reference to `vtable for Communicate'|
obj\Debug\communicate.o(.text+0x172)||In function `ZN11CommunicateC2EP7QWidget':|
E:\Project\cam2\communicate.cpp|5|undefined reference to `vtable for Communicate'|
obj\Debug\communicate.o(.text+0x17e):E:\Project\cam2\communicate.cpp|5|undefined reference to `vtable for Communicate'|
obj\Debug\communicate.o(.text+0x63a)||In function `ZN11CommunicateC1EP7QWidget':|
E:\Project\cam2\communicate.cpp|5|undefined reference to `vtable for Communicate'|
obj\Debug\communicate.o(.text+0x646):E:\Project\cam2\communicate.cpp|5|more undefined references to `vtable for Communicate' follow|
||=== Build finished: 6 errors, 0 warnings ===|
guys please help...cant figure it out...
This is a subtle bug (and probably partly at least a compiler bug) that I've seen before. Since QWidget has a virtual destructor, the compiler needs a vtable for your class. But your class doesn't have any virtual functions, so it didn't build one for your Communicate class.
Add a virtual ~Communicate() {}; to your class, and all will be well.
Yes, it took me some time to figure this out too!
MOC(meta object compiler) needs to know of your communicate.h (as well as of any other Q_OBJECT'ed classes) to do its job. Unless you place them into .pro file under HEADERS section - you will get this "undefined reference"
A quick option to solve the problem is to remove the Q_OBJECT macro, this will allow you to compile and test your application,
but, not a right choice, if you intend to work every day with QT on CB must configure your environment.
One option that I personally like more and create a custom makefile and a file. "pro" for the application it is easily transportable in other environments as "QtCreator" "NetBeansIDE", etc.
I'll quickly explain what are the steps to follow. If you have installed QtCreator deserves support of self-generated by QtCreator file, and with a little experience can build your own files.
This example only allow you to compile and run the files under "Target Release" later you will have to customize your work environment
Create file: Makefile
####### Compiler, tools and options
PROJECT_NAME = Communicate
QT_INCLUDE = /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc/include/
QT_MKSPECS = /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/
QT_LIB = /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc/lib
QT_QMAKE = /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc/bin/
CC = gcc
CXX = g++
DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I$(QT_MKSPECS)linux-g++ -I../$(PROJECT_NAME) -I$(QT_INCLUDE)QtCore -I$(QT_INCLUDE)QtGui -I/usr/local/QtSDK/Desktop/Qt/4.8.1/gcc/include -I. -I../$(PROJECT_NAME) -I.
LINK = g++
LFLAGS = -Wl,-O1 -Wl,-rpath,$(QT_LIB)
LIBS = $(SUBLIBS) -L$(QT_LIB) -lQtGui -L$(QT_LIB) -L/usr/X11R6/lib -lQtCore -lpthread
AR = ar cqs
RANLIB =
QMAKE = $(QT_QMAKE)qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
STRIP = strip
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### Output directory
OBJECTS_DIR = ./Release
####### Files
SOURCES = ../$(PROJECT_NAME)/main.cpp \
../$(PROJECT_NAME)/communicate.cpp moc_communicate.cpp
OBJECTS = main.o \
communicate.o \
moc_communicate.o
DIST = $(QT_MKSPECS)common/unix.conf \
$(QT_MKSPECS)common/linux.conf \
$(QT_MKSPECS)common/gcc-base.conf \
$(QT_MKSPECS)common/gcc-base-unix.conf \
$(QT_MKSPECS)common/g++-base.conf \
$(QT_MKSPECS)common/g++-unix.conf \
$(QT_MKSPECS)qconfig.pri \
$(QT_MKSPECS)modules/qt_webkit_version.pri \
$(QT_MKSPECS)features/qt_functions.prf \
$(QT_MKSPECS)features/qt_config.prf \
$(QT_MKSPECS)features/exclusive_builds.prf \
$(QT_MKSPECS)features/default_pre.prf \
$(QT_MKSPECS)features/release.prf \
$(QT_MKSPECS)features/default_post.prf \
$(QT_MKSPECS)features/unix/gdb_dwarf_index.prf \
$(QT_MKSPECS)features/warn_on.prf \
$(QT_MKSPECS)features/qt.prf \
$(QT_MKSPECS)features/unix/thread.prf \
$(QT_MKSPECS)features/moc.prf \
$(QT_MKSPECS)features/resources.prf \
$(QT_MKSPECS)features/uic.prf \
$(QT_MKSPECS)features/yacc.prf \
$(QT_MKSPECS)features/lex.prf \
$(QT_MKSPECS)features/include_source_dir.prf \
../$(PROJECT_NAME)/$(PROJECT_NAME).pro
QMAKE_TARGET = $(PROJECT_NAME) Release
DESTDIR = $(OBJECTS_DIR)
TARGET = $(PROJECT_NAME)
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$#" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$#" "$<"
####### Build rules
all: Makefile $(TARGET)
$(TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
Makefile: ../$(PROJECT_NAME)/$(PROJECT_NAME).pro $(QT_MKSPECS)linux-g++/qmake.conf $(QT_MKSPECS)common/unix.conf \
$(QT_MKSPECS)common/linux.conf \
$(QT_MKSPECS)common/gcc-base.conf \
$(QT_MKSPECS)common/gcc-base-unix.conf \
$(QT_MKSPECS)common/g++-base.conf \
$(QT_MKSPECS)common/g++-unix.conf \
$(QT_MKSPECS)qconfig.pri \
$(QT_MKSPECS)modules/qt_webkit_version.pri \
$(QT_MKSPECS)features/qt_functions.prf \
$(QT_MKSPECS)features/qt_config.prf \
$(QT_MKSPECS)features/exclusive_builds.prf \
$(QT_MKSPECS)features/default_pre.prf \
$(QT_MKSPECS)features/release.prf \
$(QT_MKSPECS)features/default_post.prf \
$(QT_MKSPECS)features/unix/gdb_dwarf_index.prf \
$(QT_MKSPECS)features/warn_on.prf \
$(QT_MKSPECS)features/qt.prf \
$(QT_MKSPECS)features/unix/thread.prf \
$(QT_MKSPECS)features/moc.prf \
$(QT_MKSPECS)features/resources.prf \
$(QT_MKSPECS)features/uic.prf \
$(QT_MKSPECS)features/yacc.prf \
$(QT_MKSPECS)features/lex.prf \
$(QT_MKSPECS)features/include_source_dir.prf \
$(QT_LIB)/libQtGui.prl \
$(QT_LIB)/libQtCore.prl
$(QMAKE) -spec $(QT_MKSPECS)linux-g++ -o Makefile ../$(PROJECT_NAME)/$(PROJECT_NAME).pro
$(QT_MKSPECS)common/unix.conf:
$(QT_MKSPECS)common/linux.conf:
$(QT_MKSPECS)common/gcc-base.conf:
$(QT_MKSPECS)common/gcc-base-unix.conf:
$(QT_MKSPECS)common/g++-base.conf:
$(QT_MKSPECS)common/g++-unix.conf:
$(QT_MKSPECS)qconfig.pri:
$(QT_MKSPECS)modules/qt_webkit_version.pri:
$(QT_MKSPECS)features/qt_functions.prf:
$(QT_MKSPECS)features/qt_config.prf:
$(QT_MKSPECS)features/exclusive_builds.prf:
$(QT_MKSPECS)features/default_pre.prf:
$(QT_MKSPECS)features/release.prf:
$(QT_MKSPECS)features/default_post.prf:
$(QT_MKSPECS)features/unix/gdb_dwarf_index.prf:
$(QT_MKSPECS)features/warn_on.prf:
$(QT_MKSPECS)features/qt.prf:
$(QT_MKSPECS)features/unix/thread.prf:
$(QT_MKSPECS)features/moc.prf:
$(QT_MKSPECS)features/resources.prf:
$(QT_MKSPECS)features/uic.prf:
$(QT_MKSPECS)features/yacc.prf:
$(QT_MKSPECS)features/lex.prf:
$(QT_MKSPECS)features/include_source_dir.prf:
$(QT_LIB)/libQtGui.prl:
$(QT_LIB)/libQtCore.prl:
qmake: FORCE
#$(QMAKE) -spec $(QT_MKSPECS)linux-g++ -o Makefile ../$(PROJECT_NAME)/$(PROJECT_NAME).pro
dist:
#$(CHK_DIR_EXISTS) .tmp/$(PROJECT_NAME)1.0.0 || $(MKDIR) .tmp/$(PROJECT_NAME)1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/$(PROJECT_NAME)1.0.0/ && $(COPY_FILE) --parents ../$(PROJECT_NAME)/communicate.h .tmp/$(PROJECT_NAME)1.0.0/ && $(COPY_FILE) --parents ../$(PROJECT_NAME)/main.cpp ../$(PROJECT_NAME)/communicate.cpp .tmp/$(PROJECT_NAME)1.0.0/ && (cd `dirname .tmp/$(PROJECT_NAME)1.0.0` && $(TAR) $(PROJECT_NAME)1.0.0.tar $(PROJECT_NAME)1.0.0 && $(COMPRESS) $(PROJECT_NAME)1.0.0.tar) && $(MOVE) `dirname .tmp/$(PROJECT_NAME)1.0.0`/$(PROJECT_NAME)1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/$(PROJECT_NAME)1.0.0
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
#-$(DEL_FILE) Makefile
check: first
mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_moc_header_make_all: moc_communicate.cpp
compiler_moc_header_clean:
-$(DEL_FILE) moc_communicate.cpp
moc_communicate.cpp: ../$(PROJECT_NAME)/communicate.h
$(QT_QMAKE)moc $(DEFINES) $(INCPATH) ../$(PROJECT_NAME)/communicate.h -o moc_communicate.cpp
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean: compiler_moc_header_clean
####### Compile
main.o: ../$(PROJECT_NAME)/main.cpp ../$(PROJECT_NAME)/communicate.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../$(PROJECT_NAME)/main.cpp
communicate.o: ../$(PROJECT_NAME)/communicate.cpp ../$(PROJECT_NAME)/communicate.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o communicate.o ../$(PROJECT_NAME)/communicate.cpp
moc_communicate.o: moc_communicate.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_communicate.o moc_communicate.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:
Create Project file: Communicate.pro
QT += core gui
TARGET = Communicate
TEMPLATE = app
SOURCES += main.cpp\
communicate.cpp
HEADERS += communicate.h
Setup Custom Makefile ...Project->properties:
Setup Run Action ...Project->properties:
Run
Although that CB is an optimal environment for working with wxWidgets, and C/C++ in general, I personally think that in the case of working with Qt, QtCreator provides a development environment more native and optimized to work with your projects QT.
You need to define the destructor. Even though it derives from a QObject it's not enough for the compiler to use default constructor/destructors.
Qt Linker Error: "undefined reference to vtable"