Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: add #cgo CFLAGS and #CGO CXXFLAGS directives that only apply to files in the current package #40041

Open
Keithcat1 opened this issue Jul 4, 2020 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Keithcat1
Copy link

My situation is that instead of distributing static libraries, I have the C++ and C sources of the C package I'm wrapping stored in the same directory as my Go files, so that the package can in theory can be compiled on any C compiler.
In order to improve performance, I added a build tag which added the -flto flag, in order to enable link-time-optimization between all the C++ files.
However, I got an error when I added this line:
#CGO CFLAGS: -flto
to the file which implements LTO.
cannot load DWARF output from $WORK\b002\cgo.o: decoding dwarf section info a
t offset 0x0: too short
So I'd like a way to apply CFLAGS and CXXFLAGS to only the C and C++ files that are actually part of the package, and not CGO generated C files.

@ianlancetaylor ianlancetaylor changed the title CGO: Add #cgo CFLAGS and #CGO CXXFLAGS directives that only apply to files in the current package cmd/cgo: add #cgo CFLAGS and #CGO CXXFLAGS directives that only apply to files in the current package Jul 4, 2020
@ianlancetaylor
Copy link
Contributor

Any thoughts on how that would be implemented?

@Keithcat1
Copy link
Author

It would look something like this:
package cgo_wrapper
/*
#cgo CPACKAGEFLAGS: -flto
#cgo CXXPACKAGEFLAGS: -flto
*/
import "C"

This applies the specified CFLAGS and CXXFLAGS to only files in the current package, not aditional CGO helpers compiled by Go.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 11, 2020
@dmitshur dmitshur added this to the Backlog milestone Jul 11, 2020
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants