référence non définie à une fonction, même lorsque les bibliothèques sont incluses

voix
0

Je fais un programme simple pour calculer des matrices. Il y a 3 fichiers au total, mat.h, mat.cppet main.cpp.

Contenu de mat.h:

#ifndef MAT_H
#define MAT_H

#include <array>

template<.....>
class Mat {
    ...
};

#endif

Contenu de mat.cpp:

#include mat.h

using std::array;

// Definitions of Mat functions/constructors

Contenu de main.cpp:

#include <iostream>
#include mat.h
using namespace std;

int main() {
    //Here I create a couple of Mat objects.
    return 0;
}

Le problème est que quand je compile à l'aide , g++ mat.cpp main.cppil me donne une erreur de liaison, en disant que toutes les fonctions définies dans mat.cppne sont pas définies (référence non définie). Le problème disparaît si je définis la principale fonction mat.cpp, mais je veux avoir des fichiers différents.

Par souci de clarté, voici le message d'erreur:

main.o: En la función `main':
main.cpp:(.text+0x42): referencia a `Mat<double, 1ul, 2ul>::Mat(std::array<double, 2ul> const&)' sin definir
main.cpp:(.text+0x6e): referencia a `Mat<double, 1ul, 2ul>::Mat(std::array<double, 2ul> const&)' sin definir
main.cpp:(.text+0x9a): referencia a `Mat<double, 2ul, 1ul>::Mat(std::array<double, 2ul> const&)' sin definir
main.cpp:(.text+0xc6): referencia a `Mat<double, 2ul, 1ul>::Mat(std::array<double, 2ul> const&)' sin definir
main.cpp:(.text+0x10c): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::Mat(std::array<Mat<double, 1ul, 2ul>, 2ul> const&)' sin definir
main.cpp:(.text+0x152): referencia a `Mat<Mat<double, 2ul, 1ul>, 2ul, 1ul>::Mat(std::array<Mat<double, 2ul, 1ul>, 2ul> const&)' sin definir
main.cpp:(.text+0x190): referencia a `Mat<int, 2ul, 2ul>::Mat(std::array<int, 4ul> const&)' sin definir
main.cpp:(.text+0x1c6): referencia a `Mat<int, 2ul, 2ul>::Mat(std::array<int, 4ul> const&)' sin definir
main.cpp:(.text+0x1fc): referencia a `Mat<int, 2ul, 2ul>::Mat(std::array<int, 4ul> const&)' sin definir
main.cpp:(.text+0x23e): referencia a `Mat<int, 2ul, 2ul>::Mat(std::array<int, 4ul> const&)' sin definir
main.cpp:(.text+0x254): referencia a `Mat<Mat<int, 2ul, 2ul>, 2ul, 2ul>::Mat(std::array<Mat<int, 2ul, 2ul>, 4ul> const&)' sin definir
main.cpp:(.text+0x2e7): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.o: En la función `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul> mult<double, int, 1ul, 2ul, 1ul, 2ul, 2ul, 2ul>(Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>, Mat<Mat<int, 2ul, 2ul>, 2ul, 2ul>)':
main.cpp:(.text._Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE[_Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE]+0x3a): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::Mat()' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE[_Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE]+0x8d): referencia a `Mat<Mat<int, 2ul, 2ul>, 2ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE[_Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE]+0xb9): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE[_Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE]+0xfc): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE[_Z4multIdiLm1ELm2ELm1ELm2ELm2ELm2EE3MatIS0_IT_XT1_EXT6_EEXT3_EXT5_EES0_IS0_IS1_XT1_EXT2_EEXT3_EXT4_EES0_IS0_IT0_XT2_EXT6_EEXT4_EXT5_EE]+0x10e): referencia a `Mat<double, 1ul, 2ul>& Mat<double, 1ul, 2ul>::operator+=<double>(Mat<double, 1ul, 2ul>)' sin definir
main.o: En la función `Mat<double, 1ul, 2ul> mult<double, int, 1ul, 2ul, 2ul>(Mat<double, 1ul, 2ul>, Mat<int, 2ul, 2ul>)':
main.cpp:(.text._Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE[_Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE]+0x2b): referencia a `Mat<double, 1ul, 2ul>::Mat()' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE[_Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE]+0x77): referencia a `Mat<double, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE[_Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE]+0x97): referencia a `Mat<int, 2ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.cpp:(.text._Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE[_Z4multIdiLm1ELm2ELm2EE3MatIT_XT1_EXT3_EES0_IS1_XT1_EXT2_EES0_IT0_XT2_EXT3_EE]+0xbe): referencia a `Mat<double, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIS_IiLm2ELm2EELm2ELm2EE[_ZTV3MatIS_IiLm2ELm2EELm2ELm2EE]+0x10): referencia a `Mat<Mat<int, 2ul, 2ul>, 2ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIS_IiLm2ELm2EELm2ELm2EE[_ZTV3MatIS_IiLm2ELm2EELm2ELm2EE]+0x18): referencia a `Mat<Mat<int, 2ul, 2ul>, 2ul, 2ul>::set(Mat<int, 2ul, 2ul> const&, unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIiLm2ELm2EE[_ZTV3MatIiLm2ELm2EE]+0x10): referencia a `Mat<int, 2ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIiLm2ELm2EE[_ZTV3MatIiLm2ELm2EE]+0x18): referencia a `Mat<int, 2ul, 2ul>::set(int const&, unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIS_IdLm1ELm2EELm1ELm2EE[_ZTV3MatIS_IdLm1ELm2EELm1ELm2EE]+0x10): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIS_IdLm1ELm2EELm1ELm2EE[_ZTV3MatIS_IdLm1ELm2EELm1ELm2EE]+0x18): referencia a `Mat<Mat<double, 1ul, 2ul>, 1ul, 2ul>::set(Mat<double, 1ul, 2ul> const&, unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIdLm2ELm1EE[_ZTV3MatIdLm2ELm1EE]+0x10): referencia a `Mat<double, 2ul, 1ul>::get(unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIdLm2ELm1EE[_ZTV3MatIdLm2ELm1EE]+0x18): referencia a `Mat<double, 2ul, 1ul>::set(double const&, unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIdLm1ELm2EE[_ZTV3MatIdLm1ELm2EE]+0x10): referencia a `Mat<double, 1ul, 2ul>::get(unsigned long, unsigned long)' sin definir
main.o:(.data.rel.ro._ZTV3MatIdLm1ELm2EE[_ZTV3MatIdLm1ELm2EE]+0x18): referencia a `Mat<double, 1ul, 2ul>::set(double const&, unsigned long, unsigned long)' sin definir
collect2: error: ld returned 1 exit status
Créé 19/09/2018 à 13:24
source utilisateur
Dans d'autres langues...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more