函数___tmainCRTStartup中引用未解析的外部符号_main
unresolved external symbol _main referenced in function ___tmainCRTStartup
当我尝试编译 c++ 控制台应用程序时,我收到此错误:">函数 __tmainCRTStartup 中引用的未解析的外部符号 main"。我已经做了一些搜索,我能找到的就是将我的"链接器"从窗口更改为控制台,反之亦然。这不起作用,我什至尝试创建一个新的控制台应用程序。
我不确定是什么原因造成的,template <typename T>
是否有可能在两个文件中出现时引起混淆?这里的任何帮助将不胜感激。
代码如下:
主.cpp:
#include <iostream>
#include "tools.h"
using namespace tools;
template <typename T>
int main()
{
T input1;
T input2;
std::cout << "Enter in 1st number: " << endl;
std::cin >> input1;
std::cout << "Enter in 2nd number: " << endl;
std::cin >> input2;
std::cout << "num1 - num2 = [" << numberDifference(input1, input2) << "]" << endl;
getchar();
getchar();
return 0;
}
工具.h:
#include <iostream>
namespace tools
{
template <typename T>
T numberDifference(T num1, T num2)
{
if(num1 > num2)
return num1 - num2;
else
return num2 - num1;
}
};
删除main
函数的template
定义。
或者至少从适当的main
函数调用它。
例如
template< typename T >
int templated_main( int c, char** argv )
{
// What was in your original main function....
}
int main( int c, char** argv )
{
return templated_main<int>( c, argv );
}
删除 main 之前的template <typename T>
。这将使main
成为模板函数。
并将T input1; T input2;
更改为某些特定类型,例如 int
或 float
.
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 代码在main()中运行,但在函数中出现错误
- 在函数内部的声明中初始化数组,并在外部使用它
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 使外部项目可用于find_package CMake
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- 不确定要在我的main中放入什么才能使我的代码正常工作
- C++:来自外部文件的Trivia
- 从函数角度看ID到文件路径的内部与外部映射
- 外部函数在 main() 上调用时返回分段错误 11.(C++)
- 未解析的外部符号__imp_glewInit函数 main 中引用
- main.obj : 错误 LNK2019: 未解析的外部符号 公共: __cdecl.
- C 外部阵列在标头中声明,在main.cpp中不可用
- QT错误:LNK1120:1未解决的外部Main.OBJ:-1:错误:LNK2019运行QMAKE
- C++ 如何从 main() 外部访问在 main() 中初始化的对象
- visual main.obj:错误LNK2019:C++中未解析的外部符号
- 在C++中清除数组会在外部函数中而不是在main()中产生编译器错误
- C++对象在main外部初始化