makefile的出错,请帮忙看看

qsd007 2007-03-07 04:24:37
edit : MainFile.o TestQuery.o
g++ -o edit MainFile.o TestQuery.o

TestQuery.o MainFile.o : TestQuery.h

.PHONY : clean
clean :
rm edit $(objects)

出错提示:
$ make
make: *** No rule to make target `TestQuery.h', needed by `MainFile.o'. Stop.

TestQuery 是一个类;分成.h 和 .cpp
MainFile 只是一个写main的cpp文件,包含了TestQuery.h
是makefile哪里写错了,请大家指教~~
...全文
336 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
qsd007 2007-03-09
  • 打赏
  • 举报
回复
文件被改成:
edit : MainFile.o TestQuery.o
g++ -o edit MainFile.o TestQuery.o

TestQuery.o : TestQuery.cpp
g++ -c TestQuery.cpp
MainFile.o : MainFile.cpp
g++ -c MainFile.cpp

.PHONY : clean
clean :
rm edit MainFile.o TestQuery.o
还是报错~~
$ make
make: *** No rule to make target `TestQuery.cpp', needed by `TestQuery.o'. Stop.
qsd007 2007-03-09
  • 打赏
  • 举报
回复
楼上的兄弟,,为什么不要.h文件??
qsd007 2007-03-09
  • 打赏
  • 举报
回复
#include <iostream>
#include <istream>
#include <fstream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <string>
using namespace std;

class TextQuery
{
public:
typedef vector<string>::size_type line_no;

void read_file(ifstream &is)
{
store_file(is);
build_map();
}
set<line_no> run_query(const string &) const;
string text_line(line_no) const;

TextQuery();
virtual ~TextQuery();
private:
void store_file(ifstream &is);
void build_map();

vector<string> lines_of_text;

map< string, set<line_no> > word_map;
};
qsd007 2007-03-09
  • 打赏
  • 举报
回复
//MainFile.cpp
#include "TextQuery.h"
using namespace std;

ifstream& open_file(ifstream &in, const string &file)
{
in.close();
in.clear();

in.open(file.c_str());
return in;
}
string make_plural(size_t ctr ,const string &word,
const string &ending)
{
return (ctr ==1) ? word : word +ending;
}

void print_results(const set<TextQuery::line_no>& locs,
const string &sought, const TextQuery &file)
{
typedef set<TextQuery::line_no> line_nums;
line_nums::size_type size = locs.size();
cout<<endl<<sought<<"occurs"
<<size<<" "
<<make_plural(size, "time", "s") <<endl;
line_nums::const_iterator it = locs.begin();
for (;it!= locs.end() ; ++it)
{
cout<< "\t(line "
<<(*it) +1 <<" )"
<<file.text_line(*it)<<endl;
}
}

int main(int argc,char **argv)
{
ifstream infile;
if(argc<2 || !open_file(infile,argv[1]))
{
cerr<<"No input file!" << endl;
return EXIT_FAILURE;
}
TextQuery tq;
tq.read_file(infile);

while (true)
{
cout<<"enter word to look for , or q to quit ";
string s;
cin>>s;

if(!cin || s == "q")
break;
set<TextQuery::line_no> locs = tq.run_query(s);
print_results(locs,s,tq);
}
return 0;
}
//TextQuery.cpp
#include "TextQuery.h"


TextQuery::TextQuery()
{

}

TextQuery::~TextQuery()
{

}

void TextQuery::store_file(ifstream &is)
{
string textline;
while (getline(is,textline))
{
lines_of_text.push_back(textline);
}
}

void TextQuery::build_map()
{
for (line_no line_num = 0;line_num != lines_of_text.size();++line_num)
{
istringstream line (lines_of_text[line_num]);
string word;
while (line>>word)
{
word_map[word].insert(line_num);
}
}
}

set<TextQuery::line_no>
TextQuery::run_query(const string &query_word) const
{
map<string, set<line_no> >::const_iterator
loc = word_map.find(query_word);
if(loc == word_map.end())
{
return set<line_no>();//return empty set
}
else
{
return loc->second;
}
}

string TextQuery::text_line(line_no line ) const
{
if(line <lines_of_text.size())
return lines_of_text[line];
throw out_of_range("line number out of range");
}
//TextQuery.h
qsd007 2007-03-09
  • 打赏
  • 举报
回复
共四个文件啊,都放在一个目录下面,
TestQuery 是一个类;分成.h 和 .cpp
MainFile 只是一个写main的cpp文件,包含了TestQuery.h
还有一个makefile文件
dabaocsdn 2007-03-09
  • 打赏
  • 举报
回复
最近刚刚能够写简单的makefile,路过一下
wflyfox 2007-03-09
  • 打赏
  • 举报
回复
TestQuery.cpp 这个文件在什么地方?
不是在其他的目录吧
qsd007 2007-03-08
  • 打赏
  • 举报
回复
怎么都没有人知道吗!!!!
天哪~~
wflyfox 2007-03-08
  • 打赏
  • 举报
回复
TestQuery.o:TestQuery.cpp
g++ -c TestQuery.cpp
MainFile.o:MainFile.cpp
g++ -c MainFile.cpp
qsd007 2007-03-07
  • 打赏
  • 举报
回复
试过拉,,,也是一样啊~~
两句是等价的
yisea123 2007-03-07
  • 打赏
  • 举报
回复
按楼上说的试试
拉卡尼休 2007-03-07
  • 打赏
  • 举报
回复
TestQuery.o MainFile.o : TestQuery.h
改成:
TestQuery.o:TestQuery.cpp TestQuery.h
g++ -c TestQuery.cpp
MainFile.o:MainFile.cpp TestQuery.h
g++ -c MainFile.cpp

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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