Menu

Linker error]undefined reference@'winMain@16'

Roy
2005-07-21
2012-09-26
  • Roy

    Roy - 2005-07-21

    Hi everyone?
    I have this persistent error that appeared after I had worked on all 45errors in my code. It is the [Linked error] undefined reference'winMain@16'.
    I have read all your comments about this error, plus many online and text book statements about the error and followed them in my Dev C++ compiler but i am achieving zero results.
    I surely need your help in this problem.
    For reference, let me attache below the codes I am talking about. Its supposed to be a reference code in a namespace called Matrix1.
    The main is in the Application file and is supposed to use the header file Matrix1.h.
    Actually, all objects created in the main class, of the Matrix1::MatrixClass, cannot be understood by the compiler since MatrixClass is not properly compiled and yet the compiler cannot compile MatrixClass due to the above mentioned linker error.
    Please help.

    The two codes are as follows:

    //first file: Matrix1.cpp
    // 20/07/05 21:52

    include <string>

    include <math.h>

    //using namespace std;

    namespace Matrix1
    {
    class MatrixClass
    {

    class here.
    private:
    int maxPrice;
    int expiry_time;
    float r;
    int size;
    float k; //strike price
    int spaceincrements;
    int timeincrements;
    char typedoption;

       public:
       //constructor for building a matrix of a specific size
               MatrixClass(int maxS, int expiryT, float
    

    intRate, float strikePrice, char opType)
    {
    float deltaT = 0.5;
    float deltaS = 0.5;
    maxPrice = maxS;
    int spaceincrements = 10; //
    (max_price / deltaS);
    expiry_time = expiryT;
    r = intRate;
    int timeincrements =
    10; //expiry_time / deltaT;
    k = strikePrice;

                       typedoption = opType;
    
                       float buffer[spaceincrements]
    

    [timeincrements]; //the array bound cannot be a variable
    //Refer to B.Stroustrup,chapter 5.2.
    Else you
    //use vectors.
    //this is a store for the matrix values

           //Instantiating the array - buffer.
           for (int i = 0; i &lt; spaceincrements; i++)
           {
               for (int j = 0; j &lt; timeincrements; j++)
               {
                   buffer[i][j] = 0;
               }
           }
           //setting final conditions of the buffer array.
            float delta_T = expiry_time / timeincrements;
    
            switch(typedoption)
            {
                 case 'c':
                      for (int i = 0; i &lt; spaceincrements; i++)
                      {
                                for (int j = 0; j &lt; timeincrements; j++)
                                {
                                    if (((i * spaceincrements * 1.0) - k) &gt;
    

    0)
    {
    buffer[i][j] = (i * 1.0 *
    spaceincrements);
    }
    else
    {
    buffer[i][j] = 0;
    }
    }
    }
    break;
    case 'p':
    for (int i = 0; i < timeincrements; i++)
    {
    for (int j = 0; j < timeincrements; j++)
    {
    while (j * delta_T == (1.0 *
    expiry_time))
    {
    if ((i * 1.0 * spaceincrements) - k >
    0)
    {
    buffer[i][j] = 0;
    }
    else
    {
    buffer[i][j] = (i * 1.0 *
    spaceincrements) - k;
    }
    }
    }
    }
    break;
    }

                       //setting boundary condition
    

    values, but depending on option type.
    switch (typedoption)
    {
    case 'c':
    for (int i =0; i < spaceincrements; i++)
    {
    for (int j = 0; j < timeincrements ; j++)
    {
    buffer[0][j] = 0;
    buffer[maxPrice][j] =
    maxPrice;
    }
    };
    break;
    case 'p':
    for (int i = 0; i < spaceincrements; i++)
    {
    for (int j = 0; j < timeincrements ; j++)
    {
    buffer[0][j] = (k * exp(-r(expiry_time-
    (j
    timeincrements))));
    buffer[maxPrice][j] = 0;
    }
    };
    break;
    }

               };
    
       };
    

    }

    //The second file: Application.cpp
    // This is the main project file for DeV-C++ application project
    //generated using a Wizard

    include "Matrix1.h"

    include <iostream>

    include <tchar.h>

    include <stdio.h>

    include <stdlib.h>

    include <string>

    //#include <mscorlib.dll>

    using namespace std;

    int main()
    {
    // TODO: Please replace the sample code below with your
    own.
    cout<<("Hello, welcome to this finite difference option
    pricing scheme for European Options.");

       int maxprice = 0;
       int expirytime = 0;
       float strikeprice = 0;
       char optiontype = '0';
       float interest_rate = 0;
       float stddev = 0;
       float constvarA = 0;
       float constvarB = 0;
       float constvarC = 0;
       float rstheta = 0;
       float siglambsquared = 0;
       char c = 'c';
       char p = 'p';
    
       //setting the maximum stock price.
       cout&lt;&lt;&quot;Set your max price:&quot;;
       cin&gt;&gt;maxprice;
       //Setting the expiry time.
    

    cout<<"Thank you, now set your expiry time";
    cin>>expirytime;
    //Setting the strike price.
    cout<<"Thank you, now set your strike price";
    cin>>strikeprice;
    //setting the riskless interest rate.
    cout<<"Thank you, now set your current interest
    rate";
    cin>>interest_rate;
    //setting the standard deviation.
    cout<<"Thank you, now set the stock volatility";
    cin>>stddev;
    //determining the type of European option under
    consideration.
    cout<<"Thank you, now type either " << c << " for
    call option type or " << p <<" for put option type";
    cin>>optiontype;
    while (optiontype != p || optiontype != c)
    {
    cout << "Sorry, but you have made an unclear input:"
    << endl;
    cout << "Please type either " << c << "or " << p <<" for
    your option type";
    }
    //create the matrices
    Matrix1::MatrixClass Matrix1st = new
    Matrix1::MatrixClass(maxprice, expirytime, interest_rate,
    strikeprice, optiontype);

       for (int j = expirytime - MatrixClass::deltaT; j = 0; j--
    

    )
    {
    for (int i = 1; i = (maxprice - MatrixClass::deltaS); i++)
    {
    //computing the Black Scholes coefficients varA,
    varB and varC:
    // This is to be done for every point of the grid for
    which the
    // option value is to be computed.

           // computing (int. rate * stock price at point i *
    

    theta)
    float rstheta = (interest_rate * ( i *
    MatrixClass::deltaS ) * MatrixClass::deltaT /
    MatrixClass::deltaS );
    //computing a variable factor - square of
    (sigma * lambda).
    float siglambsquared = ( stddev * stddev * ( i *
    MatrixClass::deltaS ) * ( i * MatrixClass::deltaS ) *
    MatrixClass::deltaT / (MatrixClass::deltaS *
    MatrixClass::deltaS));

           constvarA = ( siglambsquared /2 );
           constvarB = ( 1 + rstheta - siglambsquared);
           constvarC = ( (siglambsquared / 2 ) - rstheta );
    
           Matrix1st[i][j] = Matrix1st[i+1][j+1]*constvarA +
    

    Matrix1st[i][j+1]constvarB + Matrix1st[i-1][j-1]constvarC;
    }
    }
    for (int j = 0; j < expirytime; j++)
    {
    while (j = 0)
    {
    for (int i = 0; i < maxprice; i++)
    {
    cout<< "For stock price ="
    (i*MatrixClass::deltaS) ", the fair price is:" Matrix1st[i][j];
    <<endl;
    }
    }
    }

       system(&quot;PAUSE&quot;);
       return 0;
    

    }

     
    • Roy

      Roy - 2005-07-23

      Hi?
      I have points mentioned earlier as follows:
      1. I have uninstalled version 4.9.9.1 completely (with the pc advising me to also uninstall the C::...\Dev C++ directory if I dont have any personal data in it. I removed the trial files I had saved in a subdirectory and deleted the directory). After I installed Dev C++ - version 4.9.9.2 with the mgw compiler, from the net. This time I installed it directly under dir C:\, as in C:\DevC++.
      2. I have opened a new project as you mentioned and inserted the code files that I had done earlier, into it like main.cpp (which initially was Application.c), Matrix1.cpp and Matrix1.h
      3. I have also followed the advise mentioned under NO.3 of "what does a compile log tell us?". Since I had created a project with all files in it, I used the second option (for projects).
      4. I then decided to compile and got the following compile log:
      Compiler: Default compiler
      Building Makefile: "C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\Computer Implementation of finite difference option pricing schemes\Martins2\Makefile.win"
      Executing make...
      make.exe -f "C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\Computer Implementation of finite difference option pricing schemes\Martins2\Makefile.win" all
      g++.exe -D__DEBUG__ -c Application/main.cpp -o Application/main.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include" -fexpensive-optimizations -pg -g3
      Application/main.cpp: In function int main()': Application/main.cpp:58: error:Matrix1' has not been declared
      Application/main.cpp:58: error: MatrixClass' undeclared (first use this function) Application/main.cpp:58: error: (Each undeclared identifier is reported only once for each function it appears in.) Application/main.cpp:58: error: expected;' before "Matrix1st"
      Application/main.cpp:60: error: MatrixClass' has not been declared Application/main.cpp:60: error:deltaT' undeclared (first use this function)
      Application/main.cpp:62: error: MatrixClass' has not been declared Application/main.cpp:62: error:deltaS' undeclared (first use this function)
      Application/main.cpp:69: error: MatrixClass' has not been declared Application/main.cpp:69: error:MatrixClass' has not been declared
      Application/main.cpp:69: error: MatrixClass' has not been declared Application/main.cpp:71: error:MatrixClass' has not been declared
      Application/main.cpp:71: error: MatrixClass' has not been declared Application/main.cpp:71: error:MatrixClass' has not been declared
      Application/main.cpp:71: error: MatrixClass' has not been declared Application/main.cpp:71: error:MatrixClass' has not been declared
      Application/main.cpp:77: error: Matrix1st' undeclared (first use this function) Application/main.cpp:86: error:MatrixClass' has not been declared
      Application/main.cpp:86: error: &quot;For stock price =&quot;' cannot be used as a function Application/main.cpp:86: error: expected;' before string constant
      Application/main.cpp:86: error: expected primary-expression before '<<' token
      make.exe: *** [Application/main.o] Error 1

      Questions:
      1. Why is it that the compiler still searches for files in the long thread as in: make.exe -f "C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\Computer Implementation of finite difference option pricing schemes\Martins2\Makefile.win"?
      2. Many of the errors that you spoke of yesterday (the ones you said I could sort out) are as a result of the compiler not recognising the other source code through the compiler because they are used by the object of its class in the main. So under a project, how do I compile one source file at a time, because I think if I dont compile that other Matrix1.cpp, objects of its class in the main will remain undefined. I hope I am right with this.

      Its a husstle for me now but I think I am learning Dev C++ pretty fast. Thank you.
      Roy.

       
    • Wayne Keen

      Wayne Keen - 2005-07-23

      "I have uninstalled version 4.9.9.1 completely (with the pc advising me to also uninstall the C::...\Dev C++ directory if I dont have any personal data in it. I removed the trial files I had saved in a subdirectory and deleted the directory). After I installed Dev C++ - version 4.9.9.2 with the mgw compiler, from the net. This time I installed it directly under dir C:\, as in C:\DevC++. "

      Sounds like you didn't follow the directions for a clean uninstall that are in the FAQ thread. Deleting the directory is not enough.

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2005-07-21

      Could you please post the other two elements of the "Basic 3" - see the FAQ thread in this forum for a description if you need it...

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2005-07-21

      You also failed to include your header file

      Matrix1.h

      in your post.

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2005-07-21

      And what exactly is this line of code supposed to do?

      class here.

      It looks like a comment that has been mangled.

      Wayne

       
    • Roy

      Roy - 2005-07-21

      Hi Wayne,
      Very sorry, I hadn't read those details about what needs to be included when posting a querry. However, here they are:
      1. The OS is windows XP

      1. The Version of Dev C++ that I am using is: 4.9.9.1

      2. The header file is as follows:
        // Matrix1.h

      include <iostream>

      ifndef MATRIX_1_H;

      define MATRIX_1_H;

      namespace Matrix1
      {
      MatrixClass(int maxS, int expiryT, float intRate, float strikePrice, char opType);
      }

      endif

      //To be honest, I have not met a book that has properly explained the creation (not the use) of non-standard header files.

      1. I bet you may also need the compile statement. If so, it is:
        [Linker error] undefined reference to `WinMain@16'
       
    • Roy

      Roy - 2005-07-21

      Hi Wayne,
      Very sorry, I hadn't read those details about what needs to be included when posting a querry. However, here they are:
      1. The OS is windows XP

      1. The Version of Dev C++ that I am using is: 4.9.9.1

      2. The header file is as follows:
        // Matrix1.h

      include <iostream>

      ifndef MATRIX_1_H;

      define MATRIX_1_H;

      namespace Matrix1
      {
      MatrixClass(int maxS, int expiryT, float intRate, float strikePrice, char opType);
      }

      endif

      //To be honest, I have not met a book that has properly explained the creation (not the use) of non-standard header files.

      1. I bet you may also need the compile statement. If so, it is:
        [Linker error] undefined reference to `WinMain@16'
       
    • Wayne Keen

      Wayne Keen - 2005-07-21

      Arghgh, reading is not your strong point eh?

      I did NOT ask for a compile "statement", I asked for the compile LOG. Please read the directions again.

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2005-07-21

      PLEASE do not start a bunch of new threads about the same question. It is really quite rude.

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2005-07-21

      Repost from other unneccesarily started thread:

      Hi?
      Sorry I meant the compile log and not the compile statement for no.4.
      The compile log is:

      Compiler: New compiler
      Executing g++.exe...
      g++.exe "C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\Computer Implementation of finite difference option pricing schemes\Martins2\Application\Matrix1.cpp" -o "C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\Computer Implementation of finite difference option pricing schemes\Martins2\Application\Matrix1.exe" -fexpensive-optimizations -pg -g3 -I"C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\Computer Implementation of finite difference option pricing schemes\Martins2\Application" -L"C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\C++ info\Dev-Cpp\lib" -lgmon -pg -g3
      C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\C++ info\Dev-Cpp\lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'

      Execution terminated

       
      • Wayne Keen

        Wayne Keen - 2005-07-21

        Now, you went crazy with putting spaces in directory names. This ia a VERY bad idea. Spaces in paths are not well parsed. Not to mention long path names will get you into trouble with command line lenght issues.

        Now, you have Dev installed in:

        C:\Documents and Settings\Martin Roy Lukwago\My Documents\study information\MSC MathFin at Hull Univ\C++ info\Dev-Cpp

        This is an even worse idea. Take a piece of advice, unless you really understand a tool, NEVER override its preferred installation path. Personally, I would rip it out of there and install it where it goes, i.e. c:\dev-cpp

        Now, the code you posted includes three files, NONE of which are named main.c. Yet your log refers to it.

        Wayne

         
        • Wayne Keen

          Wayne Keen - 2005-07-21

          I created a New:Empty Project, put your code in, and compiled it.

          I got a lot of errors, but they appear to be legitimate coding errors on your part - undeclated variables (note C++ is case senstive, so maxprice is not the same as maxPrice), missing comments etc.

          Wayne

           
          • Wayne Keen

            Wayne Keen - 2005-07-21

            Yep, there are a large numbers of errors in your code, but you should be able to fix them.

            Wayne

             
            • Wayne Keen

              Wayne Keen - 2005-07-21

              Note that since this is now a windows project, you sould not use a windows project. I used:

              File:New:Project:Empty Project

              You have a number of compile options set as well, like -pgmon, did you do that on purpose?

              Wayne

               
    • Roy

      Roy - 2005-07-22

      Sorry Wayne,
      I know i have been a pain to you insome way but please bare with me on some of these issues. I didnt know many of the stuff you mentioned until you detailed them.
      Now I didnt understand the comment:
      Note that since this is now a windows project, you sould not use a windows project. I used:

      File:New:Project:Empty Project

      You have a number of compile options set as well, like -pgmon, did you do that on purpose?

      Could you please elaborate?
      IN addition, please explain to me how I can access the New:Empty project so that I can use it. This site is not yet stright forward to me.
      Otherwise, I seriously appreciate every comment you give.

       
    • Wayne Keen

      Wayne Keen - 2005-07-22

      Your log shows these compile options are set:

      -lgmon -pg -g3

      How you set them, I have not a clue, I have not been there with you.

      Start Dev, go up to the menu item File - click it. Go down to the item New: Click it. Go to the menu item Project. This will open a new window with a bunch of icons, one of which is Empty Project. Click it. (Or double click). It will ask you for a name for your project. Name it, and you are now working in a new project. You can add file to your project by going to Project:Add to Project, or create stuff new for it by going to New:Source File.

      You really need to bump around in the menus and see what's there.

      Note that, as I tolld you, there are a lot of errors in your code, misnamed and undeclared variables etc. You will need to fix those.

      Wayne

       
    • Roy

      Roy - 2005-07-22

      Thanks, hadnt imagined it was that simple.
      I will try it all out asap and reinstall the software.
      Once again, thanks Wayne,
      Roy.

       
      • Wayne Keen

        Wayne Keen - 2005-07-23

        Don't be a scared-to-try-stuff old fart like me. Play with it. Have fun. "I wonder what that does?" is a good attitude to have.

        Wayne

         
    • Roy

      Roy - 2005-08-02

      Hi?
      All errors cleared as of now and the code compiles and runs properly.
      I appreciate all your tireless assistance and patience, Wayne.
      I just have one more question.
      I have tried to read topics on how I can out put my data and retrieve it from MS-Excel but its confusing me. Any ideas on this?
      cheers,
      Martin.

       
    • Wayne Keen

      Wayne Keen - 2005-08-04

      I will generally write my data out with commas between the elements, i.e.

      2,3,4,5
      6,7,8,9
      1,1,1,1

      and call the file something like

      test.csv

      which Excel will open properly.

      Wayne

       

Log in to post a comment.