News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Disabling PCH for a single file

Started by nji, July 03, 2020, 10:06:25 AM

Previous topic - Next topic

nji

Hello.
If the whole project is using pch, but a single file doesn't...
Is there a way to disable it for this file only?
Or do I have to remove the project-wide pch usage
and insert it for all but the one file?
Thanks in advance.

nji

That problem arises when inserting sqlite amalgamation (C) into
an wxWidget project (C++).
The latter has project wide PCH usage and this doesn't work for
the sqlite code.
I meanwhile tried to disable PCH usage in the advanced properties
of sqlite.c, adding  -DNOPCH to
$compiler $options $includes -c $file -o $object
But no effect, it still uses pch.
The command line is like this
gcc.exe  -DNOPCH -Wall -pipe -mthreads -Winvalid-pch -include wx_pch.h -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -DWX_PRECOMP -g -ID:\develop\wxWidgets\include -ID:\develop\wxWidgets\lib\gcc_dll\mswu -c D:\develop\sqlite-amalgamation-3310100\sqlite3.c -o obj\Debug\sqlite-amalgamation-3310100\sqlite3.o


oBFusCATed

I don't think so. You have to probably put the sqlite code in a static library and build it separately.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

nji

Thanks.  :)

I meanwhile tried that way.

Originally I thought taking the amalgamation would be the simplest way of using sqlite.
But taking the precompiled dll + headers from amalgamation is even easier.
As long as your compiler matches with the one used for the precompiled dll.
You don't even need the def file.

stahta01

Do you understand the idea of CB targets?
If not, I suggest you learn how to have multiple targets in a project.
You can set different compiler and linker options for each target.

I would create an static library target for the sqlite file.

Tim S.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

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 :).
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

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


--- 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
--


Tim S.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]