解决我的“WorkoutGeneratorMain.cpp”被IDE分类为C++头。我不知道为什么发生,但我修好了。现在我可以处理我所有的其他错误。VS2010链接器错误
谢谢大家!
============================================== =====
在Visual Studio 2010专业版编译时,我的计划,我得到以下错误:
------构建开始:项目:WorkoutGenerator,配置:调试的Win32 --- ---
开始建造2012/8/15 12:19:18 PM。
InitializeBuildStatus:
触摸“Debug \ WorkoutGenerator.unsuccessfulbuild”。
ClCompile:
LiftClass.cpp
ManifestResourceCompile:
所有输出均达到最新。
MSVCRTD.LIB(crtexe.obj):错误LNK2019:解析外部符号主要在结引用_ _tmainCRTStartup
C:\用户\ Shanalex \文件\编程\ C++编程\ WorkoutGenerator \ WorkoutGenerator \调试\ WorkoutGenerator .exe:致命错误LNK1120:1个未解析的外部设备
在我的搜索中,我发现了几个指南来解决这个问题;但是,他们几乎都提示该文件是设置为控制台设置的Windows应用程序,反之亦然。我的程序是一个控制台应用程序,所有设置对于win32控制台应用程序来说都是正确的。一些地方有链接错误,但我似乎没有任何其他人有我的项目设置的问题。
我对C++和VS2010中的多部分程序相当陌生。我可以很容易地犯一个基本的错误,但是在将我的代码与各种教程和书籍的代码进行比较时,我一直无法找到它。
我有三个代码文件,如下所示:
LiftClass.h
//Lift Classes
//Defines the Lift Class
#ifndef LIFTCLASSHEADER_H_INCLUDED
#define LIFTCLASSHEADER_H_INCLUDED
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <ctime>
using namespace std;
class Lift
{
public:
string LName;
string LType;
string LBody;
vector<double> LLoadScale;
Lift(string Name, string Type, string Body,
double Pawn, double Bishop, double Knight, double Rook, double Royal);
};
Lift::Lift(string Name, string Type, string Body,
double Pawn, double Bishop, double Knight, double Rook, double Royal)
{
LName = Name,
LType = Type,
LBody = Body,
LLoadScale.push_back(Pawn),
LLoadScale.push_back(Bishop),
LLoadScale.push_back(Knight),
LLoadScale.push_back(Rook),
LLoadScale.push_back(Royal);
}
#endif
然后,我有我的电梯类的.cpp实现,并为他们随机化的功能。
LiftClass.cpp
//Exercise Randomizer using Lift Class
//Initializes Lifts for use in Workout Generator
//Version 2.0 will reference Database
#include "LiftClass.h"
Lift exerciseRandomizer() //Define database of exercise & randomly select one
{
vector<Lift> LiftDatabase;
Lift Clean("Clean", "Olympic", "Full", .33, .66, 1, 1.33, 1.66);
Lift Bench("Bench Press", "Heavy", "Upper", .33, .66, 1, 1.5, 2);
LiftDatabase.push_back(Clean);
LiftDatabase.push_back(Bench);
srand(static_cast<unsigned int>(time(0))); //Seed random number
unsigned randomNumber = rand(); //Generate Random Number
//Get random between 1 and total lift count
unsigned randomSelector = (randomNumber % LiftDatabase.size());
return LiftDatabase[randomSelector];
}
最后,我有我的主要功能WorkoutGeneratorMain.cpp
WorkoutGeneratorMain.cpp
//Workout Generator
//Generates workouts based on goal and fitness level
#include "LiftClass.h"
int main()
{
exerciseRandomizer();
Lift LiftA = exerciseRandomizer();
cout << "\n\nYour first lift is: " << LiftA.LName << "\n\n Its lift type is: " << LiftA.LType << endl;
cout << "\n\nGood Luck!" << endl;
system("pause");
return 0;
}
任何建议都非常赞赏。
感谢,
-Alex
题外话题,但你应该避免使用名称空间标准;特别是在头文件中。 – juanchopanza 2012-08-15 18:21:59
我看到'LiftClass.cpp'被编译:'ClCompile:LiftClass.cpp'。但是我没有看到'WorkoutGeneratorMain.cpp'的相同消息。你确定,它包含在你的项目中吗? – Lol4t0 2012-08-15 18:25:46
如果您正在链接不使用相同运行时的组件,则可能会出现此错误。像单线程/多线程,调试/发布等。 – 2012-08-15 18:27:31