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

Comments

@Keithcat1
Copy link

@Keithcat1 Keithcat1 commented Jul 4, 2020

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

@ianlancetaylor ianlancetaylor commented Jul 4, 2020

Any thoughts on how that would be implemented?

@Keithcat1
Copy link
Author

@Keithcat1 Keithcat1 commented Jul 5, 2020

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 this to the Backlog milestone Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.