Solved

fatal error LNK1120: 1 unresolved externals

Posted on 2003-10-23
11
853 Views
Last Modified: 2010-05-18
ok well here is my code and i can't figure out why it keeps throwing this error.

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "activity.h"

#include <conio.h>

using namespace std;

void randNum(int);
void brute(const activity&);
void dynamic(const activity&);
void greedy (const activity&);
void init_mm();
int number_range(int from, int to);
int number_mm(void);
static      int      rgiState[2+55];

int main()
{
      //variables for this program
      activity* problems;
      problems = new activity[90];
      int random;
      long n = 1;            //n from the psuedocode in the book
      
      init_mm(); //seed the number generator
   
    //generate the activity problems to find
      for(int i = 0; i < 90; i++)
      {
            random = number_range(0, 100);
            problems[i].setStartTime((long)random);
            problems[i].setFinishTime((long)random + n);

            if(i % 3 == 0) //increment the n value for every third run of our for loop
            {
                  n++;
            }
      }

      //debug for loop checking for actually creation
      for(int i = 0; i < 90; i++)
      {
            cout << problems[i].getStartTime() << "  " << endl;
      }
      getch();


      //call three algorithms  #2
            //brute force a
            //dynamic b
            //greedy c

      //give output of the time it took to accomplish and an average

      //close up stuff
      delete[] problems;
      return 0;
}

void brute(const activity& probs)
{

}

void dynamic(const activity& probs)
{

}

void greedy(const activity& probs)
{

}

      //random number generator stuff
int number_mm( void )
{
    int *piState;
    int iState1;
    int iState2;
    int iRand;
    piState            = &rgiState[2];
    iState1             = piState[-2];
    iState2             = piState[-1];
    iRand             = ( piState[iState1] + piState[iState2] )
                      & ( ( 1 << 30 ) - 1 );
    piState[iState1]      = iRand;
    if ( ++iState1 == 55 )
          iState1 = 0;
    if ( ++iState2 == 55 )
          iState2 = 0;
    piState[-2]            = iState1;
    piState[-1]            = iState2;
    return iRand >> 6;
}

int number_range( int from, int to )
{
    int power;
    int number;
    if ( ( to = to - from + 1 ) <= 1 )
          return from;
    for ( power = 2; power < to; power <<= 1 )
          ;
    while ( ( number = number_mm( ) & ( power - 1 ) ) >= to )
          ;
    return from + number;
}

void init_mm( )
{
    int *piState;
    int iState;
    piState      = &rgiState[2];
    piState[-2]      = 55 - 55;
    piState[-1]      = 55 - 24;
    piState[0]      = ( (int) time( NULL ) ) & ( ( 1 << 30 ) - 1 );
    piState[1]      = 1;
    for( iState = 2; iState < 55; iState++ )
    {
              piState[iState] = ( piState[iState-1] + piState[iState-2] )
                          & ( ( 1 << 30 ) - 1 );
    }
    return;
}
0
Comment
Question by:cosmowen
11 Comments
 
LVL 2

Expert Comment

by:MeiaDose
ID: 9609433
You should post the description that followed that link error.

The possible cause of error is a variable that is declared in your header file...or you think that is declared but its not...

This kind of errors usually occurs when you have something like this:

"
//file: A.h

class A{
   int i;

public:
        int myMethod();
}

//file A.cpp

int myMethod(){
      return i=0;
}

"

Can you see the error? It should be -> int A::myMethod(){...}
"


What is the name of the unresolved external?

Could you show us the "activity.h" file?
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9609448
That error arises when the linker does not find the implementation for a certain function you have declared.

In other words.......

The function is defined (in the header), but there is no implementation being linked.........


As you haven't posted your code I don't know which function the linker is not finding

but the error arises because of what I have explained you above
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 9609461
Another thing you might want to check is if you have a static data member in your class, you need to instantiate it somewhere outside of your file:

// In activity.h
class activity
{
...
  static int x;
};

// In activity.cpp
#include "activity.h"

int activity::x;

But again, since you haven't posted the activity portion, we don't know.
0
 

Author Comment

by:cosmowen
ID: 9609488
asked for by popular demand here are the rest of the files

//"activity.h"
class activity
{
private:
      long startTime;
      long finishTime;

public:      
      activity(void);
      activity(long, long);
      long getStartTime(void);
      long getFinishTime(void);
      void setStartTime(long);
      void setFinishTime(long);
};

//"activity.cpp"
#include <iostream>
#include <stdlib.h>
#include "activity.h"

long activity::getFinishTime()
{
      return startTime;
}

long activity::getStartTime()
{
      return finishTime;
}

void activity::setStartTime(long val)
{
      startTime = val;
}

void activity::setFinishTime(long val)
{
      finishTime = val;
}
0
 

Author Comment

by:cosmowen
ID: 9609498
ohh also here is the rest of the stuff from the debugger

Prog_2 error LNK2019: unresolved external symbol "public: __thiscall activity::activity(void)" (??0activity@@QAE@XZ) referenced in function _main

Prog_2 fatal error LNK1120: 1 unresolved externals
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:tinchos
ID: 9609545
You have to implement both constructors

activity(void);
activity(long, long);

0
 
LVL 9

Accepted Solution

by:
tinchos earned 50 total points
ID: 9609561
add to activity.cpp


activity::activity()
{
startTime = 0;
finishTime = 0;
}

activity::activity(long start, long end)
{
startTime = start;
finishTime = end;
}
0
 

Author Comment

by:cosmowen
ID: 9609599
thnx tinchos should have caught that one! never forget to define your default constructor or  your most used constructor.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9609634
the problem is that you have declared them

If you haven't declared constructors at all there is no need to implement any of them
0
 

Author Comment

by:cosmowen
ID: 9609682
yeah i know i just overlooked it when i built that class last night at midnight, i like tyo always declare my own default constructor so that i know what will happen and that the my attributes will have a 0/null value. Thanks again for your help.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9609717
Ok

Glad you could solve the problem

C U

Tincho
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now