我在链接时遇到了一个奇怪的错误。
标题:
全局.h
#include <cmath>
#include <iostream>
#include <vector>
#include <blitz/tinyvec2.h>
typedef blitz::TinyVector<double,3> vettore;
#include "animal.h"
动物.h
#ifndef __ANIMAL_H
#define __ANIMAL_H
//! basic data structure for an animal -------------------------
struct Animal
{
int age;
public:
Animal(int _age) : age(_age) {}
};
//! contains info about a pair of animals ----------------------
struct AnimalPairs
{
vettore distance;
AnimalPairs( const vettore& _distance ) : distance(_distance) {}
};
typedef std::vector<AnimalPairs> pair_list;
//! data structure for a group of animals ----------------------
class AnimalVector
{
private:
std::vector<Animal> animals;
pair_list pairs;
public:
AnimalVector( const AnimalVector &other );
};
#endif
这是*cpp
文件
主文件
#include "global.h"
int main ()
{
std::cout<< "Hello" << std::endl;
}
动物.cpp
#include "global.h"
AnimalVector::AnimalVector( const AnimalVector &other )
{
pairs = other.pairs;
}
编译我使用
g++ main.cpp animal.cpp -I/usr/include/boost -I/fs01/ma01/homes/matc/local/blitz/include
这是我得到的错误:
/tmp/ccGKHwoj.o: In function `AnimalPairs::AnimalPairs(AnimalPairs const&)':
animal.cpp:(.text._ZN11AnimalPairsC2ERKS_[_ZN11AnimalPairsC5ERKS_]+0x1f):
undefined reference to \`blitz::TinyVector<double,
3>::TinyVector(blitz::TinyVector<double, 3> const&)'
collect2: error: ld returned 1 exit status
由于某些原因,如果我将AnimalVector
构造函数设置为inline
,则代码将起作用。有人可以解释我为什么吗?
编辑:这里是blitz/tinyvec2.h
https://github.com/syntheticpp/blitz/blob/master/blitz/tinyvec2.h的链接