1

I have been trying for a while to create a DLL via Visual Studio 2019. Most of the files are .cpp and their headers (.cpp & .h), but there is one which is .c file (and its header).

When I include "pch.h" from the .c file, I get the following error:

Error C1853 precompiled header file is from a different version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)

Among of the tries I did, but unfortunately none of them worked:

  • Replaced the suffix from .c to .cpp, and tried the opposite too (all the .cpp to .c)

  • #include "stdafx.h" instead of #include "pch.h"

I have also created another DLL (the example from MSDN site) to see how should it be, and from what it seems - the only problem is caused by the .c file.

The sites where I was looking for any good solution to my problem:

And more sites....

I am doing this to have a connection between my C/C++ code to my GUI (C#, WindowsForms). Hence, if you might have a better general solution instead of creating a dll, or any suggestions about fixing this issue, it will be great to read!

My question may look similar to other questions, but I couldn't find an answer for mine. Sorry if there are any English mistakes. If there is anything wrong, I will fix it.

Thank you very much beforehand.

Modern
  • 75
  • 2
  • 9
  • 1
    Changing the extension of the problematic file from .c to .cpp should be enough, if the file compiles fine as C++ (and make sure your rebuild all). What's the error in that case? Otherwise you can exclude this file from precompiled header (but it will have to compile with its own headers) – Simon Mourier Feb 05 '21 at 10:21
  • Changing the extension leads to a lot of errors that weren't there before the exchanging. If it helps, the .c file is sqlite3.c. Here are some examples of the errors I get after changing the extension: – Modern Feb 05 '21 at 10:37
  • sqlite3.c is self-sufficient, so the best is to exclude it from pch: https://stackoverflow.com/questions/9318951/disabling-precompiled-headers-for-a-specific-file-in-a-vc-2010-project – Simon Mourier Feb 05 '21 at 10:47
  • Thanks for leaving comments! I have already tried what you sent. If i'm not wrong, and that's what you meant: If I set the filed of Precompiled-Header to Not Using Precompiled Headers and deleting the pch.h from Precompiled Header File, then I do not get errors from sqlite3.c, however I do get linkage erros that I haven't had before. – Modern Feb 05 '21 at 11:01
  • Yes, but just change that only for the sqlite3.c. If that's you did, well, you have other problems. Welcome to the joys of C/C++... If you can post a reproducing project somewhere, we can have a look. – Simon Mourier Feb 05 '21 at 11:58
  • I did it. If it can help, the following are the links to the pictures of the relevant properties. The properties of the project (through Solution Explorer): https://imgur.com/Wo70iuQ The properties of sqlite3.c: https://imgur.com/i6R4jii – Modern Feb 05 '21 at 16:04
  • So you have other problems. – Simon Mourier Feb 05 '21 at 16:25

0 Answers0