Solved

fatal error LNK1120: 1 unresolved externals

Posted on 2003-10-23
11
877 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Industry Leaders: 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!

Question has a verified solution.

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

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

626 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