Qt 5.1 - 构建时出现"Add library"错误。LNK2019
Qt 5.1 - "Add library" error on build. LNK2019
我正在尝试将c ++库(在Qt中创建)链接到控制台应用程序。在纯 c++ 中,我确实成功地将库 dll 链接到程序。在Qt中,我得到LNK2019:未解析的外部符号。
图书馆
利巴
头
*liba_global.h*
#ifndef LIBA_GLOBAL_H
#define LIBA_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(LIBA_LIBRARY)
# define LIBASHARED_EXPORT Q_DECL_EXPORT
#else
# define LIBASHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // LIBA_GLOBAL_H
*lib_example.h*
#ifndef LIB_EXAMPLE_H
#define LIB_EXAMPLE_H
#include "liba_global.h"
//Interface as seen on http://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm
class LIBASHARED_EXPORT Lib_example
{
public:
Lib_example(){}
virtual ~Lib_example(){}
virtual int getId()=0;
virtual void setId(int id)=0;
};
#endif // LIB_EXAMPLE_H
*test_a.h*
#ifndef TEST_A_H
#define TEST_A_H
#include "liba_global.h"
#include "lib_example.h"
class LIBASHARED_EXPORT Test_A:public Lib_example
{
public:
Test_A();
~Test_A();
int getId();
void setId(int id);
private:
int id;
};
#endif // TEST_A_H
源
*test_a.cpp*
#include "test_a.h"
int Test_A::getId()
{
return id;
}
void Test_A::setId(int id)
{
this->id = id;
}
Test_A::Test_A()
{
this->id = 0;
}
Test_A::~Test_A()
{ }
亲
QT -= gui
TARGET = LibA
TEMPLATE = lib
DEFINES += LIBA_LIBRARY
SOURCES +=
test_a.cpp
HEADERS += lib_example.h
liba_global.h
test_a.h
unix:!symbian {
maemo5 {
target.path = /opt/usr/lib
} else {
target.path = /usr/lib
}
INSTALLS += target
}
项目
主.cpp
#include <QCoreApplication>
#include <iostream>
#include "test_a.h"
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Test_A test;
test.setId(2);
cout<<test.getId()<<endl;
return a.exec();
}
亲
QT += core
QT -= gui
TARGET = ProjUsingLib_A
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-LibA-Desktop_Qt_5_1_1_MSVC2012_32bit-Debug/release/ -lLibA
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-LibA-Desktop_Qt_5_1_1_MSVC2012_32bit-Debug/debug/ -lLibA
else:unix: LIBS += -L$$PWD/../build-LibA-Desktop_Qt_5_1_1_MSVC2012_32bit-Debug/ -lLibA
INCLUDEPATH += $$PWD/../LibA
DEPENDPATH += $$PWD/../LibA
我编写了代码并使用Qt Creator进行链接。
更多详细信息:使用 MSVC2012_32bit_debug 选项编译的 lib 和 main。
错误:
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall Test_A::Test_A(void)" (??0Test_A@@QAE@XZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __thiscall Test_A::~Test_A(void)" (??1Test_A@@UAE@XZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual int __thiscall Test_A::getId(void)" (?getId@Test_A@@UAEHXZ) referenced in function _main
main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual void __thiscall Test_A::setId(int)" (?setId@Test_A@@UAEXH@Z) referenced in function _main
提前致谢:)
你不是在构建/链接test_a.cpp
。 将其添加到生成文件的SOURCES
行。
相关文章:
- Boost Graph Library,修复节点大小
- SFML library: http request
- Visual Studio - Cmake Project - Add NetCDF
- 解决"ld: library not found for -ltensorflow_framework.2.3.0"
- Linking library C++
- 在VS2019项目中集成ImageMagick:x64-windows-static library
- OpenSSL fips in C++ wrapper Library 如何?错误:指纹不匹配
- C++ class vs a library
- C++ library with Tensorflow on Android
- CMake:尝试在 Jenkins 构建机器上运行时出现"Linked Library"错误 (0xc0000135)
- 在 atomic() 中 ++、add operation 和 fetch_add() 有什么区别
- 将 c++ cmake-library 构建发布到本地存储库时出现 Gradle 错误
- wxImageList::Add()始终返回0
- 函数 C::add() 中不允许将'C *'隐式转换为'A *'
- 为什么'allocate in one library and free in the other'是错误的
- 链接 library.lib 使用 setup.py.
- C++有"not equal compare and exchange"或"fetch add on not equal"吗?
- 目标提升::<library>已经有导入的位置 + 链接错误
- CMake add library libpq (postgreSQL) mac c++ clion
- Qt 5.1 - 构建时出现"Add library"错误。LNK2019