【发布时间】:2009-03-15 12:02:01
【问题描述】:
我正在使用 qt 并开发将在 win xp/vista 下运行的桌面应用程序。
我有一个第 3 方库 UserAgentLib(静态和共享)。但我不确定如何在 qt creator 中链接。
我打开了 *.pro 文件并添加了我的库和头文件路径。 该库称为 UserAgentLib,头文件称为 UserAgentLib.h
TARGET = Dialer
TEMPLATE = app
LIBS += D:\Projects\qtDialer\tools\lib\UserAgentLib
INCLUDEPATH += D:\Projects\qtDialer\tools\inc
SOURCES += main.cpp\
catdialer.cpp
HEADERS += catdialer.h
FORMS += catdialer.ui
我认为它确实找到了头文件,因为我在 UserAgentLib.h 文件中收到大约 100 个声明错误。但是,我不认为它与图书馆链接。
非常感谢您的任何建议,
=======================
我在 VS C++ 2008 中创建了一个非常简单的库。这是头文件和源文件的代码。 标题:
// mathslibrary.hpp
int add_numbers(const int a, const int b);
来源:
// mathslibrary.cpp
#include "mathslibrary.hpp"
int add_numbers(const int a, const int b)
{
return a + b;
}
我已经把它编译成一个库。并通过与 VS 2008 中的 WIN32 控制台应用程序链接进行测试。该库按预期工作。
现在当我尝试与 qt 链接时。
#include <QtCore/QCoreApplication>
#include <iostream>
#include "mathslibrary.hpp"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::cout << "add numbers 40 + 60 = " << add_numbers(40, 60) << std::endl;
return a.exec();
}
这是我的 qmake 文件:
QT -= gui
TARGET = testlibrary
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
LIBS = D:\Projects\TestLibrary\mathsLibrary\Debug\mathsLibrary.lib
INCLUDEPATH = D:\Projects\TestLibrary\mathsLibrary\
SOURCES += main.cpp
这些是我在尝试构建时遇到的错误:
c:/Qt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c::-1 : 错误:未定义对 `WinMain@16' 的引用
:-1: 错误:collect2: ld 返回 1 个退出状态
这些是编译问题:
正在运行项目测试库的构建步骤...
正在创建 gdb 宏库...
配置不变,跳过 QMake 步骤。
开始:C:/Qt/mingw/bin/mingw32-make.exe debug -w
mingw32-make: 进入目录`D:/Projects/TestQTLibrary/testlibrary'
C:/Qt/mingw/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: 进入目录`D:/Projects/TestQTLibrary/testlibrary'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\testlibrary.exe -L "c:\Qt\qt\lib"
D:\Projects\TestLibrary\mathsLibrary\Debug\mathsLibrary.lib -lQtCored4 mingw32-make[1]: 离开目录`D:/Projects/TestQTLibrary/testlibrary'
mingw32-make: 离开目录 `D:/Projects/TestQTLibrary/testlibrary'
c:/Qt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:
(.text+0x104): 未定义对 `WinMain@16' 的引用 collect2: ld 返回 1 个退出状态 mingw32-make[1]: * [debug\testlibrary.exe] 错误 1 mingw32-make: * [调试] 错误 2 以代码 2 退出。 构建项目测试库时出错 执行构建步骤“Make”时
非常感谢您的建议,
【问题讨论】: