Compiler Error

F

fabio

Gianni said:
Patrick said:
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.
 
P

Patrick Coleman

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
 
G

Gianni Mariani

Patrick said:
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 ?
 
P

Patrick Coleman

Patrick Coleman wrote:

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
 
G

Gianni Mariani

Rolf said:
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*,
*)' 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 -
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.
 
P

Patrick Coleman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top