Linking C++ with C

In order to link C procedures into C++ programs, you need to declare your C functions in your C++ programs by declaring them in your C++ file. An example is

	extern "C" {
	        double bleft(double);
	 }
which declares sqrt to be a function that takes a double as an argument and returns a double. This information is needed so that C++ can check that your uses of this function have the correct type.

If you're using makefiles, you can have the files combined automatically. You'd could use a Makefile like:


	SRCS = foo.C bar.c
	OBJS = foo.o bar.o


	.SUFFIXES: .C .o
	.C.o: ; $(C++) $(C++FLAGS) -c $<
	C++=g++


	prog: $(OBJS)
		$(C++) $(C++FLAGS) -o prog $(OBJS) -lm
to link together foo.c (the c++ file) and bar.c (ordinary C) to make the executable program prog.