简体   繁体   中英

VS2010 Linker Error

Solved My "WorkoutGeneratorMain.cpp" was classified as a C++ header by the IDE. I'm not sure why that happened, but I fixed it. Now I get to deal with all of my other bugs.

Thanks all!

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

I get the following error when compiling my program in Visual Studio 2010 Professional:

------ Build started: Project: WorkoutGenerator, Configuration: Debug Win32 ------
Build started 8/15/2012 12:19:18 PM.
InitializeBuildStatus:
Touching "Debug\\WorkoutGenerator.unsuccessfulbuild".
ClCompile:
LiftClass.cpp
ManifestResourceCompile:
All outputs are up-to-date.
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol main referenced in unction _ _tmainCRTStartup
C:\\Users\\Shanalex\\Documents\\Programming\\C++Programming\\WorkoutGenerator\\WorkoutGenerator\\Debug\\WorkoutGenerator.exe : fatal error LNK1120: 1 unresolved externals

In my searching, I have found several guides to fixing this; however, they almost all suggest that the file is a windows application set to console settings or vice versa. My program is a console application, and all settings appear to be correct for a win32 console application. Some where there is a linking error, but I don't seem to have any of the problems with my project settings that others have.

I am fairly new to multipart programs in C++ and VS2010. I could very easily be making an elementary mistake, but I haven't been able to find it when comparing my code to that of various tutorials and books.

I have three code files, as follows:

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

Then, I have my .cpp implementation of the lift class, and a function for randomizing them.

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];
}

And finally, I have my main function 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;
}

Any suggestions are greatly appreciated.

Thanks,

-Alex

You'd think that int main() is the entry point of the executable, but it's not (necessarily). :) Depending on project settings, the runtime might call wmain or main . Which is why you use _tmain instead, which is a macro expanding to what the runtime expects.

Try changing it to:

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

PS - this should have been generated automatically, perhaps you deleted it instead of replacing the contents of _tmain .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM