编译和链接多个文件时使用g++
g++ when compile and link multiple files
我遇到g++编译/链接问题。我想实现一个动态数组。我将类定义和实现分离为"DArray.h"answers"DArray.copp"文件。并在"DArraytest.cpp"文件中进行测试,该文件中包含一个主函数n。
所有这些文件都在同一目录中,我使用以下命令进行编译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_stream>&std::endl>(std::basic_stream>&)'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_initization_and_edestruction_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):对"__gxx_personality_v0"的未定义引用collect2:错误:ld返回1退出状态
有人能帮我吗
我认为您需要向g++提供所有.cpp文件名。为了避免这种情况,您可以创建一个makefile,它可以自动将相同的编译规则应用于所有.cpp文件
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- c++库的公共头文件中应该包含什么
- 用c++从输入文件中读取另一行
- Cppcheck生成xml转储文件
- 读取文件的最后一行并输入到链接列表时出错
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 如何将内容数组写入文本文件?
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到