【问题标题】:Linking issues after adding a new source folder in QT在 QT 中添加新的源文件夹后链接问题
【发布时间】:2014-02-15 12:49:23
【问题描述】:

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/ 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 tokensscanner.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.

【问题讨论】:

  • 你在哪里定义int Main()int Main(int, char *[]) 是什么?
  • @JoachimPileborg 我在 CH2.cpp 中定义了 int main()。我在这个项目中引入了 Main.cpp 源,其中包含 int Main(int, char *[])。
  • 一般情况下你不应该makeqmake 报告错误。 qmake 也使用不同的语法进行文件通配,你尝试过类似HEADERS += $$files(src/*.h) 的东西吗?
  • @fasked:qmake 没有任何错误。我已经用 qmake 输出更新了这个错误。此外,我还尝试在 .pro 文件中添加 HEADERS += $$files(src/*.h) ,但也没有用。
  • @Vivek WARNING: Failure to find: ../CH2/src/*.h 是错误 :)

标签: c++ qt clang


【解决方案1】:

链接错误是由于没有将 $$PWD/lib/CPPLib 中的一些附加源文件作为库包含在 CH2.CPP 中

【讨论】:

    猜你喜欢
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多