View Full Version : How pure C program calls a C++ library

December 11th, 2007, 09:33 AM
Hi, everyone:
I develop a project in pure environment. Now, I get a open source about STUN protocol written in C++ and want to use those function. An the beginning, I try to manually convert C++ functions into corresponding C functions and find that there are really so many statements I need to modify. So I wanto to find another way to replace the iteractive way. What shall I do???
The following is part of content of Makefile:

CXXFLAGS+=-g -O -Wall
LDFLAGS+=-g -O -Wall

all: server client

- rm *.o server client tlsServer

server: server.o stun.o udp.o
$(CXX) $(LDFLAGS) -o $@ $^

client: client.o stun.o udp.o
$(CXX) $(LDFLAGS) -o $@ $^

$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

libstun.a: stun.o udp.o
ar rv $@ $<

co $@

# Dependancies
server.o: stun.h udp.h
client.o: stun.h udp.h
stun.o: stun.h udp.h
udp.o: stun.h udp.h

December 11th, 2007, 10:01 AM
Try compiling your C source files as C++ files to see if they will build without error. A lot of times, C programs are syntactically valid as C++ programs, but just don't use any of the object oriented features.