リンク時に奇妙なエラーが発生します。
ヘッダー:
グローバル.h
#include <cmath>
#include <iostream>
#include <vector>
#include <blitz/tinyvec2.h>
typedef blitz::TinyVector<double,3> vettore;
#include "animal.h"
animal.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
ファイルがあります
main.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
、コードが機能します。誰かが私に理由を説明できますか?
編集: https://github.com/syntheticpp/blitz/blob/master/blitz/tinyvec2.hへのリンクは次のとおりです。blitz/tinyvec2.h