[Linker error] undefined reference to `CGI::query'

Discussion in 'C++' started by Oliver Bleckmann, Nov 29, 2006.

  1. Damn, what's wrong here?

    CGI cgi;
    map<string,string> cgiParam = cgi.analyseCgiParam();
    cout << cgiParam["plz1"] << endl;
    cout << cgiParam["vorname1"] << endl;

    ///////////////////////

    #include <iostream>
    #include <string>
    #include <list>
    #include <map>
    #include <sstream>
    using namespace std;

    class CGI
    {
    private:
    static std::string query;
    char* input;
    const char **names;
    const char **values;
    int number;
    int val;
    protected:
    public:
    list<string> split(string str, char tr)
    {
    list<string> strElemente; // Ergebnis: Liste von Teilstrings
    string::iterator pos1, // Anfang/Ende von
    pos2; // Teilstrings
    pos1 = str.begin(); // Beginn eines Teilstrings
    pos2 = find (pos1, str.end(), tr); // Ende eines Teilstrings
    while ( pos2 != str.end())
    {
    // Trenner als Ende gefunden
    assert(*pos2==tr);
    string elem; // Teilstring
    copy (pos1, pos2, back_inserter(elem)); // Teilstring kopieren
    strElemente.push_back(elem); // Teilstring speichern
    pos1 = pos2;
    ++pos1; // neuer Anfang hinter altem Ende
    pos2 = find (pos1, str.end(), tr); // neue Suche
    }
    // pos2 zeigt auf das Ende. pos1 zeigt auf den Beginn
    // des letzten Teilstrings vor dem Ende.
    // Letzten Teilstring extrahieren:
    //
    string last;
    copy (pos1, str.end(), back_inserter(last));
    strElemente.push_back(last);
    return strElemente;
    }
    map<string, string> analyseCgiParam()
    {
    std::string meth_s = null_to_empty(std::getenv("REQUEST_METHOD"));
    if (meth_s == "")
    {
    cout << "EMPTY" << endl;
    }
    else if (meth_s == "GET")
    {
    query = null_to_empty(getenv("QUERY_STRING"));
    cout << "GET" << endl;
    cout << query << endl;
    }
    else if (meth_s == "POST")
    {
    int len = atoi(getenv("CONTENT_LENGTH"));
    // MIME getenv("CONTENT_TYPE") application/x-www-form-urlencoded
    //std::string input[len+1];
    input = new char[len+1];
    fread(input, 1, len, stdin);
    input[len] = 0;
    cout << "POST" << endl;
    query = input;
    cout << query << endl;
    delete input;
    //fflush ( stdin );
    }
    else cout << "NONE" << endl;
    list<string> feldListe = split(query, '&'); // in Felder zerlegen
    map<string,string> felder; // Ergebnis
    // Felder in Paare aus Feldnamen und Wert splitten
    for ( list<string>::iterator i = feldListe.begin(); i !=
    feldListe.end(); ++i)
    {
    list<string> feldStr = split(*i, '=');
    pair< string, string > feld;
    feld.first = feldStr.front(); // Feldname
    feldStr.pop_front();
    feld.second = feldStr.front(); // Feldwert
    felder[feld.first] = feld.second; // Paar speichern
    }
    return felder; // Abbildung Feld-Name -> Feld-Wert zurueck geben
    }
    inline const char * null_to_empty(const char * str)
    {
    if (! str)
    return "";
    return str;
    }
    int string2Int(string str)
    {
    istringstream istr (str);
    int i;
    istr >> i;
    return i;
    }
    CGI()
    {
    }
    virtual ~CGI()
    {
    }
    };
    Oliver Bleckmann, Nov 29, 2006
    #1
    1. Advertising

  2. "Oliver Bleckmann" <> writes:

    > Damn, what's wrong here?
    >
    > CGI cgi;
    > map<string,string> cgiParam = cgi.analyseCgiParam();
    > cout << cgiParam["plz1"] << endl;
    > cout << cgiParam["vorname1"] << endl;
    >
    > ///////////////////////
    >
    > #include <iostream>
    > #include <string>
    > #include <list>
    > #include <map>
    > #include <sstream>
    > using namespace std;
    >
    > class CGI
    > {
    > private:
    > static std::string query;

    ^^^^
    Here you declare a static variable. Somewhere in your program in a
    compile unit you must also define and initialize it, like a global
    variable.

    [snipped rest of posted code]

    somewhere in a .cc:

    std::string CGI::query = "";

    HTH,
    Rudiger
    Rud1ger Sch1erz, Nov 30, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    637
    Jules
    Aug 18, 2005
  2. Replies:
    4
    Views:
    1,630
    Peter Jansson
    Dec 16, 2005
  3. Mark
    Replies:
    4
    Views:
    6,131
    Githlar
    Mar 13, 2006
  4. Replies:
    3
    Views:
    586
  5. Replies:
    1
    Views:
    335
Loading...

Share This Page