0
votes

BEGINNER ALERT: I am unable to figure out why the following link error?

I created a simple project with CH2.CPP which builds correctly in QT:

#include <iostream>

using namespace std;

int main()
{
cout << "Hello World!" << endl;
return 0;
}

After this I added additional source files to the project by modifying the .pro file:

TEMPLATE = app
#CONFIG += console
#CONFIG -= app_bundle
#CONFIG -= qt

SOURCES = $$PWD/src/*.cpp
SOURCES += $$PWD/lib/CPPLib/*.cpp
HEADERS = $$PWD/src/*.h
HEADERS += $$PWD/lib/CPPLib/*.h

QMAKE_CXXFLAGS += -std=c++11
#QMAKE_CXXFLAGS += -lpthread
#QMAKE_LFLAGS += -static
#QMAKE_LFLAGS += -static-libgcc
#QMAKE_LFLAGS += -static-libstdc++

INCLUDEPATH += $$PWD/lib/CPPLib/

following which I received this error when building the project. Here is the compile output:

08:10:01: Running steps for project CH2…
08:10:01: Configuration unchanged, skipping qmake step.
08:10:01: Starting: "/usr/bin/make" 
/Users/vivekshumi/Qt5.2.0/5.2.0/clang_64/bin/qmake -spec macx-clang CONFIG+=x86_64 -o     Makefile ../CH2/CH2.pro
WARNING: Failure to find: ../CH2/src/*.h       

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.6 -o CH2.app/Contents/MacOS/CH2 ch2.o console.o direction.o error.o filelib.o gevents.o ginteractors.o gmath.o gobjects.o gtimer.o gtypes.o gwindow.o hashmap.o lexicon.o main.o platform.o point.o random.o simpio.o sound.o startup.o strlib.o tokenscanner.o -F/Users/vivekshumi/Qt5.2.0/5.2.0/clang_64/lib -framework QtGui -framework QtCore -framework OpenGL -framework AGL

Undefined symbols for architecture x86_64:
"Main()", referenced from:
  Main(int, char**) in main.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: *** [CH2.app/Contents/MacOS/CH2] Error 1
08:10:01: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project CH2 (kit: Desktop Qt 5.2.0 clang 64bit)
When executing step 'Make'
08:10:01: Elapsed time: 00:00.   

Main.cpp contents which was added to this project from the new source directory:

int Main(int, char *[]) {
extern int Main();
return Main();
}

qmake output:

23:14:09: Running steps for project CH2...
23:14:09: Starting: "/Users/vivekshumi/Qt5.2.0/5.2.0/clang_64/bin/qmake"     /Users/vivekshumi/Developer/CH2/CH2.pro -r -spec macx-clang CONFIG+=debug CONFIG+=x86_64  CONFIG+=declarative_debug CONFIG+=qml_debug
WARNING: Failure to find: ../CH2/src/*.h
23:14:09: The process "/Users/vivekshumi/Qt5.2.0/5.2.0/clang_64/bin/qmake" exited normally.
23:14:09: Elapsed time: 00:00.
1
Where do you define int Main()? And what is int Main(int, char *[])?Some programmer dude
@JoachimPileborg I defined int main() in CH2.cpp. I brought in Main.cpp source to this project, which contains int Main(int, char *[]).Vivek
In general case you shouldn't make while qmake reports errors. Also qmake uses different syntax for file globbing, did your try something like HEADERS += $$files(src/*.h)?fasked
@fasked: qmake did not have any errors. I have updated the bug with the qmake output. In addition I also tried adding the HEADERS += $$files(src/*.h) in the .pro files, which also did not work.Vivek
@Vivek WARNING: Failure to find: ../CH2/src/*.h is error :)fasked

1 Answers

0
votes

The linking error happened due to not including some of the additional source file in $$PWD/lib/CPPLib as libraries in CH2.CPP