Solved

fatal error LNK1120: 1 unresolved externals

Posted on 2003-10-23
11
859 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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
 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 109
Unresolved External Symbols 3 81
Least Squares Curve Fitting 4 77
Add values of each row in an array 3 57
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

770 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