referencia indefinida a alguna función, incluso cuando se incluyen las bibliotecas

votos
0

Estoy haciendo un programa sencillo para calcular matrices. Hay 3 archivos en total, mat.h, mat.cppy main.cpp.

Contenido de mat.h:

#ifndef MAT_H
#define MAT_H

#include <array>

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

#endif

Contenido de mat.cpp:

#include mat.h

using std::array;

// Definitions of Mat functions/constructors

Contenido de main.cpp:

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

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

El problema es que cuando compilo usando g++ mat.cpp main.cppme da un error de vinculador, diciendo que todas las funciones definidas en mat.cppno están definidos (referencia indefinida). El problema desaparece si defino la función principal de mat.cpp, pero yo quiero tener diferentes archivos.

En aras de la claridad, aquí está el mensaje de error:

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
Publicado el 19/09/2018 a las 13:24
fuente por usuario
En otros idiomas...                            

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