Jump to content

LNK1120+2019 in example from C++ Through Game Programming

かあびぃ

It's odd. I get 2 fatal errors(LNK1120, and LNK2019) when trying to build a direct example taken straight from the book. Any ideas?

 

 

        

// Game Stats
// Demonstrates declaring and initializing variables

#include <iostream>
using namespace std;

int main()
{
    int score;                
    double distance;        
    char playAgain;            
    bool shieldsUp;            

    short lives, aliensKilled;

    score = 0;
    distance = 1200.76;
    playAgain = 'y';
    shieldsUp = true;
    lives = 3;
    aliensKilled = 10;
        
    double engineTemp = 6572.89;

    cout << "\nscore: "        << score << endl;
    cout << "distance: "    << distance << endl;
    cout << "playAgain: "    << playAgain << endl;
    //skipping shieldsUp since you don't generally print Boolean values
    cout << "lives: "        << lives << endl;
    cout << "aliensKilled: "<< aliensKilled << endl;
    cout << "engineTemp: "    << engineTemp << endl;

    int fuel;
    cout << "\nHow much fuel? ";
    cin >> fuel;
    cout << "fuel: " << fuel << endl;

    typedef unsigned short int ushort;
    ushort bonus = 10;
    cout << "\nbonus: " << bonus << endl;

    return 0;
}
 

 

 

CPU: i7 5820k @3.2           Motherboard: Asrock x99x Killer           CPU Cooler: Cooler Master Hyper 212 EVO           GPU: Asus 280x DirectCU II

 

 

Case: NZXT S340            RAM: 8GB Hyperx Fury DDR4 @2133MHz           HDD: Corsair Force LS 120GB           PSU: EVGA GQ 650W 80+GOLD

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, かあびぃ said:

using namespace std;

remove this line from your code.

and make sure "main" is set to be entry point in the compiler, linker settings when building the project

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, DXMember said:

remove this line from your code.

Unfortunately i get the same errors 

 

 

CPU: i7 5820k @3.2           Motherboard: Asrock x99x Killer           CPU Cooler: Cooler Master Hyper 212 EVO           GPU: Asus 280x DirectCU II

 

 

Case: NZXT S340            RAM: 8GB Hyperx Fury DDR4 @2133MHz           HDD: Corsair Force LS 120GB           PSU: EVGA GQ 650W 80+GOLD

Link to comment
Share on other sites

Link to post
Share on other sites

Those are linker errors (unresolved externals), so the program compiled fine, the linker just can't find some external symbols. Could you paste the full error lines given, they should include information about the missing symbol names.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Unimportant said:

Those are linker errors (unresolved externals), so the program compiled fine, the linker just can't find some external symbols. Could you paste the full error lines given, they should include information about the missing symbol names.

Sure


Error LNK2019    unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

 

 

CPU: i7 5820k @3.2           Motherboard: Asrock x99x Killer           CPU Cooler: Cooler Master Hyper 212 EVO           GPU: Asus 280x DirectCU II

 

 

Case: NZXT S340            RAM: 8GB Hyperx Fury DDR4 @2133MHz           HDD: Corsair Force LS 120GB           PSU: EVGA GQ 650W 80+GOLD

Link to comment
Share on other sites

Link to post
Share on other sites

For some reason the linker can't find your 'main' function. It's however clearly present in the code (which compiles and runs fine for me, with g++). So there must be something wrong with your project configuration. Are you sure the project is set to win32 console application ? And Linker -> System -> SubSystem should be Windows.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Unimportant said:

For some reason the linker can't find your 'main' function. It's however clearly present in the code (which compiles and runs fine for me, with g++). So there must be something wrong with your project configuration. Are you sure the project is set to win32 console application ? And Linker -> System -> SubSystem should be Windows.

It is a win32 console, but not sure about the linker settings, how do i set those?

 

 

CPU: i7 5820k @3.2           Motherboard: Asrock x99x Killer           CPU Cooler: Cooler Master Hyper 212 EVO           GPU: Asus 280x DirectCU II

 

 

Case: NZXT S340            RAM: 8GB Hyperx Fury DDR4 @2133MHz           HDD: Corsair Force LS 120GB           PSU: EVGA GQ 650W 80+GOLD

Link to comment
Share on other sites

Link to post
Share on other sites

Right click on the project you're working on (not the solution), select properties and in the menu that pops up there should be a submenu for linker settings.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Unimportant said:

Right click on the project you're working on (not the solution), select properties and in the menu that pops up there should be a submenu for linker settings.

 

Subsystem says: Console(/SUBSYSTEM:CONSOLE)

 

 

CPU: i7 5820k @3.2           Motherboard: Asrock x99x Killer           CPU Cooler: Cooler Master Hyper 212 EVO           GPU: Asus 280x DirectCU II

 

 

Case: NZXT S340            RAM: 8GB Hyperx Fury DDR4 @2133MHz           HDD: Corsair Force LS 120GB           PSU: EVGA GQ 650W 80+GOLD

Link to comment
Share on other sites

Link to post
Share on other sites

Can't really help you further then. The code is OK. It's a project setting somewhere. Maybe start with a fresh project and try again.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×