Compiler Error

Discussion in 'C++' started by fabio, Aug 28, 2003.

  1. fabio

    fabio Guest

    Gianni Mariani wrote:

    > Patrick Coleman wrote:
    >> Hi,
    >> This may seem to be a basic question, but I keep getting the following
    >> error:
    >> main.cc:93: undefined reference to
    >> `AT_UrlParser::AT_UrlParser[in-charge](char const*,
    >> std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
    >>
    >> line 93:
    >> AT_UrlParser qservice(service);
    >>
    >> I'm including a custom header file that defines AT_UrlParser.
    >>
    >> What is this error message telling me? It seemed to me that it started
    >> happening for no reason at all (that line was compiling fine until I
    >> converted some of my char vars to strings and used .c_str() later in the
    >> code), but it must have been something I've done.
    >>
    >> Thanks,
    >> Patrick

    >
    >
    > Which version of the compiler are you using ?
    >
    > It says it is unable to find the constructor defintion.
    >
    > Are there some more messages ?
    >
    > Does placing :
    >
    > AT_UrlParser qservice("http://test.com/test/test.html");
    >
    > on line 93 change the error ?



    I'm just trying to *guess*; it could be a problem of linking. Your function
    seems to be declared but not defined anywhere. But it's just a guessing,
    try to post your code.
    fabio, Aug 28, 2003
    #1
    1. Advertising

  2. Hi,
    This may seem to be a basic question, but I keep getting the following
    error:
    main.cc:93: undefined reference to
    `AT_UrlParser::AT_UrlParser[in-charge](char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'

    line 93:
    AT_UrlParser qservice(service);

    I'm including a custom header file that defines AT_UrlParser.

    What is this error message telling me? It seemed to me that it started
    happening for no reason at all (that line was compiling fine until I
    converted some of my char vars to strings and used .c_str() later in the
    code), but it must have been something I've done.

    Thanks,
    Patrick
    Patrick Coleman, Aug 28, 2003
    #2
    1. Advertising

  3. Patrick Coleman wrote:
    > Hi,
    > This may seem to be a basic question, but I keep getting the following
    > error:
    > main.cc:93: undefined reference to
    > `AT_UrlParser::AT_UrlParser[in-charge](char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
    >
    > line 93:
    > AT_UrlParser qservice(service);
    >
    > I'm including a custom header file that defines AT_UrlParser.
    >
    > What is this error message telling me? It seemed to me that it started
    > happening for no reason at all (that line was compiling fine until I
    > converted some of my char vars to strings and used .c_str() later in the
    > code), but it must have been something I've done.
    >
    > Thanks,
    > Patrick



    Which version of the compiler are you using ?

    It says it is unable to find the constructor defintion.

    Are there some more messages ?

    Does placing :

    AT_UrlParser qservice("http://test.com/test/test.html");

    on line 93 change the error ?
    Gianni Mariani, Aug 28, 2003
    #3
  4. On Thu, 28 Aug 2003 08:10:47 +0000, Gianni Mariani wrote:

    > Patrick Coleman wrote:


    <snip>

    >
    >
    > Which version of the compiler are you using ?
    >
    > It says it is unable to find the constructor defintion.
    >
    > Are there some more messages ?
    >
    > Does placing :
    >
    > AT_UrlParser qservice("http://test.com/test/test.html");
    >
    > on line 93 change the error ?


    Hi,

    Here is the relevant code:

    ---begin---
    //Includes
    #include <iostream>
    #include <fstream>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <errno.h>
    #include <at_url_parse.h>

    using namespace std;

    <snip>

    int getnodes (char service[]) //service is a URL
    {

    <snip>

    string host;
    string path;

    //AT_UrlParser parsedservice(service); //This is my original line
    AT_UrlParser qservice("http://test.com/test/test.html"); //This is your suggested line - neither works

    host = qservice.m_host;
    path = qservice.m_path;

    <snip>
    }
    ---end---

    The relevant header is 'at_parse_url.h', see thread 'Splitting URLs' in
    this group. My compiler messages are below (these are from the
    compilation of the code exactly as it is above):

    (I am using an IDE (Anjuta) so the compiler messages are not pretty...)

    ---begin---
    <skipping useless make messages>
    Making all in src
    make[2]: Entering directory `/home/pcoleman/Projects/CECID/src'
    if g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/include -Wall -O1 -g -g -O2 -MT cecid-main.o -MD -MP -MF ".deps/cecid-main.Tpo" \
    -c -o cecid-main.o `test -f 'main.cc' || echo './'`main.cc; \
    then mv ".deps/cecid-main.Tpo" ".deps/cecid-main.Po"; \
    else rm -f ".deps/cecid-main.Tpo"; exit 1; \
    fi

    In file included from main.cc:16:
    at_url_parse.h: In constructor `AT_UrlString::AT_UrlString(const std::string&)':
    at_url_parse.h:33: warning: base initializer for `std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
    at_url_parse.h:33: warning: will be re-ordered to precede member initializations

    In file included from main.cc:16:
    at_url_parse.h:164:29: warning: no newline at end of file

    main.cc: In function `int buildlist()':
    main.cc:48: warning: unused variable `int dc'

    /bin/sh ../libtool --mode=link g++ -g -O2 -o cecid cecid-main.o
    g++ -g -O2 -o cecid cecid-main.o

    cecid-main.o(.text+0x403): In function `getnodes(char*)':
    /home/pcoleman/Projects/CECID/src/main.cc:94: undefined reference to `AT_UrlParser::AT_UrlParser[in-charge](char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
    collect2: ld returned 1 exit status

    make[2]: *** [cecid] Error 1
    make[2]: Target `all' not remade because of errors.
    make[2]: Leaving directory `/home/pcoleman/Projects/CECID/src'
    make[2]: Entering directory `/home/pcoleman/Projects/CECID'
    make[2]: Leaving directory `/home/pcoleman/Projects/CECID'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/pcoleman/Projects/CECID'
    make: *** [all] Error 2

    ---end---

    and heres my output from 'g++ -v'...:

    ---begin---
    Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/3.2.2/specs
    Configured with: ../gcc-3.2.2/configure --prefix=/usr --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --target=i386-slackware-linux --host=i386-slackware-linux
    Thread model: posix
    gcc version 3.2.2
    ---end---

    ....so I hope that helps.

    Thanks for the assistance,
    Patrick
    Patrick Coleman, Aug 28, 2003
    #4
  5. Rolf Magnus wrote:
    > Patrick Coleman wrote:
    >
    >
    >>int getnodes (char service[]) //service is a URL

    >
    >
    > ...
    >
    >
    >>//AT_UrlParser parsedservice(service); //This is my original line
    >>AT_UrlParser qservice("http://test.com/test/test.html"); //This is
    >>your suggested line - neither works

    >
    >
    >>cecid-main.o(.text+0x403): In function `getnodes(char*)':
    >>/home/pcoleman/Projects/CECID/src/main.cc:94: undefined reference to
    >>`AT_UrlParser::AT_UrlParser[in-charge](char const*,
    >>std::basic_string<char, std::char_traits<char>, std::allocator<char>
    >>
    >>>*)' collect2: ld returned 1 exit status

    >
    >
    > Seems you declared a constructor for a class named AT_UrlParser that
    > thakes a char* and and std::string with at least that std::string as
    > default parameter, but you didn't define it, or maybe you forgot to
    > link that definition in.


    Right.

    You need to make sure that at_url_parse.o gets linked in as well.

    this line -
    >>> g++ -g -O2 -o cecid cecid-main.o


    should look like -

    g++ -g -O2 -o cecid cecid-main.o at_url_parse.o

    It's a simple linker issue.

    As for the warnings at_url_parse.h:33, I don't get these on gcc 3.3.1.

    I'm no autoconf expert but if you have control of the build tools, look
    a MakeXS (shameless plug) on http://freshmeat.net, it would have
    automatically done the right thing.
    Gianni Mariani, Aug 28, 2003
    #5
  6. Hi,
    Thanks for all the help. I finally got the problem fixed, and I know a lot
    more about including and linking headers now :)
    Thanks,
    Patrick
    Patrick Coleman, Aug 29, 2003
    #6
    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. Yan
    Replies:
    0
    Views:
    1,132
  2. Jack Wright
    Replies:
    5
    Views:
    623
    Shiv Kumar
    Jan 19, 2004
  3. Ram
    Replies:
    0
    Views:
    2,832
  4. Andrey Batyuck

    Compiler compiler with C++ as output

    Andrey Batyuck, May 11, 2004, in forum: C++
    Replies:
    3
    Views:
    438
    Frederik Hertzum
    May 17, 2004
  5. RickMuller
    Replies:
    4
    Views:
    705
    Alexey Shamrin
    Mar 26, 2005
Loading...

Share This Page