help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compile error when using selfcode .h file


From: Simon Buchan
Subject: Re: compile error when using selfcode .h file
Date: Tue, 27 Sep 2005 17:15:30 +1200
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

fsshl@yahoo.com wrote:
I am in g++ or gcc 3.4.4 (tested on both linux ubuntu kernel 3.6.8 and
cygwin 1.5.18-1 dll on window xp-sp2)

I like to test and using the following .h (lib? I do not know yet to
make it become lib)

http://www.cs.duke.edu/~ola/ap/code/apstring.h

by simple test program
-------------------------------------------------------
#include <iostream>
#include "/home/eric/apstring.h"

using namespace std;

int main() {

apstring name;

cout << "Enter your last name: " << endl;
cin >> name;
cout << name;

  return 0;

}
---------------------------------------------------------------
but compiler response error
----------

$ g++   pg88.C -o pg88
In file included from
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/iostream.h:31,
                 from /home/eric/apstring.h:4,
                 from pg88.C:4:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or
antiquated header. Please consider using one of the 32 headers found in
section 17.4.1.2 of the C++ standard. Examples include substituting the
<X> header for the <X.h> header for C++ includes, or <iostream> instead
of the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/cygdrive/c/DOCUME~1/ERICLI~1/LOCALS~1/Temp/ccKePRMx.o:pg88.C:(.text+0x167):
undefined reference to `apstring::apstring()'
/cygdrive/c/DOCUME~1/ERICLI~1/LOCALS~1/Temp/ccKePRMx.o:pg88.C:(.text+0x1a5):
undefined reference to `operator>>(std::basic_istream<char,
std::char_traits<char> >&, apstring&)'
/cygdrive/c/DOCUME~1/ERICLI~1/LOCALS~1/Temp/ccKePRMx.o:pg88.C:(.text+0x1b8):
undefined reference to `operator<<(std::basic_ostream<char,
std::char_traits<char> >&, apstring const&)'
/cygdrive/c/DOCUME~1/ERICLI~1/LOCALS~1/Temp/ccKePRMx.o:pg88.C:(.text+0x1ca):
undefined reference to `apstring::~apstring()'
/cygdrive/c/DOCUME~1/ERICLI~1/LOCALS~1/Temp/ccKePRMx.o:pg88.C:(.text+0x1f4):
undefined reference to `apstring::~apstring()'
collect2: ld returned 1 exit status
-------------------------------------------------------------

  thanks in advance any advancer's advice or help
charles
First off, why? It clearly states it implements a sub-set of the standard C++ string class in the header. (It also uses pre-standard headers, which is why you get those warnings) If you still want to use it, you need to also compile the source file that goes with it (apstring.cpp at the same site) to get the definitions of the functions used, which is why it complains it can't find those apstring functions when it links
A typical commandline interaction:
# this is a comment
# note the -c option! I use cc as it is not case-sensitive.
# compile the object file with our main definitions
g++ -c pg88.cc -o pg88.o
# compile the object file with the apstring definitions
g++ -c apstring.cpp -o apstring.o
# link into a working application (note the lack of -c!)
g++    pg88.o apstring.o -o pg88

turning apstring into a (static or dynamic library) is probably overkill in this case. Look through the g++ docs for more information.
PS: the above interaction can be compressed into:
g++    pg88.cc apstring.cpp -o pg88
In a reasonably big system, however, this re-compiles every function every time, even if it wasn't changed. Read up on makefiles to make (pun intended) this all really easy once it's set up.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]