Meghatározatlan referencia néhány funkció akkor is, ha a könyvtárak szerepelnek

szavazat
0

Csináltam egy egyszerű program kiszámítja mátrixok. Jelenleg 3 fájl összesen mat.h, mat.cppés main.cpp.

Tartalma mat.h:

#ifndef MAT_H
#define MAT_H

#include <array>

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

#endif

Tartalma mat.cpp:

#include mat.h

using std::array;

// Definitions of Mat functions/constructors

Tartalma main.cpp:

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

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

A probléma az, hogy amikor összeállításhoz használ g++ mat.cpp main.cppez ad nekem egy kapcsoló hiba, mondván, hogy minden meghatározott feladatok mat.cppnincsenek meghatározva (undefined reference). A probléma megszűnik, ha meghatározza a fő funkciója az mat.cpp, de azt szeretné, hogy a különböző fájlokat.

Az egyértelműség kedvéért, itt a hibaüzenet jelenik meg:

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
A kérdést 19/09/2018 13:24
a forrás felhasználó
Más nyelveken...                            

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