代码:mingwg++链接器错误
Codelite MinGW G++ Linker Error
我在codelite上有一个链接器问题。当我把。hpp和。cpp文件放在我单元测试的main中,一切正常。
这是我的。hpp文件:
class ITPropertiesBase
{
public:
virtual ~ITPropertiesBase(){}
virtual const char *getName() = 0;
};
template <typename T>
class Properties : public ITPropertiesBase
{
public:
Properties(const char *name, T value);
~Properties();
const char *getName();
private:
const char *m_name;
T m_value;
};
这是我的。cpp文件:
template <typename T> Properties<T>::Properties(const char *name, T value) : m_name(name), m_value(value)
{
}
template <typename T> Properties<T>::~Properties()
{
}
template <typename T> const char* Properties<T>::getName()
{
return m_name;
}
这是我的main:
#include <iostream>
#include <vector>
#include <string>
#include "Properties.hpp"
int main(int argc, char **argv)
{
const char *testInput = "test";
std::vector<ITPropertiesBase*> as;
as.push_back(new Properties<int>(testInput, 5));
return 0;
}
链接器输出:
C:Windowssystem32cmd.exe /c "C:/MinGW-4.8.1/bin/mingw32-make.exe -j4 -e -f Makefile"
"----------Building project:[ Interfaces - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'E:/CodeLite/ElysiumEngine/Interfaces'
C:MinGW-4.8.1bing++.exe -c "E:/CodeLite/ElysiumEngine/Interfaces/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I.
C:MinGW-4.8.1bing++.exe -c "E:/CodeLite/ElysiumEngine/Interfaces/Properties.cpp" -g -O0 -Wall -o ./Debug/Properties.cpp.o -I. -I.
C:MinGW-4.8.1bing++.exe -o ./Debug/Interfaces @"Interfaces.txt" -L.
./Debug/main.cpp.o: In function `main':
E:/CodeLite/ElysiumEngine/Interfaces/main.cpp:11: undefined reference to `Properties<int>::Properties(char const*, int)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Interfaces] Error 1
mingw32-make.exe: *** [All] Error 2
Interfaces.mk:79: recipe for target 'Debug/Interfaces' failed
mingw32-make.exe[1]: Leaving directory 'E:/CodeLite/ElysiumEngine/Interfaces'
Makefile:4: recipe for target 'All' failed
2 errors, 0 warnings
有人知道发生了什么事吗?
这可能适用于您:
- 将头文件移出源目录
它工作时,他们都在同一个文件夹或不,最好是重新定位他们。你需要告诉编译器它们在哪里,与你的项目有关。
change to #include <Properties.hpp>
然后将头文件放入include目录。
然后在编译器标志中,添加包含头文件的目录。通常是一个名为include的目录。例如:
-I../include/
这个编译器标志将包含父目录的include文件夹。其中的所有头文件将对编译器可见。通常,所有源代码或cpp文件都捆绑在一起。
- 还有一件事,试着把你的模板移到头文件中。
参考http://codelite.org/LiteEditor/ProjectSettings。
编辑:补充子弹
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接