www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/12/01:56:31

From: "Bill Blough" <NOSPAM DOT b_blough AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Newbie Linker Problems
Lines: 142
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Message-ID: <e9_q6.6977$R_6.717819@newsread2.prod.itd.earthlink.net>
Date: Mon, 12 Mar 2001 06:38:02 GMT
NNTP-Posting-Host: 209.26.240.180
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread2.prod.itd.earthlink.net 984379082 209.26.240.180 (Sun, 11 Mar 2001 22:38:02 PST)
NNTP-Posting-Date: Sun, 11 Mar 2001 22:38:02 PST
Organization: EarthLink Inc. -- http://www.EarthLink.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm currently learning C++ by reading, doing end of chapter exercises, and
occasionally a side project of my own.

I'm getting linker errors when I try and compile a program I wrote for one
of the end of chapter exercises.  After hours troubleshooting my own code, I
downloaded the exercise solution from the publisher's website.  That code
won't compile either, so I guss it's not my code.

It's a Windows 98 system.  I'm using a text editor for coding and doing
compilation from a command prompt.  LFN support is enabled.

my command line is:         gxx main.cpp -o main.exe

After reading the FAQ, I also tried:        gxx -O2 main.cpp -o main.exe

The error is:

----------------------------------------------------------------------

/DJGPP/tmp\ccZ2XPu0.o(.text+0x90):main.cpp: undefined reference to
`printthis(basic_string<char, string_char_traits<char>,
__default_alloc_template<false, 0> > const &)'
/DJGPP/tmp\ccZ2XPu0.o(.text+0xd4):main.cpp: undefined reference to
`printthat(basic_string<char, string_char_traits<char>,
__default_alloc_template<false, 0> > const &)'
collect2: ld returned 1 exit status

----------------------------------------------------------------------

The source is:

----------------------------------------------------------------------

// print.h
#ifndef PRINT_H
#define PRINT_H

#include <string>
using namespace std;

// Function prototype
void print(const string& s);

#endif

----------------------------------------------------------------------

// print.cpp
#include "print.h"
#include <string>
#include <iostream>
using namespace std;

void print(const string& s)
{
  cout << s << endl;
}

----------------------------------------------------------------------

// printthis.h
#ifndef PRINTTHIS_H
#define PRINTTHIS_H

#include <string>
using namespace std;

// Function prototype
void printthis(const string& s);

#endif

-----------------------------------------------------------------------

// printthis.cpp
#include "printthis.h"
#include "print.h"

void printthis(const string& s)
{
  print(s);
}

-------------------------------------------------------------------------

// printthat.h
#ifndef PRINTTHAT_H
#define PRINTTHAT_H

#include <string>
using namespace std;

// Function prototype
void printthat(const string& s);

#endif

------------------------------------------------------------------------

// printthat.cpp
#include "printthat.h"
#include "print.h"

void printthat(const string& s)
{
  print(s);
}

-----------------------------------------------------------------------


// main.cpp
#include "printthis.h"
#include "printthat.h"

int main()
{
  printthis("This is a test string using printthis().");
  printthat("This is a test string using printthat().");

  return 0;
}

----------------------------------------------------------------------


Any info relating to the problem, or advice on how to fix it or where to
look, would be greatly appreciated.  Other info/advice may be appreciated,
but possibly to a lesser degree :-)

Thanks in advance.

Bill Blough








- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019