User forums > Using Code::Blocks

Disabling PCH for a single file

<< < (2/2)

sodev:
The problem here is not PCH itself but a mix of C and C++. The SQLite file has the .c extension so it will be compiled as C code, the project settings however force include the PCH which was created in C++ mode and this causes the error. So beside the two outlined solutions, extra target that compiles the file with different settings and using a precompiled variant, i propose a third solution: rename the file to .cpp so it will be compiled in C++ mode. If SQLite can be compiled in C++ mode this is the simplest solution :).

oBFusCATed:

--- Quote from: sodev on July 06, 2020, 02:46:00 am ---If SQLite can be compiled in C++ mode this is the simplest solution :).

--- End quote ---
This is one big "if". C and C++ aren't really compatible in this way. Even if it compiles it might be broken due to different UB rules in the two languages.

sodev:
If the code doesn't use any constructs that are invalid in C++ and contains the usual extern "C" wrapping there should be no problem. And a quick check reveals that at least the amalgamation source does contain this wrapping, so im pretty confident that works without problem.

In my experience C libraries work without issues in C++ mode (especially if they already contain the wrapping), however i am not dealing with embedded c libraries which might contain hardcore c hacks that break c++ :).

stahta01:
What I think is the proper long term fix for this problem.

Git patch attached


--- Code: ------ a/src/plugins/scriptedwizard/resources/wxwidgets/pch/wx_pch.h
+++ b/src/plugins/scriptedwizard/resources/wxwidgets/pch/wx_pch.h
@@ -10,7 +10,9 @@
 #ifndef WX_PCH_H_INCLUDED
 #define WX_PCH_H_INCLUDED
 
-// basic wxWidgets headers
+#ifdef __cplusplus
+
+// basic wxWidgets C++ headers
 #include <wx/wxprec.h>
 
 #ifdef __BORLANDC__
@@ -25,4 +27,6 @@
     // put here all your rarely-changing header files
 #endif // WX_PRECOMP
 
+#endif // __cplusplus
+
 #endif // WX_PCH_H_INCLUDED
--

--- End code ---

Tim S.

Navigation

[0] Message Index

[*] Previous page

Go to full version