Topic: Mixing C++ with C
Author: mudrt@uxa.ecn.bgu.edu (Darren R. Thompson)
Date: 1 Aug 1994 11:04:09 -0500 Raw View
To whom it may concern,
I am trying to compile C and C++ code and I was wondering
how to include C++ code with C. Also, if there are any
important things to remember when doing this please let me
know. Below is a partial listing of my code.
In the main program voice.c++:
#include <gl/gl.h>
#include <gl/device.h>
#define CUBE
extern "C" {
#include "drawCode.h"
}
#include "cave.h"
#ifndef AUDIO
#include "audioOutPut.h"
#include "audioInPut.h"
#endif
..
..
..
..
In drawCode.h:
#include <stdio.h>
#include <gl/gl.h>
#include <gl/device.h>
#include <gl/sphere.h>
#include <math.h>
#include <unistd.h>
void MyInit();
void MyDraw();
In drawCode.c:
#include "drawCode.h"
#include "materials.h"
#include "lights.h"
#include "cave.h"
#include "cube.h"
#define AUDIO
extern "CPP" {
#include "audioInPut.h"
#include "audioOutPut.h"
}
..
..
..
..
Makefile:
DEPEND = Dpndfile
SRC = voice.c++ drawCode.c audioInPut.c++ audioOutPut.c++ fft.c++
OBJ = voice.o drawCode.o audioInPut.o audioOutPut.o fft.o
C_FLAG = -g3 -c -I/usr/local/CAVE/include -L/usr/local/CAVE/lib
L_FLAG = -g3 +w +p -o voice
STD_LIB = -L/usr/local/CAVE/lib -laudio -laudiofile -laudioutil -lm -lcavesim5 -lsphere -lgutil -limage -lgl_s
STD_INCL = -I/usr/include/CC -I/usr/include -I/usr/local/CAVE/include
########################
default: all
include $(DEPEND)
.c.o:
cc -cckr $(C_FLAG) $(STD_INCL) $*.c
.c++.o:
CC $(C_FLAG) $(STD_INCL) $*.c++
all: $(OBJ) $(DEPEND)
CC $(L_FLAG) $(STD_INCL) $(OBJ) $(STD_LIB)
dep: $(SRC)
CC -M $(SRC) $(STD_INCL) > $(DEPEND)
make
Compiler Errors:
cfe: Error: drawCode.c, line 6: Syntax Error
extern "CPP" {
-------------^
cfe: Error: /usr/include/CC/iostream.h, line 49: Syntax Error
class streambuf ;
------^
cfe: Error: /usr/include/CC/iostream.h, line 50: Syntax Error
class ostream ;
------^
cfe: Error: /usr/include/CC/iostream.h, line 53: Syntax Error
class ios {
------^
cfe: Error: /usr/include/CC/iostream.h, line 57: Syntax Error
enum io_state { goodbit=0, eofbit=1, failbit=2, badbit=4,
^
cfe: Error: /usr/include/CC/iostream.h, line 58: Syntax Error
hardfail=0200};
-------------^
cfe: Error: /usr/include/CC/iostream.h, line 62: Syntax Error
nocreate=040, noreplace=0100} ;
----------------------------^
cfe: Error: /usr/include/CC/iostream.h, line 63: Syntax Error
enum seek_dir { beg=0, cur=1, end=2 } ;
------------- ----------------------^
cfe: Error: /usr/include/CC/iostream.h, line 79: Syntax Error
} ;
--^
cfe: Error: /usr/include/CC/iostream.h, line 87: Syntax Error
ios(streambuf*) ;
--------------^
cfe: Error: /usr/include/CC/iostream.h, line 90: Syntax Error
long flags() const { return x_flags ; }
^
cfe: Error: /usr/include/CC/iostream.h, line 90: Syntax Error
long flags() const { return x_flags ; }
---- --------^
cfe: Error: /usr/include/CC/iostream.h, line 91: Syntax Error
long flags(long f);
^
cfe: Error: /usr/include/CC/iostream.h, line 97: Syntax Error
int width() const { return x_width ; }
--- --------^
cfe: Error: /usr/include/CC/iostream.h, line 98: Syntax Error
int width(int w)
^
cfe: Error: /usr/include/CC/iostream.h, line 104: Syntax Error
ostream* tie() { return x_tie ; }
-------- ----- ^
cfe: Error: /usr/include/CC/iostream.h, line 105: Syntax Error
char fill(char) ;
^
cfe: Error: /usr/include/CC/iostream.h, line 106: Syntax Error
char fill() const { return x_fill ; }
---- -------^
cfe: Error: /usr/include/CC/iostream.h, line 107: Syntax Error
int precision(int) ;
^
cfe: Error: /usr/include/CC/iostream.h, line 108: Syntax Error
int precision() const { return x_precision ; }
--- ------------^
cfe: Error: /usr/include/CC/iostream.h, line 110: Syntax Error
int rdstate() const { return state ; }
^
cfe: Error: /usr/include/CC/iostream.h, line 110: Syntax Error
int rdstate() const { return state ; }
--- ----------^
cfe: Error: /usr/include/CC/iostream.h, line 111: Syntax Error
operator void*()
---------^
cfe: Error: /usr/include/CC/iostream.h, line 116: Syntax Error
operator const void*() const
---------^
cfe: Error: /usr/include/CC/iostream.h, line 122: Syntax Error
int operator!() const
^
cfe: Error: /usr/include/CC/iostream.h, line 124: Syntax Error
int eof() const { return state&eofbit; }
^
cfe: Error: /usr/include/CC/iostream.h, line 124: Syntax Error
int eof() const { return state&eofbit; }
--- ------^
cfe: Error: /usr/include/CC/iostream.h, line 125: Syntax Error
int fail() const { return state&(failbit|badbit|hardfail); }
^
cfe: Error: /usr/include/CC/iostream.h, line 125: Syntax Error
int fail() const { return state&(failbit|badbit|hardfail); }
--- -------^
cfe: Error: /usr/include/CC/iostream.h, line 126: Syntax Error
int bad() const { return state&badbit ; }
^
cfe: Fatal: Too many errors... goodbye.
*** Error code 1 (bu21)
You can either post the answer up or send it to me.
Thank you,
Darren.