golang/go

cmd/cgo: inject preamble before other include directives

Open

#35,315 opened on Nov 2, 2019

View on GitHub
 (17 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
FeatureRequestNeedsInvestigationcompiler/runtimehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Yes

What did you see?

The cgo generated file _cgo_export.c includes stdlib.h before anything else (see here). It precludes the possibility to use some "include first" headers without errors or warnings, such as Python.

From the Python docs:

Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included.

Cgo should allow to inject a C preamble before any other include directive.

Contributor guide