user7042812 user7042812 - 1 year ago 85
C Question

Precompiled header is from previous version of compiler

How do I use c library in large C++ codebase?

I have found some good c library, and since c and c++ are compatible that's awesome for me. I have this big codebase with many projects, and i want to use that library inside one of projects.

So I built library on C drive, and after that I just placed it into folder with the project i want to use it with, changed references in project properties to target that library etc.

After that I have called from one of cpp files function in my send.c file which included some library files, and got error during building

Precompiled header is from previous version of compiler

So I wanted to ask:

  1. Should I build separately library or is it ok to do this way as I did ?

  2. How should i fix these errors ? (I tried changing from .c into .cpp but library than has many errors)

  3. Where should i put library ? Are there any good conventions ? Since now it is just there pasted next to the project

  4. How can if it can, previous compiling have impact on new build ?! Wouldn't it just precompile it again ?

  5. In this large codebase i don't see that many libraries so autonomous like this one. Can i turn it somehow into one .lib file and somehow use it easier by just importing it? Since I wont be changing it, it will always be used just for message sending. And like this there is a bunch of things that need to be configured in each project that would use it maybe in the future

Thanks !

Note 1:
I am using Visual Studio 2015 on Windows Server 2012 R2.

Answer Source

Fixed this by following steps:

  1. Turned off precompiled headers
  2. Deleted .pch file

Since this was not fixing the error I did some few more things:

  1. Changed extension of send.c to send.cpp
  2. Properties->C/C++->Advanced->Compile As C Code (/TC)
  3. Properties->General-> character set changed to Use Multi-Byte Character Set

And this fixed my problem :)