首页 文章

g编译和链接多个文件时

提问于
浏览
-1

我遇到g编译/链接问题 . 我想实现一个动态数组 . 我将类定义和实现分为“DArray.h”和“DArray.cpp”文件 . 并在“DArraytest.cpp”文件中进行测试,其中包含一个main functionn .

所有文件都在同一目录中,我使用以下命令编译g * .cpp

但它仍然给我这样的链接错误/tmp/cc4tu73o.o:在函数 __static_initialization_and_destruction_0(int, int)': DArray.cpp:(.text+0x1d): undefined reference to std :: ios_base :: Init :: Init()'DArray.cpp :( . text 0x34):未定义引用 std::ios_base::Init::~Init()' /tmp/ccdHUZjJ.o: In function main':DArraytest . cpp :( . text 0x12):未定义引用 DArray<int>::DArray()' DArraytest.cpp:(.text+0x2e): undefined reference to DArray :: append(int const&)'DArraytest.cpp :( . text 0x4a):未定义引用 DArray<int>::append(int const&)' DArraytest.cpp:(.text+0x66): undefined reference to DArray :: append(int const&)'DArraytest.cpp :( . text 0x82):未定义引用 DArray<int>::append(int const&)' DArraytest.cpp:(.text+0xa3): undefined reference to std :: cout'DArraytest.cpp :( . text 0xa8):未定义引用 std::ostream::operator<<(int)' DArraytest.cpp:(.text+0xb0): undefined reference to std :: basic_ostream>&std :: endl>(std :: basic_ostream>&)'DArraytest.cpp :( . text 0xb8):未定义引用 std::ostream::operator<<(std::ostream& (*)(std::ostream&))' DArraytest.cpp:(.text+0xc9): undefined reference to DArray :: ~DArray()'DArraytest.cpp :( . text 0xeb):未定义引用 DArray<int>::~DArray()' /tmp/ccdHUZjJ.o: In function __static_initialization_and_destruction_0(int,int)':DArraytest.cpp :( . text 0x11d) :未定义引用 std::ios_base::Init::Init()' DArraytest.cpp:(.text+0x134): undefined reference to std :: ios_base :: Init :: ~Init()' /tmp/ccdHUZjJ.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0' collect2:错误:ld返回1退出状态

有人能帮我吗

1 回答

  • 0

    我认为您需要向g提供所有.cpp文件名 . 为避免这种情况,您可以创建一个makefile,它可以自动将相同的编译规则应用于所有.cpp文件

相关问题