error LNK2019: 无法解析的外部符号

kobesff 2009-11-27 10:46:33
错误 1 error LNK2019: 无法解析的外部符号 "public: long __thiscall TestSuite::Test::report(void)const " (?report@Test@TestSuite@@QBEJXZ),该符号在函数 _main 中被引用 string2.obj string2


错误 2 error LNK2019: 无法解析的外部符号 "protected: void __thiscall TestSuite::Test::do_test(bool,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *,long)" (?do_test@Test@TestSuite@@IAEX_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBDJ@Z),该符号在函数 "public: void __thiscall RparseTest::testData(void)" (?testData@RparseTest@@QAEXXZ) 中被引用 string2.obj string2

错误 3 fatal error LNK1120: 2 个无法解析的外部命令 C:\Users\Seawing\Documents\Visual Studio 2008\Projects\string2\Debug\string2.exe string2
------------------------------上面是用VC2008出现的链接错误-----------------------------------------------------
下面是C++编程思想的代码(COPY过来用,基本不会错)
//: C03:Rparse.cpp
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
//{L} ../TestSuite/Test
#include "Rparse.h"
int main() {
RparseTest t;
t.run();
return t.report();
} ///:~

//: C03:Rparse.h
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
#ifndef RPARSE_H
#define RPARSE_H
#include <cstddef>
#include <string>
#include <vector>
#include "../TestSuite/Test.h"
using std::size_t;
using std::string;
using std::vector;

class RparseTest : public TestSuite::Test {
// To store the words:
vector<string> strings;
public:
void parseForData() {
// The ';' characters will be delimiters
string s("now.;sense;make;to;going;is;This");
// The last element of the string:
int last = s.size();
// The beginning of the current word:
size_t current = s.rfind(';');
// Walk backward through the string:
while(current != string::npos) {
// Push each word into the vector.
// Current is incremented before copying
// to avoid copying the delimiter:
++current;
strings.push_back(s.substr(current, last - current));
// Back over the delimiter we just found,
// and set last to the end of the next word:
current -= 2;
last = current + 1;
// Find the next delimiter:
current = s.rfind(';', current);
}
// Pick up the first word -- it's not
// preceded by a delimiter:
strings.push_back(s.substr(0, last));
}
void testData() {
// Test them in the new order:
test_(strings[0] == "This");
test_(strings[1] == "is");
test_(strings[2] == "going");
test_(strings[3] == "to");
test_(strings[4] == "make");
test_(strings[5] == "sense");
test_(strings[6] == "now.");
string sentence;
for(size_t i = 0; i < strings.size() - 1; i++)
sentence += strings[i] += " ";
// Manually put last word in to avoid an extra space:
sentence += strings[strings.size() - 1];
test_(sentence == "This is going to make sense now.");
}
void run() {
parseForData();
testData();
}
};
#endif // RPARSE_H ///:~




太悲剧了,自己写了半天都不行,copy下源代码也不行汗!
各位能说下为什么吗 以及怎么解决 希望详细点,能多些扩展问题!
有新想法,不同想法,激发新问题的都给分
...全文
781 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
dazhilao 2010-10-05
  • 打赏
  • 举报
回复
把"../TestSuite/Test.cpp"也如入到文件里去。
kobesff 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 ztz0223 的回复:]

服了

怎么没有啊 ?
你一定要strcmp("rebuild", "重新生成解决方案")==0?

两种解决方法
第一个,你把test那块代码编译成一个lib文件,添加进来
第二,你把test的头文件和。c文件都拷贝过来一起编译
[/Quote]

没重新生成解决方案
我以为生成==开始执行

还有的
仅生成
仅重新生成 //和第一有区别麽
仅清除?
仅链接
的菜单不知道是什么意思?
就呆在云上 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 kobesff 的回复:]
引用 16 楼 loaden 的回复:
引用 15 楼 kobesff 的回复:
引用 5 楼 loaden 的回复:
如果你确认已经实现,那么请rebuild!
有可能是CPP文件的编译没有更新。


ctrl + f5 应该默认是全部文件重新编译 链接吧~

不是。
在Build(构建)菜单里选Rebuild ALL(重建)。

2008没这个build 和 rebuild这类按钮
[/Quote]

服了

怎么没有啊 ?
你一定要strcmp("rebuild", "重新生成解决方案")==0?

两种解决方法
第一个,你把test那块代码编译成一个lib文件,添加进来
第二,你把test的头文件和。c文件都拷贝过来一起编译
mstlq 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 kobesff 的回复:]
引用 16 楼 loaden 的回复:
引用 15 楼 kobesff 的回复:
引用 5 楼 loaden 的回复:
如果你确认已经实现,那么请rebuild!
有可能是CPP文件的编译没有更新。


ctrl + f5 应该默认是全部文件重新编译 链接吧~

不是。
在Build(构建)菜单里选Rebuild ALL(重建)。

2008没这个build 和 rebuild这类按钮
[/Quote]

没按钮,有菜单嘛……
生成 -- 重新生成解决方案……

如果还是找不到,那就用ctrl + alt +f7吧……
shuilongyin_00 2009-11-28
  • 打赏
  • 举报
