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

Re: c++ include problem (preprocessor directives)



On Sat, 7 Aug 1999, Oleg Krivosheev wrote:

> On Sat, 7 Aug 1999, Micha Feigin wrote:
> > Subject: c++ include problem (preprocessor directives)
> > 
> > In my files the headers are included like this:
> > #ifdef NEWCPPH
> > #include <iostream>
> > #else
> > #include <iostream.h>
> > #endif
> > 
> > #include <cassert>
> > #include <cstring>
> > #include "input.h"
> > 

> > only then i get an error that the functions declared inside
> > input.h can't be found. The linker says: 
> > 
> > main.o: In function `main':
> > main.o(.text+0x16): undefined reference to `input(void)'
> > main.o(.text+0x8a): undefined reference to `input(char const *)'
> > collect2: ld returned 1 exit status
> > make: *** [main] Error 1
 
> > what am i doing wrong?
 
> learn about C++ name mangling
> 
> extern "C" is your friend

It appears the functions defined in input.h are not being linked to
main.  Try compiling input.cpp file (you do have the funtions
defined in a separate .cpp file don't you?) with output to an object
file, say, input.o, then link with something like this: 

    g++ -o main.o -Wall -pedantic -c  main.cpp
    g++ -o input.o -Wall -pedantic -c  input.cpp
    g++   main.o input.o  -o main

This will likely fix the linking errors.

--David
David Teague, dbt@cs.wcu.edu
Debian GNU/Linux Because software support is free, timely,
                 useful, technically accurate, and friendly.
                 (I'm hoping this is all of the above!)


Reply to: