Subject: Re: problems compiling c++ source
To: Ethan Bakshy <ethan@enteract.com>
From: Patrick Welche <prlw1@newn.cam.ac.uk>
List: netbsd-help
Date: 09/05/1999 18:38:44
Ethan Bakshy wrote:
>
>  /~~~ main.cpp
> 
> #include "apvector.h" int main (int argc, char **argv) {
>     return (0); }
> 
>  \___ main.cpp
> 
> (taken from an email by richard rauch)
> 
> now it _should_ compile cleanly, there are clearly no syntax errors
> in this source file, and a few other people on the list were able
> to compile it fine. But for some reason, I am getting errors in
> /usr/include/machine/types.h after I tried compiling the source
> file with both ''gcc main.cpp'', ''g++ main.cpp''.

Again, it compiles for me (g++ main.cpp -Wall). What does gcc -v
give you? Same as me:
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
?

> My original
> source file actually uses the object, as well as a few other
> libraries, here it is:
> 
>  /~~~ main2.cpp
> 
> #include <iostream.h> #include <iomanip.h> #include <stdlib.h>
> #include <time.h> #include "apvector.h"
> 
> int main ()
>   {
> 	int i, k = 0; const int VECT_SIZE = 100; apvector<int>
> 	myVector(VECT_SIZE);
> 
> 	srand(time(0));
> 
>     for( i = 0; i < VECT_SIZE; i++)
>      myVector[i] = ( k += rand() % 10 );
> 
> 	cout << myVector.binarySearch(myVector[75]);
> 
> 	return 0; }
> 
> \___ main2.cpp
> 
> When I try compiling this one, it tells me that there are errors
> in /usr/include/assert.h. My guess is either all my header files
> are wacked, or maybe there is something wrong with my compiler?

When I try, I get:

% g++ main2.cpp -Wall
main2.cpp: In function `int main()':
main2.cpp:17: no matching function for call to `apvector<int>::binarySearch (int &)'
 
and indeed, a grep for "binary" on apvector* returns nothing, so the error
message seems correct.

> One more thing- somebody told me that just compiling the apvector.cpp
> file works fine for him (using c++ -Wall -c apvector.cpp), I get
> syntax errors in my assert.h file, and then a whole bunch of errors
> dealing with the apvector.cpp file.

I did get rid of
#include "apvector.cpp"
from apvector.h before doing that though, and it compiled cleanly with no
mention of assert.h. Do you have
/usr/include/assert.h:
     $NetBSD: assert.h,v 1.7 1998/11/14 16:30:07 christos Exp $
?

This was on NetBSD 1.4. What port do you run? (/usr/include/machine points
to the port)

Cheers,

Patrick