请大家帮我看一看link的问题
dfs.cc 功能实现 dfs.h 数据结构的声明 dfs-tst.cc 主函数
在window下面nmake,编译通过了,但link却发生错误。请各位帮我看看。谢谢啦哈。
源文件分别是:
/*
* filename: dfs.h
* src dir: d:\vc71\boost_1_31_0\work\depth_first_search\v0.1
* function: data struct declaration
* demonstrate how to create a dfs_time_visitor
* */
#include <queue>
#include <vector>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/pending/integer_range.hpp>
#include <boost/pending/indirect_cmp.hpp>
#define N 13
using namespace std;
using namespace boost;
/* the name dfs_time_visitor is not accurate cos I have put the examine_edge() and tree_edge() in the visitor */
template <typename TimeMap>
class dfs_timer_visitor:public default_dfs_visitor{
typedef typename property_traits<TimeMap>::value_type T;
public:
dfs_timer_visitor(TimeMap timeMap_, T time_):timeMap(timeMap_),time(time_){}
template<typename Vertex, typename Graph>
void discover_vertex(Vertex v, const Graph& g);
template<typename Edge, typename Graph>
void examine_edge(Edge e, const Graph& g);
template <typename Edge, typename Graph>
void tree_edge(Edge e, const Graph& g);
private:
TimeMap timeMap;
T time;
};
/*
* filename: dfs.cc
* src dir: d:\vc71\boost_1_31_0\work\depth_first_search\v0.1
* function: implement file
* demonstrate how to create a dfs_time_visitor
* */
#include "dfs.h"
template<typename TimeMap>
template<typename Vertex, typename Graph>
void dfs_timer_visitor<TimeMap>::discover_vertex(Vertex v, const Graph& g){
put(timeMap, v, time++);
}
template<typename TimeMap>
template<typename Edge, typename Graph>
void dfs_timer_visitor<TimeMap>::examine_edge(Edge e, const Graph& g){
std::cout << source(e, g) << " --> " << target(e, g) << std::endl;
}
template<typename TimeMap>
template<typename Edge, typename Graph>
void dfs_timer_visitor<TimeMap>::tree_edge(Edge e, const Graph& g){
std::cout << source(e, g) << " --> " << target(e, g) << std::endl;
}
/*
* filename: dfs_tst.cc
* src dir: d:\vc71\boost_1_31_0\work\depth_first_search\v0.1
* function: vois main() demonstrate how to create a dfs_time_visitor
* */
#include "dfs.h"
void main(){
typedef adjacency_list<vecS, vecS, directedS, property<vertex_discover_time_t, std::size_t> > Graph;
typedef std::pair<int, int> E;
/* p149 figure 19.1 */
E edge_array[] = {E(4, 2), E(11, 12), E(4, 11), E(5, 4), E(2, 3), E(12, 9), E(4, 3), E(0, 5),
E(3, 2), E(9, 10), E(3, 5), E(6, 4), E(0, 6), E(9, 11), E(7, 8), E(6, 9),
E(0, 1), E(8, 9), E(8, 7), E(7, 6), E(2, 0), E(10, 12)};
/* create a graph */
Graph g(N);
for(std::size_t i = 0; i < sizeof(edge_array)/sizeof(E); ++i){
add_edge(edge_array[i].first, edge_array[i].second, g);
}
print_graph(g);
/* create a dfs_timer_visitor */
typedef property_map<Graph, vertex_discover_time_t>::type t_map_t;
t_map_t t_map = get(vertex_discover_time, g);
typedef property_traits<t_map_t>::value_type T;
T t = 0;
dfs_timer_visitor<t_map_t> vis(t_map, t);
/* depth_first_search */
depth_first_search(g, boost::visitor(vis));
std::vector<T> v(num_vertices(g));
graph_traits<Graph>::vertex_iterator vi, vi_end;
// for(int i = 0,boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi, ++i)
// v[i] = t_map[*vi];
int ii = 0;
for(boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi, ++ii)
v[ii] = t_map[*vi];
integer_range<std::size_t> range(0, N);
std::vector<T> discover_order(N);
std::copy(range.begin(), range.end(), discover_order.begin());
std::sort(discover_order.begin(), discover_order.end(), indirect_cmp<T*, std::less<T> >(&v[0]));
for(int i = 0;i < N; ++i)
cout << discover_order[i] << " ";
}
makefile文件时:
all:dfs.obj dfs_tst.obj
cl dfs.obj dfs_tst.obj /o dfs_tst.exe
dfs.obj:dfs.cc dfs.h
cl /c dfs.cc
dfs_tst.obj:dfs_tst.cc
cl /c dfs_tst.cc
clean:
del *.obj *.exe
我是用vc71编译的。.obj都生成了,但link的时候不对。