BEGINNER ALERT:我无法弄清楚为什么会出现以下链接错误?
我创建了一个带有CH2.CPP的简单项目,该项目在QT中正确构建:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
在此之后,我通过修改.pro文件将其他源文件添加到项目中:
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/
在构建项目后我收到此错误。这是编译输出:
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 /开发人员/ 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 /用户/ 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内容:
int Main(int, char *[]) {
extern int Main();
return Main();
}
qmake输出:
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.
答案 0 :(得分:0)
发生链接错误的原因是 $$ PWD / lib / CPPLib 中的某些附加源文件不包含在CH2.CPP中的库