Undefined symbol main Error

16 Oct 2010

I'm writing a library and fought my way through learning how and a bunch of bugs to get 1 more compile error. I could only find 1 other example in the forums and the solution was to put main() in the code. Since I'm writing a library I figured I wouldn't want to do this. There error is:

" Undefined symbol main (referred from rtentry2.o). (EL6218E)" in file "/"
Here is the code:

#ifndef MBED_DCSS500_H
#define MBED_DCSS500_H

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"

namespace mbed {

class TWITTER {
public:
    TWITTER(const char username[], const char password[]);
    int tweet(char);
    char latestMention(void);
protected:
    char msg, r;
    EthernetNetIf _eth;
    HTTPClient _twitter;
};
}

#endif
#include "twitter.h"
#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPClient.h"

using namespace mbed;

TWITTER::TWITTER(const char username[], const char password[])
        : _eth(), _twitter() {_eth.setup(); _twitter.basicAuth(username, password);}

int TWITTER::tweet(char msg) {
    HTTPMap status;
    status["status"] = msg;
    HTTPResult r = _twitter.post("http://api.supertweet.net/1/statuses/update.xml", status, NULL);
    if ( r == HTTP_OK ) {
        return 1;
    } else {
        return 0;
    }
}

char TWITTER::latestMention() {
    //TODO Later
    return 0;
}

16 Oct 2010

Hi Mark,

If your compiling something, you'll need a main(). But as you say, you don't want it in the library.

If you take a look at Writing a Library, you'll see the end library example looks like this:

i.e. the library (Flasher) is within a program, and main.cpp and the mbed library are not part of the library. That way you can easily build/test the library, but you only publish the library itself.

Hope that makes sense.

Simon

17 Oct 2010

Thanks a lot simon! Still getting the hang of all of this and wasn't following the tutorial close enough.

 

-Mark