Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

fatal error LNK1120: 1 unresolved externals

Posted on 2003-10-23
11
Medium Priority
?
892 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.
Suggested Courses

926 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