delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/17/14:46:36

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Pascal units in c++
Date: Fri, 17 Apr 1998 20:45:01 +0200
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 72
Message-ID: <3537A32D.F25F2D70@LSTM.Ruhr-UNI-Bochum.De>
References: <01bd6894$499fcd60$151601bf AT cb001687> <6h4hu8$hba AT news DOT u-strasbg DOT fr> <01bd694d$74dbc4c0$151601bf AT cb001687> <6h5eg3$dhp$1 AT orudios DOT magnet DOT at> <01bd6a17$6954d040$151601bf AT cb001687>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jasper van Woudenberg wrote:
> 
> Hi!
> I've tried this like the following:
> 
> =========== VESA.H ===========
> #ifndef _VESA_H_
> #define _VESA_H_
> 
> // prototypes, structures, vars, etc.
> 
> #endif
> 
> ========== VESA.CPP ==========
> #ifndef _VESA_CPP_
> #define _VESA_CPP_
> 
> // function body's
> 
> #endif
> 
> ========== MAIN.CPP ==========
> include "vesa.h"
> 
> void main()
> {
>   // function call to function in VESA.CPP
> };
> 
> I get an "undefined reference" in main() on the line which calls the
> function. The only way to solve this problem is to add the line '#include
> "vesa.h"' to vesa.cpp, and to include vesa.cpp in the main program, not
> vesa.h. Somehow i get the feeling this is not the way it is supposed to be
> done... 
Hmm. TP has a "smart" mode of figuring out which units to make
when they are not there. So, if you have a main program main.pas that
USES Unit;
and a unit.pas, tp will automatically make unit.tpu from unit.pas, and
link all that together. 
gcc and friends work differently. You can have mixed language projects
made
of C, FORTAN, and Pascal (Basic?). 
So there is no automatism like that. The quick thing is to say
gxx -o main.exe main.cpp vesa.cpp
but that'll compile vesa.cpp everytime. So it's better to
gxx -c main.cpp           /* compile main */
gxx -c vesa.cpp           /* compile vesa */
gxx -o main.exe main.o vesa.o  /* linking */

Even better is get used to Makefiles, or use an IDE like RHIDE. 


>
> BTW: how can i convert an object file to a library?
> 

ar -svr libfoo.a vesa.o

-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


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