簡體   English   中英

VS2010鏈接器錯誤

[英]VS2010 Linker Error

解決了我的“ WorkoutGeneratorMain.cpp”被IDE分類為C ++頭文件。 我不確定為什么會這樣,但我已解決。 現在,我要處理所有其他錯誤。

謝謝大家!

================================================== =

在Visual Studio 2010 Professional中編譯程序時,出現以下錯誤:

------構建開始:項目:WorkoutGenerator,配置:調試Win32 ------
構建開始於2012年8月15日下午12:19:18。
InitializeBuildStatus:
觸摸“ Debug \\ WorkoutGenerator.unsuccessfulbuild”。
ClCompile:
LiftClass.cpp
ManifestResourceCompile:
所有輸出都是最新的。
MSVCRTD.lib(crtexe.obj):錯誤LNK2019: 在_ _tmainCRTStartup中引用的未解析的外部符號主要
C:\\ Users \\ Shanalex \\ Documents \\ Programming \\ C ++ Programming \\ WorkoutGenerator \\ WorkoutGenerator \\ Debug \\ 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

然后,我有了Lift類的.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;
}

任何建議,不勝感激。

謝謝,

-亞歷克斯

您可能會認為int main()是可執行文件的入口點,但不是(不必要)。 :)根據項目設置,運行時可能會調用wmainmain 這就是為什么您改用_tmain原因,它是擴展到運行時_tmain的宏。

嘗試將其更改為:

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

PS-這應該是自動生成的,也許您刪除了它而不是替換_tmain的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM