Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Linker error. C++

Options
  • 13-04-2005 6:26pm
    #1
    Closed Accounts Posts: 17,163 ✭✭✭✭


    I'm writing a particularly large project and decided to give linking a go. This being my first time using linking I've run into a brick wall with this error

    [Linker error] undefined reference to `WinMain@16'

    What does it mean and how do I fix it.

    The interface file
    [PHP]using namespace std;

    #ifndef NODE_H
    #define NODE_H

    class Node{
    public:
    Node();
    void data_asign(int);
    int data_get();
    void value_asign(int);
    int value_get();
    void next_asign(Node*);
    Node* next_get();
    Node* link[4]; //make this private

    private:
    int data;
    int value;
    Node* next;

    };


    #endif
    [/PHP]


    The implication file
    [PHP]#include<iostream>
    #include "node.h"
    using namespace std;

    Node::Node(){
    next = 0;
    data = 0;
    for(int i = 0; i <4;i++){
    link = NULL;
    }
    }

    void Node::data_asign(int x){
    data = x;

    }


    int Node::data_get(){

    return data;
    }

    int Node::value_get(){

    return value;
    }

    void Node::value_asign(int x){
    value = x;

    }

    void Node::next_asign(Node* x){
    next = x;
    }

    Node* Node::next_get(){

    return next;
    } [/PHP]


    I'm also linking several other files and I get the same error with all of them


Comments

  • Closed Accounts Posts: 17,163 ✭✭✭✭Boston


    Apparently i have to add int main(){return 0;} to all my implimentation files, why?

    Also the file that links to the class says linker error underfined reference, then lists every fuction in the .h file. What am I doing wrong

    thanks


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Boston wrote:
    Apparently i have to add int main(){return 0;} to all my implimentation files, why?

    Also the file that links to the class says linker error underfined reference, then lists every fuction in the .h file. What am I doing wrong

    thanks

    I'm assuming that you were compiling that class for use in a larger program, rather than as a standalone program? A main function is only required (or desirable) in a standalone program.

    What compiler are you using, and with what commands? With GCC, to compile a module do:
    g++ -c whatever.cpp

    and to link it do:
    g++ -o finalprogram whatever.o otherthing.o...

    Note that since you're on Windows, the '.o' will be replaced with something else, I can't remember what. Only one of the modules being linked should contain a main.


  • Closed Accounts Posts: 17,163 ✭✭✭✭Boston


    I was using Dev - cpp. The problem didn't go away, it seems permenent. Not know the finer points of linking,(hasn't been covered in my course) I wasn't including the right header files with the right others files that required them. Once I sorted that out, everything was ok. But thanks for your help.


Advertisement