Like Tree1Likes
  • 1 Post By rcgldr

Unresolved externals(??)

This is a discussion on Unresolved externals(??) within the C++ Programming forums, part of the General Programming Boards category; I'm new to this site and C++ programming. I'm making a text adventure game and am trying to link together ...

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    4

    Unresolved externals(??)

    I'm new to this site and C++ programming. I'm making a text adventure game and am trying to link together two different story paths (.cpp files). I have referenced them in a header in order to link them, but for some reason when it doesn't like it:

    Code:
    int FirstPhase()
    		{
    		int Path1;
    
    
    
    
    	system("cls");
    		cout << "______________________________________________________________________________" << endl;
    		cout << "______________________________________________________________________________" << endl;
    		cout << "The night is young, you climb out of your treetop sanctuary into vegitation   " << endl;
    		cout << "below. Preceding you, is a number of different paths. Which do you choose "<< endl;
    		cout << "______________________________________________________________________________" << endl;
    		cout <<" 1 - A dirt road leading out the forrest to the city." << endl;
    		cout <<" 2 - A small path leading to the dark lands." << endl;
    		cout <<" 3 - A path leading to what seems to be a small stream." << endl;
    		cout << "______________________________________________________________________________" << endl;
    		cin >> Path1;
    		if(Path1 == 1)
    			{
    				Beep(262,500);
    			 cout << "_______________________Chapter One: New tomorrow_________________________" << endl;
    			 cout << "The small road leading out of the forrest is.." << endl;
    				Path1 = PhaseOnePT2();
    			}
    		else if(Path1 == 2)
    			{
    			Beep(262,500);
    			cout << "----------------------Chapter One: New tomorrow----------------------" << endl;
    			cout << "Upon entering the dark path, you begin to hear many noises, none" << endl;
    			cout << "of which seem welcoming." << endl;
    			Sleep(3000);
    			//Path1 = SecondPhase();
    			
    			}
    		else if(Path1 == 3)
    		{
    			Beep(262,500);
    			cout << "You walk down to the stream, following the sound of water, on arrival," << endl;
    			cout << "you realise that the rapids are far too fast for you to push against." << endl;
    			cout << "A freakrock slide closes the path you used to get to the river." << endl;
    			cout << "Only one path remains open, the path to the darklands." << endl;
    			Sleep(5000);
    			//Path1 = SecondPhase();
    
    
    			
    		}
    		else
    		{
    			cout << "You are doing it wrong, warrior! Press either '1','2' or '3', nothing else!" << endl;
    			
        cout << "\n----------------------Press any key to continue----------------------" << endl;
      //  _getch();
    		}
    		system("cls");
    		return 0;
    	
    		};
    The errors are:
    error LNK2019: unresolved external symbol "int __cdecl SecondPhase(void)" (?SecondPhase@@YAHXZ) referenced in function "int __cdecl FirstPhase(void)"



    When i comment out
    Code:
     Path1 = SecondPhase();
    the error disappears. I don't know how to get it to work.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You're calling a function "SecondPhase". Therefore you need to write that function.

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    4
    Sorry i should have posted all the code
    Code:
    #include <iostream>
    #include "mage.h"
    #include "Warrior.h"
    #include "Rogue.h"
    #include "CharacterType.h"
    #include <memory>
    #include <string>
    #include <string.h>
    #include "Inventory.h"
    #include "blankEnemy.h"
    #include "Enemy.h"
    #include "Boss.h"
    #include <cstdlib>
    #include <ctime>
    #include "DeathMenu.h"
    #include "GameStart.h"
    #include "FirstPhase.h"
    #include <Windows.h>
    #include "SecondPhase.h"
    using namespace std;
    
    int SecondPhase(blankCharacter, blankEnemy,Inventory, string name, std::unique_ptr<blankCharacter> myCharacter,std::unique_ptr<blankEnemy> myEnemy, std::unique_ptr<Inventory> myInventory,std::unique_ptr<blankEnemy>myBoss)
            
            {
            
            int Path2;
        
    
    
            
            cout << "______________________________________________________________________________" << endl;
            cout << "______________________________________________________________________________" << endl;
            cout << "You start walking to the dark lands, you've lost all sense of time, and space   " << endl;
            cout << "all that has greeted you for what seems like an eternity was the darkness of the "<< endl;
            cout << "abyss. In the distance you see a glimer of light, and what seems to be a pert" << endl;
            cout << "figure, what will you do?" << endl;
            cout << "______________________________________________________________________________" << endl;
            cout <<" 1 - Remain shourded in darkness, and follow it, keeping safe as it could be a " << endl;
            cout <<" threat" << endl;
            cout <<" 2 - Confront the figure" << endl;
            cout << "______________________________________________________________________________" << endl;
            cin >> Path2;
            if(Path2 == 1)
                {
                 cout << "_______________________Chapter two: Blackest Night_________________________" << endl;
                 cout << "You try to conceal yourself in the dark abyss. Little do you know that " << endl;
                 cout << "the creature has already detected you, using it's physical form to allure" << endl;
                 cout << "you. Get ready for battle." << endl;
                 cout << "___________________________________________________________________________" << endl;
                 cout << "___________________________________________________________________________" << endl;
                 do
                        {
                    
                        cout << name << endl;
                        cout << "Magic: " << myCharacter->getMagic() << endl;
                        cout << "Stamina: " << myCharacter->getStamina() << endl;
                        cout << "Health: " << myCharacter->getHealth() << endl;
                        cout << "_____________________________________" << endl;
                        cout << "_____________________________________" << endl;
                        cout << "Attack 1 :"<< myCharacter->getFirstAttack() << endl;
                        cout << "Attack 2 :"<< myCharacter->getSecondAttack() << endl;
                        cout << "Attack 3 :"<< myCharacter->getThirdAttack() << endl;
                        cout << "---------------------------------------" << endl;
                        cout << "----Inventory Bag----" << endl;
                        cout <<"Potion, health increase 4:"<< myInventory->getPotion() << endl;
                        cout <<"Ether, Magic increase 5:" << myInventory->getEther() << endl;
                        cout << "Senzu bean, stamina up 6 :" << myInventory->getSenzuBean() << endl;
                        cout << "_______________________________________" << endl;
                        cout << "_______________________________________" << endl << endl;
            
                        cout << "Shapeshifer" << endl;
                        cout << "Health :"<< myEnemy->getHealth() << endl;
                        cout << "Magic :" << myEnemy->getMagic() << endl << endl;
                        int choice;
                        cin >> choice;
         
                    switch (choice)
                    {
                        //For Warrior's Attack
                        case 1:    
                            if(myCharacter->getHealth() > 10)
                            {
                            myEnemy->DeductHealth(20);
                            myCharacter->SetStamina(myCharacter->getStamina()-10);
                            cout << "You attacked the enemy" << endl << endl;
                            }
                            else
                            {
                                cout << "Not enough stamina!" << endl;
                            }
                        break;
    
    
                        //For Warrior's SecondAttack
                        case 2:
                            if(myCharacter->getHealth() > 25)
                            {
                            myEnemy->DeductHealth(30);
                            myCharacter->SetStamina(myCharacter->getStamina()-25);
                            cout << " You did a devistating magic attack." << endl << endl;
                            }
                            else
                            {
                                cout << name << ", not enough stamina!" << endl;
                            }
                        break;
    
    
                        //Warrior's 3rd Attack
                        case 3:
                            if(myCharacter->getMagic() > 50)
                            {
                            myEnemy->DeductHealth(110);
                            myCharacter->SetMagic(myCharacter->getMagic()-70);
                            cout << "You attacked the enemy, it looks critical!" << endl << endl;
                            }
                            else
                            {
                                cout << name << ",not enough magic! Quick think fast!" << endl;
                            }
                        break;
    
    
                        case 4:
                            if(myInventory->getPotion() > 0)
                            {
                            myCharacter->SetHealth(myCharacter->getHealth()+200);
                            myInventory->SetRestore(myInventory->getPotion() - 1);
                            cout << " You restored and increased your health." << endl << endl;
                            }
                            else
                            {
                                cout << "You have no potions!" << endl;
                            }
                        break;    
    
    
                        case 5:
                            if(myInventory->getEther() > 0)
                            {
                            myCharacter->SetMagic(+200);
                            myInventory->SetmagicUp(myInventory->getEther() - 1 );
                            cout << " You restored your magic." << endl << endl;
                            }
                            else
                            {
                                cout << "You don't have an Ether!" << endl;
                            }
                        break;
    
    
                        case 6:
                            if(myInventory->getSenzuBean() > 0)
                            {
                            myCharacter->SetStamina(+200);
                            myInventory->SetStaminaUp(myInventory->getSenzuBean() -1);
                            cout << "You restored and increased your stamina" << endl << endl;
                            }
                            else
                            {
                                cout << "You don't have a Senzu Bean! You can't recover stamina!" << endl;
                            }
    
    
                        break;
                    }
    
    
                        cout << "Shapeshifer" << endl;
                        cout << "Health :"<< myEnemy->getHealth() << endl;
                        cout << "Magic :" << myEnemy->getMagic() << endl << endl;
                        cout << "_______________________________________________" << endl;
            
            
                        int max, random_number;
                        max = 3;
    
    
                        srand(time(0));
                        random_number = (rand() % max) + 1;
    
    
                        switch(random_number)
                        {
                            case 1:    
                            myCharacter->DeductHealth(20);
                            cout << "The enemy fights back!" << endl;
                            cout << "___________________________________________________" << endl << endl;
                
                        break;
    
    
                        case 2:
                            myCharacter->SetMagic(myCharacter->getMagic()-25);
                            cout << "It's attacking your magic supply, quick do something!" << endl;
                            cout << "_____________________________________________________" << endl;
                        break;
    
    
                        case 3:
                            myCharacter->DeductHealth(50);
                            myCharacter->SetMagic(myCharacter->getMagic()-50);
                            cout << "It unleashed its ultimate attack, you must fight back!" << endl;
                            cout << "______________________________________________________" << endl << endl;
                        break;
    
    
                        };
                        
                            
                 
                //ThirdPhase();
                } while( myCharacter->getHealth() > 0 || myEnemy->getHealth() > 0 );
                    if(myEnemy->getHealth() < 0)
                            {
                    //            return ThirdPhase();
                            }
                    if(myCharacter->getHealth()<0)
                    {
                        return deathScreen();
                    }
                
                }
            else if(Path2 == 2)
                {
                cout << "----------------------Chapter two: Blackest Night----------------------" << endl;
                cout << "You approach the woman, however, as you begin to close in, a mongolian worm" << endl;
                cout << "bursts from the ground and devours her whole" << endl;
                
                //return ThirdPhase();
            }
            else
                {
                cout << "You are doing it wrong, warrior! Press either '1','2' or '3', nothing else!" << endl;
                
        cout << "\n----------------------Press any key to continue----------------------" << endl;
        //_getch();
            }
                
                return 0;
                };
    Last edited by PurpleChershire; 01-08-2014 at 05:51 AM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    int SecondPhase(blankCharacter, blankEnemy,Inventory, string name, std::unique_ptr<blankCharacter> myCharacter,std::unique_ptr<blankEnemy> myEnemy, std::unique_ptr<Inventory> myInventory,std::unique_ptr<blankEnemy>myBoss)
    I don't even see how that's going to compile with those three extra things at the front. But in any event, this function is not going to help you if you call "secondPhase()", because you don't have a blankCharacter, a blankEnemy, an Inventory, a name, a myCharacter, a myEnemy, a myInventory, or a myBoss listed there. You either need to pass those into your secondPhase function call (by typing a bunch of stuff inside the parentheses), or take these things out of the parameter list.

  5. #5
    Registered User
    Join Date
    Jan 2014
    Posts
    4
    They're all defined in my GameStart() function, i'm passing though the parameters inorder to use the selected character in the Second part of the story for a battle. That part works. I just can't seem to link together the two .cpp files. Without the unresolved externals error.

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    1,273
    in C++, the function names are "mangled" by adding additional characters to the name in order to deal with the number of parameters and their type, so the defined SecondPhase() ends up being a different function than the called SecondPhase(), which is causing the unresolved external reference error.

  7. #7
    Registered User
    Join Date
    Jan 2014
    Posts
    4
    Thank you! How would i resolve it?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by PurpleChershire View Post
    They're all defined in my GameStart() function, i'm passing though the parameters inorder to use the selected character in the Second part of the story for a battle. That part works. I just can't seem to link together the two .cpp files. Without the unresolved externals error.
    Anything defined in GameStart is only relevant in GameStart, and that's not where we are, so if you plan to use those things you need to plan again.

    If your function is supposed to take half a dozen arguments, then you need to give it half a dozen arguments:
    Code:
    SecondPhase(this, that, the_other, jim_bob, stuff, etc);

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,536
    Considering the amount of arguments to your function, I would consider using a struct or class...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unresolved externals??
    By pokiepo in forum C Programming
    Replies: 6
    Last Post: 07-02-2008, 11:38 AM
  2. unresolved externals
    By drater in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 08:49 AM
  3. unresolved externals?!?!
    By rainman39393 in forum C++ Programming
    Replies: 5
    Last Post: 02-28-2008, 05:27 AM
  4. unresolved externals
    By nocturna_gr in forum Windows Programming
    Replies: 4
    Last Post: 12-28-2007, 08:48 AM
  5. Unresolved Externals
    By nickname_changed in forum C++ Programming
    Replies: 10
    Last Post: 08-31-2003, 06:13 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21