Like Tree1Likes
  • 1 Post By jimblumberg

Error LNK2019

This is a discussion on Error LNK2019 within the C++ Programming forums, part of the General Programming Boards category; This is a code I've written for Random Directed Acyclic Graph Generation: Code: #include <stdio.h> #include <stdlib.h> #include <iostream> #include ...

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    21

    Question Error LNK2019

    This is a code I've written for Random Directed Acyclic Graph Generation:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <time.h>
    
    
    using namespace std;
    
    
    int random_or_user_defined( void );
    int random_weight_generation( int, int );
    int randvert ( void );
    int fixedvert ( void );
    int random_edge_generation( int );
    int connflagcheck( int, int, int );
    int vnum, **edge, *connflag, **weight;
    
    
    int main( void )
    {
        random_or_user_defined();
        
        srand (time(NULL));
    
    
        random_edge_generation( vnum );
    
    
        random_weight_generation( vnum, **edge );
    
    
        return 0;
    
    
    }
    
    
    int random_or_user_defined( void )
    {
        char opt;
        
        cout<<"Do you want to manually enter the number of vertices?";
        cout<<endl<<"Press Y for yes, N for no."<<endl;
        cin>>opt;
    
    
        while (( opt != 'Y' ) && ( opt != 'y' ) && ( opt != 'N' ) && ( opt != 'n' ))
        {
            cout<<"Wrong input! Try again: ";
            cin>>opt;
        }
    
    
        if (( opt == 'Y' ) || ( opt == 'y'))
        {
            randvert( );
        }
        else if (( opt == 'N' ) || ( opt == 'n' ))
        {
            fixedvert( );
        }    
        
        return vnum;
    
    
    }
    
    
    
    
    int randvert ( void )
    {
        int vnum_max;
    
    
        cout<<"Enter the number of maximum vertices: ";
        cin>>vnum_max;
        
        while (vnum_max < 2)
        {    
            cout<<"A graph with one vertex is inadmissible."<<endl<<"Enter a number greater than 1. ";
            cin>>vnum_max;
        }
    
    
        srand (time(NULL));
        vnum = (rand()%vnum_max) + 1;
        
        cout<<"Number of vertices chosen: "<<vnum;
        
        return vnum;
    }
    
    
    int fixedvert ( void )
    {
        cout<<"Enter the number of vertices: ";
        cin>>vnum;
        
        return vnum;
    }
    
    
    int random_edge_generation( int vnum )
    {
        int i, j, k, **edge;
    
    
        edge = (int **) malloc ( vnum * sizeof (int* ) );
            
        for(i = 0; i < vnum; i++)
        {
            edge[i] = (int *) malloc ( vnum * sizeof (int) );        
        }
    
    
        connflag = (int *) malloc ( vnum * sizeof (int) );
        
        for ( i = 0; i < vnum; i++ )
        {
            connflag[i] = 0;
            
            for ( j = 0; j < vnum; j++ )
    
    
                edge[i][j] = 0;
        }
    
    
        
        for ( i = 0; i < vnum; i++ )
        {
            for ( j = vnum - 1; j > i; j-- )
            {
                if (rand()%2 == 1)
                {
                    edge[i][j] = 1;
                    connflag[j] = 1;
                }
    
    
            }
        }
    
    
        connflagcheck( *connflag, **edge, vnum );
    
    
        return 0;
    }
    
    
    int connflagcheck( int *connflag, int **edge, int vnum )
    {
        int i;
        char opt;
    
    
        cout<<"Will you allow disconnected graph? Press Y or N: ";
        cin>>opt;
        
        while (( opt != 'Y')&&( opt != 'y' )&&( opt != 'N' )&&( opt != 'n' ))
        {
            cout<<"Wrong input! Try again: ";
            cin>>opt;
        }
        if (( opt == 'N' ) || ( opt == 'n' ))
        {
        
            for ( i = 1; i < vnum; i++ )
            {
                if ( connflag[i] == 0 )
                {
                    edge[rand()%i][i] = 1;
                }
            }
        }
    
    
        return **edge;
    }
    
    
    int random_weight_generation( int vnum, int **edge )
    {
        int i, j, wmax;
    
    
        cout<<"Enter the maximum weight: ";
        cin>>wmax;
    
    
        weight = (int **) malloc ( vnum * sizeof (int *) );
            
        for(i = 0; i < vnum; i++)
        {
            weight[i] = (int *) malloc ( vnum * sizeof (int) );        
        }
    
    
        for ( i = 0; i < vnum; i++ )
        {
            for ( j = vnum - 1; j > i; j-- )
            {
                if ( edge[i][j] == 1 )
                {
                    weight[i][j] = (rand() % wmax) + 1;
                }
    
    
            }
        }
    
    
        return **weight;
    }
    However this gives two LNK2019 error codes. I'm new to coding, so can anyone help me out? I'd like to learn what I'm doing wrong.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,753
    Please post the complete error messages, exactly as they appear in your development environment.

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    21
    Thank you for your swift reply. The errors I'm seeing are as follows:

    source1.obj : error LNK2019: unresolved external symbol "int __cdecl random_weight_generation(int,int)" (?random_weight_generation@@YAHHH@Z) referenced in function _main
    source1.obj : error LNK2019: unresolved external symbol "int __cdecl connflagcheck(int,int,int)" (?connflagcheck@@YAHHHH@Z) referenced in function "int __cdecl random_edge_generation(int)" (?random_edge_generation@@YAHH@Z)
    source1.exe : fatal error LNK1120: 2 unresolved externals

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,753
    You declared a function called random_weight_generation() with two int parameters. Where did you implement this function?

    Note you implemented a function with that name but with one int parameter and one int** parameter, this will be treated as a different function by the compiler.

    Your function declaration (prototype), function call, and your function implementation must all agree as to the number and type of parameters.

    Jim
    stahta01 likes this.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    I find it disturbing that you are using malloc in C++, and that you are allocating 2d arrays manually.
    I urge you to google 2d vector c++. Also, switch your C headers to C++ headers: Add c and remove .h, eg time.h --> ctime.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,260
    Mycroft Holmes
    O_o

    Wow. He would be the very best programmer ever.

    Soma

  7. #7
    Registered User
    Join Date
    Apr 2013
    Posts
    21
    Thank you for all your replies. I'll try to rectify my code and run it again. And Elysia, thanks for telling me about two-dimensional vectors. However, I could find a thorough guide for multidimensional vectors, and so I'm in the dark about its implementation. Perhaps, you might share a few link or two about it. That'd really help.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by phantomotap
    Wow. He would be the very best programmer ever.
    Elementary, my dear Thompson.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    Quote Originally Posted by Mycroft Holmes View Post
    Thank you for all your replies. I'll try to rectify my code and run it again. And Elysia, thanks for telling me about two-dimensional vectors. However, I could find a thorough guide for multidimensional vectors, and so I'm in the dark about its implementation. Perhaps, you might share a few link or two about it. That'd really help.
    What is wrong with Initialising 2D vectors - C++ Forum?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Apr 2013
    Posts
    21
    Thank you, Elysia.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 10-27-2012, 02:55 PM
  2. LNK2019 Error with jpeg.lib
    By BobMcGee123 in forum C++ Programming
    Replies: 8
    Last Post: 12-04-2008, 05:53 PM
  3. Help on error LNK2019
    By jlbfunes in forum C++ Programming
    Replies: 5
    Last Post: 08-21-2008, 08:19 AM
  4. I got error LNK2019
    By Daggio in forum Windows Programming
    Replies: 3
    Last Post: 03-14-2008, 02:29 AM
  5. Main.obj : error LNK2019:
    By thestien in forum Game Programming
    Replies: 6
    Last Post: 12-18-2007, 04:39 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21