简体   繁体   中英

Using K&R-style C functions in C++ code

I'm trying to use oncrpc-windows project in my VC++ project in VS2010. The oncrpc exports functions in svc.h files without any arguments, but in fact the functions have arguments. For example, the header file exports

#define DllExport   __declspec( dllexport ) 
...
DllExport SVCXPRT *svcudp_create();

but the implementation file contains

SVCXPRT * svcudp_create(sock)
    int sock;
{

    return(svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE));
}

If I try to create C file which uses exported functions, then everything is OK, the code is compiled successfully. The problem is I can't use the exported function in my CPP code, the compiler stops with the following message

error C2660: 'svcudp_create' : function does not take 1 arguments

I tried to use extern "C" , however it didn't help. I'm wondering how can I use the exported functions in my VC++ project? Is it really need to write own header files with correct signatures?

You will need to compile any .c files which use K&R style syntax to object files before you compile your .cc or .cpp files. This should be done in a MakeFile.

Example:

PNAME = "ProjectName"
PROGRAM_FILES = program.cpp program.h

svc.o: svc.c svc.h
    gcc -c $< -o $@
program.o: $(PROGRAM_FILES)
    gcc -c $< -o $@
all: svc.o program.o
    gcc $< -o $(PNAME)
clean:
    -rm -f *.o $(PNAME)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM