关于网友提出的“ 新手求助 error LNK2019: 无法解析的外部符号,无法解析的外部命令”问题疑问,本网通过在网上对“ 新手求助 error LNK2019: 无法解析的外部符号,无法解析的外部命令”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 新手求助 error LNK2019: 无法解析的外部符号,无法解析的外部命令
描述:
//func.h文件
#ifndef FUNC_H
#define FUNC_H
#ifndef VECTOR_H
#define VECTOR_H
#include
#endif
double sum(std::vector::const_iterator,std::vector::const_iterator);
#endif
//func.cpp文件
#include "func.h"
double sum(std::vector::const_iterator beg,std::vector::const_iterator end)
{
double result=0.0;
while(beg!=end)
{
result+=*beg++;
}
return result;
}
//prog1.cpp文件
#include
#include
#include "func.h"
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
//7.14
double input;
std::vector dvec;
while(cin>>input)
{
dvec.push_back(input);
}
std::vector::iterator iter=dvec.begin();
if(iter!=dvec.end())
cout<<><>
return 0;
}
命令行编译不了:
F:\cpp>cl prog1.cpp
用于 80x86 的 Microsoft (R) 32 位 C/C++ 优化编译器 16.00.30319.01 版
版权所有(C) Microsoft Corporation。保留所有权利。
prog1.cpp
D:\Program Files\Microsoft Visual Studio 10.0\VC\include\xlocale(323) : warning
C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:prog1.exe
prog1.obj
prog1.obj : error LNK2019: 无法解析的外部符号 "double __cdecl sum(class std::_Ve
ctor_const_iterator<><>
>
>,class std::_Vector_const_iterator<><>
locator > >)" (?sum@@YANV?$_Vector_const_iterator@V?$_Vector_val@NV?$all
ocator@N@std@@@std@@@std@@0@Z),该符号在函数 _main 中被引用
prog1.exe : fatal error LNK1120: 1 个无法解析的外部命令
F:\cpp>
解决方案1:
你的头文件先这样试试?
//func.h文件
#include
double sum(std::vector::const_iterator beg,std::vector::const_iterator end);
解决方案2: 修改一下:
//func.h文件
#ifndef FUNC_H
#define FUNC_H
#ifndef VECTOR_H
#define VECTOR_H
#include
#endif
double sum(std::vector::const_iterator,std::vector::const_iterator);
#endif
红色部分修改为以下的:
double sum(std::vector::const_iterator beg,std::vector::const_iterator end);
以上介绍了“ 新手求助 error LNK2019: 无法解析的外部符号,无法解析的外部命令”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2201650.html