回复
VS2008有的!LZ再看下!很容易找到的!
kobesff 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 loaden 的回复:]
引用 15 楼 kobesff 的回复:
引用 5 楼 loaden 的回复:
如果你确认已经实现,那么请rebuild!
有可能是CPP文件的编译没有更新。


ctrl + f5 应该默认是全部文件重新编译 链接吧~

不是。
在Build(构建)菜单里选Rebuild ALL(重建)。
[/Quote]
2008没这个build 和 rebuild这类按钮
「已注销」 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 kobesff 的回复:]
引用 5 楼 loaden 的回复:
如果你确认已经实现,那么请rebuild!
有可能是CPP文件的编译没有更新。


ctrl + f5 应该默认是全部文件重新编译 链接吧~
[/Quote]
不是。
在Build(构建)菜单里选Rebuild ALL(重建)。
kobesff 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 loaden 的回复:]
如果你确认已经实现,那么请rebuild!
有可能是CPP文件的编译没有更新。
[/Quote]

ctrl + f5 应该默认是全部文件重新编译 链接吧~
kobesff 2009-11-28
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 daven172 的回复:]
关键是这里:
#include "../TestSuite/Test.h"
Test.h这个文件有没有放到合适位置?
[/Quote]

添加就可以了,放哪里应该没关系吧。。
Daven172 2009-11-28
  • 打赏
  • 举报
回复
关键是这里:
#include "../TestSuite/Test.h"
Test.h这个文件有没有放到合适位置?
kobesff 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 jackyjkchen 的回复:]


VC的文件列表,右键-添加。
最好将所有cpp添加进来,如果嫌不清爽,建议先编译testsuite成静态库,连接一下就行了
[/Quote]

好久没碰C++了,之前只会些基础,很少动手,现在再来打代码 出现的问题还真多而且这些问题之前都是知道,但现在碰到了却忘了,等上网查的时候才又想起来,太悲剧了
kobesff 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 loaden 的回复:]
引用 9 楼 kobesff 的回复:
引用 1 楼 jackyjkchen 的回复:
编译通过了说明代码没错,怀疑你没有吧test.cpp放进工程,只有一个test.h

呀 进了一步  我以为只要把这个放在项目文件夹下面就行了  原来还有添加 谢啦
请问为什么要添加呢 
#include "../TestSuite/Test.h" 这个testsuite文件夹已经放在项目文件夹里面了啊!?

添加到工程,VS才会把它编译成.obj文件。
[/Quote]

添加之后出现

microsoft visual c++ debug library的对话框
终止 重试 忽略 按钮

不知道为什么?
jackyjkchen 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 kobesff 的回复:]
引用 1 楼 jackyjkchen 的回复:
编译通过了说明代码没错,怀疑你没有吧test.cpp放进工程,只有一个test.h

呀 进了一步  我以为只要把这个放在项目文件夹下面就行了  原来还有添加 谢啦
请问为什么要添加呢 
#include "../TestSuite/Test.h" 这个testsuite文件夹已经放在项目文件夹里面了啊!?
[/Quote]
VC的文件列表,右键-添加。
最好将所有cpp添加进来,如果嫌不清爽,建议先编译testsuite成静态库,连接一下就行了
「已注销」 2009-11-27
  • 打赏
  • 举报
回复
从源文件到中间文件:obj,再链接成可执行文件。
「已注销」 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 kobesff 的回复:]
引用 1 楼 jackyjkchen 的回复:
编译通过了说明代码没错,怀疑你没有吧test.cpp放进工程,只有一个test.h

呀 进了一步  我以为只要把这个放在项目文件夹下面就行了  原来还有添加 谢啦
请问为什么要添加呢 
#include "../TestSuite/Test.h" 这个testsuite文件夹已经放在项目文件夹里面了啊!?
[/Quote]
添加到工程,VS才会把它编译成.obj文件。
kobesff 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jackyjkchen 的回复:]
编译通过了说明代码没错,怀疑你没有吧test.cpp放进工程,只有一个test.h
[/Quote]
呀 进了一步 我以为只要把这个放在项目文件夹下面就行了 原来还有添加 谢啦
请问为什么要添加呢
#include "../TestSuite/Test.h" 这个testsuite文件夹已经放在项目文件夹里面了啊!?
cattycat 2009-11-27
  • 打赏
  • 举报
回复
把cpp文件添加进项目,原因是没实现report和do_test函数,没找到定义。
jackyjkchen 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kobesff 的回复:]
引用 1 楼 jackyjkchen 的回复:
编译通过了说明代码没错,怀疑你没有吧test.cpp放进工程,只有一个test.h

建工程---添加.CPP  .h了

怀疑错误  呵呵
[/Quote]
TestSuite::Test::report的实现在哪里?
开心的卡夫卡 2009-11-27
  • 打赏
  • 举报
回复
你的../TestSuite/Test.h这些东西的位置都对不对啊!检查下!
「已注销」 2009-11-27
  • 打赏
  • 举报
回复
如果你确认已经实现,那么请rebuild!
有可能是CPP文件的编译没有更新。
加载更多回复(4)

65,203

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