使用向量和查找时C++未解析的外部
Unresolved externals in C++ when using vectors and find
我已经在一个完全独立的项目中尝试了这段代码,它工作正常(唯一的区别是无法正常工作的项目被导出为 DLL)。这是代码:
RTATMATHLIB。.CPP
#include "stdafx.h"
#include "RTATMATHLIB.h"
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdexcept>
using namespace std;
double someFunc(double** Y, int length)
{
vector<double> myVector;
for(int i = 0; i < length; i++)
{
double value = (*Y)[i];
vector<double>::iterator it = find(myVector.begin(), myVector.end(), value);
if(it != myVector.end())
{
continue;
}
else
{
myVector.push_back(value);
}
}
return 0;
}
RTATMATHLIB。H
__declspec(dllexport) double someFunc(double** Y, int length);
错误
Error 1 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator<double,class std::allocator<double> >::_Vector_const_iterator<double,class std::allocator<double> >(double *,class std::_Container_base_secure const *)" (??0?$_Vector_const_iterator@NV?$allocator@N@std@@@std@@QAE@PANPBV_Container_base_secure@1@@Z) RTATMATHLIB.obj RTATMATHLIB
Error 2 fatal error LNK1120: 1 unresolved externals
仅此而已。我不确定为什么它在另一个项目中工作而不是这个项目......
我找到了另一个论坛帖子,其中似乎有人报告了与您遇到的相同问题。请检查您是否有
_DEBUG
在项目设置(在 C/C++ -- 预处理器下)或代码中的某个位置(或包含文件)中定义。
看起来好像 std::vector 认为您正在构建调试版本,而实际上您正在创建发布版本。
我希望这有所帮助。
在我的情况下,问题是将Runtime Library
设置为 Multi-threaded DLL
的调试配置。解决方法是将其更改为 Multi-threaded Debug DLL
.错误消失了。删除_DEBUG
宏也是一种解决方法,我想这不是一个好主意,因为您最终会得到链接到非调试标准库的调试版本。
问题是我在 C/C++->预处理器中定义了_DEBUG。将其更改为NDEBUG解决了问题。
为我工作:在我的情况下,问题是运行时库设置为多线程 DLL 的调试配置。解决方法是将其更改为多线程调试 DLL
相关文章:
- 在函数内部的声明中初始化数组,并在外部使用它
- 使外部项目可用于find_package CMake
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- C++:来自外部文件的Trivia
- 从函数角度看ID到文件路径的内部与外部映射
- C++:将外部库链接到dll库
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 节俭并发:未解决的外部问题
- 如何在c++中从git建立外部库
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何使用对C函数和类对象的外部调用来处理C++头文件
- 具有外部"c"和程序集的未定义函数
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 在C++中使用 gRPC 时未解析的外部符号
- 在类函数中初始化外部作用域变量
- 如果全局变量默认是外部变量,为什么要添加"extern"关键字?
- 调用外部函数,无法指定类型 C++/MVS
- 同时具有"外部"和"内联"说明符的变量
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta