Solved

fatal error LNK1120: 1 unresolved externals

Posted on 2003-10-23
11
854 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compile GLUT with Visual Studio 2015 1 108
Arduino EDI - Programming language 3 80
Least Squares Curve Fitting 4 60
Beginner to Unreal Engine 4 5 57
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

919 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

19 Experts available now in Live!

Get 1:1 Help Now