2012-08-15 61 views
0

解决我的“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

+1

题外话题,但你应该避免使用名称空间标准;特别是在头文件中。 – juanchopanza 2012-08-15 18:21:59

+3

我看到'LiftClass.cpp'被编译:'ClCompile:LiftClass.cpp'。但是我没有看到'WorkoutGeneratorMain.cpp'的相同消息。你确定,它包含在你的项目中吗? – Lol4t0 2012-08-15 18:25:46

+0

如果您正在链接不使用相同运行时的组件,则可能会出现此错误。像单线程/多线程,调试/发布等。 – 2012-08-15 18:27:31

回答

3

你会认为int main()是可执行文件的入口点,但它不是(必然)。 :)根据项目设置,运行时可能会调用wmainmain。这就是为什么你使用_tmain,这是一个扩展到运行时所期望的宏。

尝试将其更改为:

int _tmain(int argc, _TCHAR* argv[]) 

PS - 这应该是自动生成的,也许你删除它,而不是替代的_tmain内容。

+1

编译器应根据您选择的运行时间为您处理。如果不是这样,那么该项目可能没有正确的运行时间来连接它所连接的库...... – 2012-08-15 18:28:38

+0

'int main()'不应该引起任何问题。 '_tmain'允许Unicode应用程序以Unicode字符串的形式接收命令行参数,但不要求_tmain'使用'_tmain'。 – 2012-08-15 18:32:40

+0

@PeterRitchie我认为你的意思是IDE ... – 2012-08-15 18:49:32