错误 LNK2019:未解析的外部符号 - 问题的不可见实例
error LNK2019: unresolved external symbol - unseen instance of the issue
>我有一个错误LNK2019:未解决的外部符号问题。
我有 2 个文件,并将它们移动到共享位置,以便 2 个不同的项目可以使用类。那里还有其他类似的类。
问题是,当我从其中一个项目的主项目调用类时,我得到了
error LNK2019: unresolved external symbol "public: __thiscall CProcessCommandLine::~CProcessCommandLine(void)" (??1CProcessCommandLine@@QAE@XZ) referenced in function _main
error LNK2019: unresolved external symbol "public: bool __thiscall CProcessCommandLine::Wait(void)const " (?Wait@CProcessCommandLine@@QBE_NXZ) referenced in function _main
error LNK2019: unresolved external symbol "public: class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const & __thiscall CProcessCommandLine::getTargetNamesVect(void)" (?getTargetNamesVect@CProcessCommandLine@@QAEABV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ) referenced in function _main
error LNK2019: unresolved external symbol "public: __thiscall CProcessCommandLine::CProcessCommandLine(void)" (??0CProcessCommandLine@@QAE@XZ) referenced in function _main
当我打开头文件并右键单击其中一个函数并转到定义时,它不会转到.cpp中的定义。当我右键单击.cpp中的函数并说转到定义时,它说"符号未定义"。
有人知道为什么会发生这种情况吗?.h 和 .cpp 位于同一位置,并且该位置位于项目的附加包含目录中
编辑:
此文件夹中的其他文件中存在以下代码:
#ifdef PROJ1
#include "class1.h"
#elif PROJ2
#include "class2.h"
#endif
我以前从未见过这些东西。它们在代码中使用,但仅用于包含正确的标头,具体取决于它在哪个项目中使用。以上是此文件夹中其他类的.cpp。所以我把它放在这里。但在其他类中,它不属于的项目是灰色的。当我把它放到 .h 中时,它会变灰正确的标题。但由于某种原因,这个.cpp没有被认为是项目的一部分。
如果你的函数属于与你正在构建的模块不同的模块,你必须导出这些类:
#ifdef THIRD_MODULE
#define DLLIMPEXP _declspec(dllexport)
#else
#define DLLIMPEXP _declspec(dllimport)
#endif
class DLLIMPEXP CProcessCommandLine
{
//...
};
生成定义此类的项目,并定义THIRD_MODULE
。
此项目将生成.lib
文件,您必须将其添加到主项目的链接器设置中的其他依赖项中。
相关文章:
- C++ std::function 对于类 exept 的所有实例都是空的(只有 Visual2019 编译器问题)
- 在另一个类中创建类实例时出现问题
- 为什么我的类电影在创建电影实例时遇到问题?
- 在C++中将类实例添加到对象层次结构中的问题
- 在抛出 'std::invalid_argument' 的实例后终止调用 what(): stoi (找不到问题所在)
- 错误 C2280 / 在 std::vector 中实例化对象时复制构造函数出现问题?
- C++程序问题:抛出'std::invalid_argument'实例后终止调用
- 显式模板实例化问题
- 在 x86 32 位上的静态类实例中解决此问题
- 分割故障 - 遇到问题,创建新的数组实例
- 关于QLIST类型实例复制构造函数的一个奇怪问题
- 如何理解C++并发操作中同类实例导致死锁的问题
- 创建 QQuickItem 子类的实例是否有问题,我不打算渲染或添加到 QML 树中的实例?
- 创建'new'实例可以解决析构函数崩溃问题?
- 实例化函数模板的编译问题
- 从结构实例调用变量语法问题C++
- CPP-Netlib 问题,在抛出 'boost::exception_detail::clone_impl 的实例后调用终止
- 模板函数实例化的可移植性问题
- 实例变量列表中的对象未被保留?指针问题
- 模板函数实例化 自定义数据类型的问题