Message-Id: <199709251326.IAA00892@labrats.com> Date: Thu, 25 Sep 1997 08:34:04 -0500 From: "Geoff Weber" To: djgpp AT delorie DOT com Subject: "undefined reference" error with variables from templates Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====_01216=_" Precedence: bulk --=====_01216=_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Appended are the source files I have arranged to demonstrate the problems I= am having... For those who haven't seen my previous posts, it also is included. Can anyone get this source file to compile and link? What obvious little glitch am I missing (I KNOW it has to be something simple)? I have built a simple source file with "vector"s that actually compiled and linked, even with strings. However, even when I just merge the mime64.cc and mime64.h files, I STILL get these errors!!! I have tried to make the variables non-static and anything else I can think of! Here I typedef'd the maps without improvements. I know there is a better way perhaps to write this module, but there are other modules in my program which depend on STL, and would be a pain to re-write. Besides,= this way should work, unless I'm missing something... (right now I'm= filled with doubts!)... Thanks for your replies so far!! This time I included everything, just as= I should have done in the beginning! Doh! Geoff Weber gweber AT labrats DOT com I was asked to supply more details on the problem below, so here they are: I am not using RHIDE at this time, I am using an editor called "Multi-Edit". To be honest, I didn't even know what RHIDE was until I was asked if I used it or not! I did check it out though, and I may start using it more...but I digress! I have used the following command lines in an attempt to compile just one of the modules with a simple "cout" main (it also declares and uses an instance of the class I am compiling, because I read in one of the archived mail messages that the compiler might want an instance declared): gcc -Wall -o mime64.exe mime64.cpp (didn't expect this to work) gcc -Wall -o mime64.exe mime64.cpp -lgpp (ditto) gcc -Wall -o mime64.exe mime64.cpp -lgpp -lstdcxx (SHOULD work) gxx -Wall -o mime64.exe mime64.cpp (all these should work) gxx -Wall -o mime64.exe mime64.cpp -lgpp gxx -Wall -o mime64.exe mime64.cpp -lgpp -lstdcxx / gcc -Wall -c mime64.cpp < gcc -Wall -o mime64.exe mime64.o (tried the libraries above= also) \ gxx -Wall -o mime64.exe mime64.o (tried the libraries above= also) Here is the output of the verbose build attempt from RHIDE (couldn't= capture the output otherwise - scrolled offscreen).... Compiling: mime64.cc Reading specs from c:/djgpp/lib\specs gcc version 2.7.2.1 c:/djgpp/bin\cpp.exe -lang-c++ -v -undef -D__GNUC__=3D2 -D__GNUG__=3D2= -D__cplusplus -D__GNUC_MINOR__=3D7 -Dunix -Di386 -DGO32 -DMSDOS= -DDJGPP=3D2 -DDJGPP_MINOR=3D1 -D__unix__ -D__i386__ -D__GO32__ -D__MSDOS__= -D__DJGPP__=3D2 -D__DJGPP_MINOR__=3D1 -D__unix -D__i386 GNU CPP version 2.7.2.1 (80386, BSD syntax) #include "..." search starts here: #include <...> search starts here: c:/djgpp/lang/cxx c:/djgpp/include c:/djgpp/contrib/grx20/include /usr/local/lib/g++-include /usr/local/include /usr/local/go32/include /usr/local/lib/gcc-lib/go32/2.7.2.1/include /usr/include End of search list. c:/djgpp/bin\cc1plus.exe c:/djgpp/tmp/RHaaaaaa\ccbaaaaa -quiet -dumpbase= mime64.cc -g -Wall -version -o c:/djgpp/tmp/RHaaaaaa\cccaaaaa GNU C++ version 2.7.2.1 (80386, BSD syntax) compiled by GNU C version= 2.7.2.1 c:/djgpp/bin\as.exe -o mime64.o c:/djgpp/tmp/RHaaaaaa\cccaaaaa no errors Creating: mime64.exe Error: mime64.o: In function `mime64::mime64(void)': mime64.cc(12) Error: undefined reference to `mime64::encode_string' mime64.cc(14) Error: undefined reference to `mime64::encode_string' mime64.cc(16) Error: undefined reference to `mime64::encode_string' Error: mime64.cc(.text+0xda): undefined reference to `mime64::encode' mime64.cc(17) Error: undefined reference to `mime64::decode' Error: mime64.cc(.text+0x10d): undefined reference to= `mime64::encode_string' Error: mime64.o: In function `mime64::Encode64(basic_string > &)': mime64.cc(45) Error: undefined reference to `mime64::encode' mime64.cc(51) Error: undefined reference to `mime64::encode' mime64.cc(54) Error: undefined reference to `mime64::encode' mime64.cc(58) Error: undefined reference to `mime64::encode' mime64.cc(59) Error: undefined reference to `mime64::encode' Error: mime64.o: In function `mime64::Decode64(basic_string > &)': mime64.cc(94) Error: undefined reference to `mime64::decode' Error: mime64.cc(.text+0x505): undefined reference to `mime64::decode' Error: mime64.cc(.text+0x534): undefined reference to `mime64::decode' Error: mime64.cc(.text+0x563): undefined reference to `mime64::decode' mime64.cc(109) Error: undefined reference to `mime64::decode' Error: mime64.o(.text+0x61f):mime64.cc: more undefined references to= `mime64::decode' follow There were some errors If anyone needs more information, please let me know! Thanks for any help you can offer - I'm just puzzled!! I have read the FAQ, and tried also looked at the mail-archive on the= delorie.com site. The only problems I saw that were similar to mine (env variable set= correctly, fresh 2.0+ install) did not have answers to their problems posted, which is= why I sent out this cry for help! Thanks again!!! Geoff gweber AT labrats DOT com >Jack, > >I realize it has been quite a while since you posted your note to the >DJGPP mail-archive about problems you were having linking "hex.cc". >However, I have run into the same exact problem you seem to have >had, and was wondering if you ever found out how to get around this >problem... more details follow. > >I downloaded and installed the DJGPP v2.0 distribution as per instructions >(fresh install). I also read the FAQ and any other info I could find >the last 2 days on this problem, but still don't know what causes it. >Basically, I am using some of the STL components (vectors, maps, etc), >as well as the "string" class ( basic_string or= whatever ), >and when I compile the modules, each compiles without any warnings or >errors, but when I try to link them together, I get a slew of "undefined >reference" errors. Even when I try to compile each one seperately, with >a simple stub main() function, I still get the same "undefined reference" >errors - even with functions and variables completely defined and= available >inside that same module!! > >I have tried using both gcc and gxx, as per the FAQ, and also tried >compiling with the -c option to get the *.o files, then linking as a >seperate step. I have also tried to explicitly including the g++ and >stdcxx libraries via the -lgpp and -lstdcxx switches. > >Can someone please tell me what I am doing wrong? > >Thanks!!! > >Geoff Weber >gweber AT labrats DOT com > > > >On April 19th, you posted: > >>I am new to DJGPP. I have a problem and would appreciate any help. It's >>probably something simple I am overlooking. >> >>When using RHIDE 1.2, and trying to Make using the following files in >>a project, I get the following error messages during link: >> >>Creating: hexgrid.exe >>Error: hex.o: In function `HEX::SetSize(int)': >>hex.cc(15) Error: undefined reference to `HEX::size' >>Error: hex.o: In function `HEX::GetSize(void)': >>hex.cc(20) Error: undefined reference to `HEX::size' >>Error: hex.o: In function `HEX::SetOffset(XY, int)': >>hex.cc(25) Error: undefined reference to `HEX::offset' >>Error: hex.cc(.text+0x27a): undefined reference to `HEX::offset' >>Error: hex.o: In function `HEX::GetOffset(int)': >>hex.cc(30) Error: undefined reference to `HEX::offset' >>Error: hex.cc(.text+0x2a5): undefined reference to `HEX::offset' >>Error: hex.o: In function `HEX::InitHex(int)': >>hex.cc(39) Error: undefined reference to `HEX::size' >>hex.cc(41) Error: undefined reference to `HEX::offset' >>Error: hex.cc(.text+0x33b): undefined reference to `HEX::offset' >>hex.cc(42) Error: undefined reference to `HEX::offset' >>Error: hex.cc(.text+0x35e): undefined reference to `HEX::offset' >>Error: hex.cc(.text+0x385): undefined reference to `HEX::offset' >>Error: hex.o(.text+0x38e):hex.cc: more undefined references to >`>HEX::offset' >>There were some errors >> >>I tried compiling and linking the same files using Turbo C++ and there= were >>no errors. > > --=====_01216=_ Content-Type: application/octet-stream; name=mime64.h Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="mime64.h" I2lmbmRlZiBNSU1FNjRfSA0KI2RlZmluZSBNSU1FNjRfSA0KDQojaW5jbHVk ZSA8bWFwPg0KI2luY2x1ZGUgPHN0cmluZz4NCg0KdHlwZWRlZiBtYXA8aW50 LCBpbnQsIGxlc3M8aW50PiA+IG1hcF9pbnRzOw0KDQpjbGFzcyBtaW1lNjQN CnsNCiAgIHByaXZhdGU6DQogICAgICBzdGF0aWMgc3RyaW5nIGVuY29kZV9z dHJpbmc7DQogICAgICBzdGF0aWMgbWFwX2ludHMgZW5jb2RlOw0KICAgICAg c3RhdGljIG1hcF9pbnRzIGRlY29kZTsNCg0KICAgcHVibGljOg0KICAgICAg bWltZTY0KCk7DQoNCiAgICAgIHN0cmluZyBFbmNvZGU2NCAoIHN0cmluZyAm c291cmNlICk7DQogICAgICBzdHJpbmcgRGVjb2RlNjQgKCBzdHJpbmcgJnNv dXJjZSApOw0KfTsNCg0KI2VuZGlmICAgICAgLyogTUlNRTY0X0ggKi8NCg== --=====_01216=_ Content-Type: application/octet-stream; name=mime64.cc Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="mime64.cc" I2luY2x1ZGUgPGlvc3RyZWFtLmg+DQoNCiNpbmNsdWRlIDxzdHJpbmc+DQoj aW5jbHVkZSA8bWFwPg0KDQojaW5jbHVkZSAibWltZTY0LmgiDQoNCnRlbXBs YXRlIGNsYXNzIG1hcDxpbnQsIGludCwgbGVzczxpbnQ+ID47DQoNCg0KbWlt ZTY0OjptaW1lNjQoKQ0Kew0KICAgdW5zaWduZWQgaW50IGk7DQoNCiAgIGVu Y29kZV9zdHJpbmcgPSAiQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNk ZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyI7DQoNCiAgIGZv ciAoIGkgPSAwOyBpIDwgZW5jb2RlX3N0cmluZy5zaXplKCk7IGkrKyApDQog ICB7DQogICAgICBlbmNvZGVbIGVuY29kZV9zdHJpbmdbaV0gXSA9IGk7DQog ICAgICBkZWNvZGVbIGkgXSA9IGVuY29kZV9zdHJpbmdbaV07DQogICB9DQoN CiAgIC8qcmV0dXJuICggdGhpcyApOyovDQp9DQoNCg0Kc3RyaW5nIG1pbWU2 NDo6RW5jb2RlNjQgKCBzdHJpbmcgJnNvdXJjZSApDQp7DQogICBsb25nICAg bCwgdDsNCiAgIGludCAgICBpLCBqOw0KICAgaW50ICAgIGNoYXJzX2xlZnQs IGNoYXJzX3RyaXBzOw0KICAgaW50ICAgIHNoaWZ0X2JpdHM7DQogICBzdHJp bmcgdGVtcCA9ICIiOw0KDQogICBjaGFyc19sZWZ0ICA9IHNvdXJjZS5zaXpl KCkgJSAzOw0KICAgY2hhcnNfdHJpcHMgPSBzb3VyY2Uuc2l6ZSgpIC0gY2hh cnNfbGVmdDsNCg0KICAgZm9yICggaSA9IDA7IGkgPCBjaGFyc190cmlwczsg aSArPSAzICkNCiAgIHsNCiAgICAgIGwgPSAoIChsb25nKSBzb3VyY2Vb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AgZGVjb2Rl W3NvdXJjZVtpKzFdXSA8PCAxMiB8DQogICAgICAgICAgZGVjb2RlW3NvdXJj ZVtpKzJdXSA8PCA2ICB8DQogICAgICAgICAgZGVjb2RlW3NvdXJjZVtpKzNd XTsNCg0KICAgICAgZm9yICggaiA9IDA7IGogPCAzOyBqKysgKQ0KICAgICAg ew0KICAgICAgICAgc2hpZnRfYml0cyA9IDE4IC0gKGogKiAzKTsNCiAgICAg ICAgIHRlbXAgICAgICArPSAoY2hhcikgKCAoIGwgJiAoMHhmZiA8PCBzaGlm dF9iaXRzKSApID4+IHNoaWZ0X2JpdHMgKTsNCiAgICAgIH0NCiAgIH0NCg0K ICAgaWYgKCBudW1fZXFzID4gMCApDQogICB7DQogICAgICBpZiAoIG51bV9l cXMgPT0gMSApDQogICAgICB7DQogICAgICAgICBsID0gKCBkZWNvZGVbY2hh cnNfcXVhZHNdICkgICA8PCAxMCB8DQogICAgICAgICAgICAgKCBkZWNvZGVb Y2hhcnNfcXVhZHMrMV0gKSA8PCA0ICB8DQogICAgICAgICAgICAgKCBkZWNv ZGVbY2hhcnNfcXVhZHMrMl0gKSA+PiAyOw0KDQogICAgICAgICB0ZW1wICs9 IChjaGFyKSAoICgweGZmMDAgJiBsKSA+PiA4ICk7DQogICAgICAgICB0ZW1w ICs9IChjaGFyKSAgICgweDAwZmYgJiBsKTsNCiAgICAgIH0NCg0KICAgICAg ZWxzZSBpZiAoIG51bV9lcXMgPT0gMiApICAgICAgLyogdGhlcmUgc2hvdWxk IEFMV0FZUyBiZSAxIG9yIDIgJz0nIGF0IHRoZSBlbmQuLi4gKi8NCiAgICAg IHsNCiAgICAgICAgIHRlbXAgKz0gKGNoYXIpICggKCBkZWNvZGVbY2hhcnNf cXVhZHNdICkgICA8PCAyIHwNCiAgICAgICAgICAgICAgICAgICAgICAgICAg KCBkZWNvZGVbY2hhcnNfcXVhZHMrMV0gKSA+PiA0ICk7DQogICAgICB9DQog ICB9DQoNCiAgIHJldHVybiAoIHRlbXAgKTsNCn0NCg0KDQppbnQgbWFpbiAo IHZvaWQgKQ0Kew0KICAgbWltZTY0IGVuY29kZXI7DQogICBzdHJpbmcgdGVt cDsNCg0KICAgdGVtcC5hc3NpZ24gKCAidGVzdGluZyIgKTsNCg0KICAgY291 dCA8PCAidGVzdGluZyAtPiAiIDw8IGVuY29kZXIuRW5jb2RlNjQgKCB0ZW1w ICkgPDwgZW5kbDsNCg0KICAgcmV0dXJuICggMCApOw0KfQ0K --=====_01216=_--