Hello All,

I have writtern a c++ code to implement Koch Snowflake pattern using recursion. The code written compiled well but did not run saying linking error for some variables as shown below:

============================
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _moveto referenced in function "public: __thiscall RecursiveCurve::RecursiveCurve(void)" (??0RecursiveCurve@@QAE@XZ)
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _setbkcolor referenced in function "public: __thiscall RecursiveCurve::RecursiveCurve(void)" (??0RecursiveCurve@@QAE@XZ)
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _setcolor referenced in function "public: __thiscall RecursiveCurve::RecursiveCurve(void)" (??0RecursiveCurve@@QAE@XZ)
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _linerel referenced in function "private: void __thiscall RecursiveCurve::drawFourLines(double,int)" (?drawFourLines@RecursiveCurve@@AAEXNH@Z)
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _grapherrormsg referenced in function _main
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _graphresult referenced in function _main
1>kosh_snowflake.obj : error LNK2019: unresolved external symbol _initgraph referenced in function _main

1>c:\users\skumar483\documents\visual studio 2010\Projects\Koch_snowflake\Debug\Koch_snowflake.exe : fatal error LNK1120: 7 unresolved externals

I am not able to get rid of these errors. Any immediate help would be appreciated.

Below is my code attached:

#define _USE_MATH_DEFINES
#include<iostream>
#include<graphics.h>
//#include<math.h>
#include<winbgi.h>
#include<cmath>

using namespace std;

class RecursiveCurve{
public:
    RecursiveCurve();
    void readInitValues();
    void snowflake();
private:
    double side, angle;
    int level;
    void right(double x){
        angle+= x;
    }
    void left(double x){
        angle -= x;
    }
    void drawFourLines(double side, int level);
};

RecursiveCurve::RecursiveCurve(){
    setcolor(WHITE);
    setbkcolor(BLUE);
    moveto(200,150);
    angle = 0.0;
    cout<<"Enter Side and Level: ";
    cin>>side>>level;
}

void RecursiveCurve::drawFourLines(double side, int level){
    if(level == 0)
        linerel((cos(angle*M_PI/180)*side),sin(angle*M_PI/180));
    else{
        drawFourLines(side/3.0,level-1);
        left(60);
        drawFourLines(side/3.0,level-1);
        right(120);
        drawFourLines(side/3.0,level-1);
        left(60);
        drawFourLines(side/3.0,level-1);
    }
}

void RecursiveCurve::snowflake(){
    for (int i=1;i<=3;i++){
        drawFourLines(side,level);
        right(120);
    }
}

void main(){
    int grBoard = DETECT, grMode, grResult, grError;
    initgraph(&grBoard,&grMode, "C:\\Users\\skumar483\\Documents\\Visual Studio 2010\\Projects\\Koch_snowflake\\Koch_snowflake\\bgi");
    grError = graphresult();
    if (grError != grOk){
        cerr<<"error: "<<grapherrormsg(grError)<<endl;
    }
    RecursiveCurve curve;
    curve.snowflake();
}

You need to link against the library that contains the function moveto, setbkcolor, setcolor, linerel, grapherrormsg, graphresult, initgraph.

Thanks Moschops for your suggestion. Need a bit more help here. Can you please help me finding the libraries required to include these functions?

As I recall, these functions were part of a library released by Borland about 20 years ago with their compiler. If you want to use them, you'll either have to do your coding using Borland's Turbo C++ from twenty years ago, or use one of the modern remakes of that library.

The wiki page for it lists a few modern remakes of that library at the bottom: http://en.wikipedia.org/wiki/Borland_Graphics_Interface

Thanks for the help. I am working on it and will share the result..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.