Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a C file inside of a C++ program

Status
Not open for further replies.

BillWright

Programmer
May 12, 2003
3
US
Hi,

I have a .c and .h file for an interface to an application and I want to use these functions inside of a C++ program. I'm having trouble compiling them into my MS Visual C++ 6.0 project. At first I just added the files to my project and I got this error when I tried to compile the project and got an error about not finding a precompiled header.

I then tried to just compile the .c and .h file into a .lib file that I could use. This gave me an error about the use of _setvalue. Is this a standard C macro? My c file has the following includes and I don't find them (except string.h> in the VC directory. Anyone know if these are standard C files or if I'm missing some more application specific files?

#include <ssdef.h>
#include <descrip.h>
#include <iodef.h>
#include <lnmdef.h>
#include <string.h>

Bill

 
Right click the file in the FileView tree and select Settings from the context menu. Then select the C/C++ tab Category Precompiled Headers: select the Not using precompiled headers radio button.

-pete
I just can't seem to get back my IntelliSense
 
Palbano,

Thanks much for the response. I didn't know about that option. That certainly forced my project to compile the .c file. Now I get the same errors that I got when I manually tried to compile the .c file, concerning the strange macros and maybe related tot he include files I can't find. Any thoughts on those errors? I probably need to contact the application company.

Bill
 
>> I probably need to contact the application company.

What is the purpose for the company giving you those header files? They won't do any good unless you have either the .c source or a .lib and/or .dll

In other words if you don't have a library you would need to be able to build it. Otherwise how can use it if it does not exist?


-pete
I just can't seem to get back my IntelliSense
 
Pete,

Thanks again for your help. As I said in my original post, I have the .c and .h files. I guess I'm supposed to either link them directly to my project or create a .lib file. Either way, I can't compile the .c file because of the macros used in it (see first post) and the include files referenced (also listed in the first post) which I do not have and originally thought they were standard C header files. I was hoping someone would recognize those files and say there were standard and explain why I couldn't find them or confirm them as foreign (application specific).

Thanks,
Bill
 
The easiest way in such cases for Visual Studio:
1. change extension of file: *.c to *.cpp
2. Write in such renamed *.cpp - files:
#ifdef __cplusplus
extern &quot;C&quot;{
#endif
...
...Your renamed *.c - file, some #include You can let before #ifdef __cplusplus
...
#ifdef __cplusplus
}
#endif

Of course, You must remove old *.c file from project and add add renamed *.cpp - file
 
and do not foget include <stdafx> in your c-files
or switch off precompilate headers from project options.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top