1

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

user3450695
  • 2,281
  • 4
  • 16
  • 16
  • 1. Did you tried to clean before make? 2. Are you sure no other error before that `Error 1`? – SHR Nov 11 '14 at 04:13
  • 1
    "Qt" does not include a C++ compiler. You may be referring to Qt Creator, which is an IDE that can use a C++ compiler. Either way, you need to figure out which C++ compiler/version you are actually using. If the one you are using is old and does not support C++11, adding a `-std=c++11` flag won't help - it'll just be an unrecognized flag. – nobody Nov 11 '14 at 04:17
  • 2
    Also, there should be more context to that error message. Post it. – nobody Nov 11 '14 at 04:17
  • @AndrewMedico 1. How do I know which version I'm using? I was able to know it didn't support some functions that are available in c++11. 2. How do I make the IDE support c++11? 3.That was the only error - exactly as I posted. – user3450695 Nov 11 '14 at 04:21
  • @SHR I've cleaned before make and it is still giving me the same error - the only error – user3450695 Nov 11 '14 at 04:24
  • 1
    You might try adding `CONFIG += c++11` to your project file instead. That is the usual way to add support for c++11. – Retired Ninja Nov 11 '14 at 04:27
  • @RetiredNinja I tried doing that but it did not support the functions in c++11. The main.o error didn't come up though – user3450695 Nov 11 '14 at 04:36
  • What is the version of g++ you're actually using? – Retired Ninja Nov 11 '14 at 05:21
  • @RetiredNinja while checking the options in Qt creator, I saw that it has a compiler path of usr/bin/g++. That is all I got. I don't know how to check the version – user3450695 Nov 11 '14 at 13:21
  • You need to type `gcc -v` in a shell and edit the results into your question. – Retired Ninja Nov 11 '14 at 18:32
  • @RetiredNinja I've added the results to the question – user3450695 Nov 11 '14 at 19:11
  • 1
    There's some information about the flags and features that gcc 4.6.3 supports here: http://stackoverflow.com/questions/17378969/how-to-change-gcc-compiler-to-c11-on-ubuntu You should probably try just compiling a simple hello word program from the command line with the different flags to see what works and then add that to the QMAKE_CXXFLAGS in your .pro file. You might also consider trying to upgrade the compiler. – Retired Ninja Nov 11 '14 at 21:24
  • In Qt Creator, try looking at the *Compile Output* to get the original error message shown in *Issues*. There has to be a better error than just `Error 1`.... – hyde Nov 13 '14 at 22:09

3 Answers3

0

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.)

Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
  • 1
    Believe me, that was the only error. I tried all your suggestions but none could solve the problem, unfortunately – user3450695 Nov 11 '14 at 04:37
0

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.
YellowPeak
  • 20
  • 2
0

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:

  1. Going to your build directory such as:

    ../build-*
    
  2. Deleting all relevant Makefile scripts and others if necessary,

  3. Then re-building it again.
Dean Seo
  • 5,486
  • 3
  • 30
  • 49