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

cgo: invalid #cgo line: CXXFLAGS, pkg-config #4765

Open
mappu opened this issue Mar 1, 2025 · 2 comments
Open

cgo: invalid #cgo line: CXXFLAGS, pkg-config #4765

mappu opened this issue Mar 1, 2025 · 2 comments

Comments

@mappu
Copy link

mappu commented Mar 1, 2025

Hi! TinyGo is super interesting, thank you for all your work on this project.

I have a large CGO package that i'm interested to try with TinyGo, to reduce binary size and perform dead code elimination across Go/C/C++ boundaries. But, I hit some missing features so far.

$ cd miqt/examples/helloworld

$ tinygo build
# github.com/mappu/miqt/qt
../../qt/cflags.go:4:6: invalid #cgo line: CXXFLAGS
../../qt/cflags.go:6:6: invalid #cgo line: pkg-config

Go with CGO uses these directives:

  • Any .cpp files in the same package directory are compiled using the $(go env CXX) compiler, using these #cgo CXXFLAGS
  • #cgo pkg-config declares the .pc file to use with $(go env PKG_CONFIG) --cflags/--libs.
@aykevl
Copy link
Member

aykevl commented Mar 1, 2025

This is not something we currently support, since TinyGo statically links against its own libc (musl) while external libraries will most likely link against the system libc (often glibc). Linking against the wrong libc will cause all kinds of issues if it's even possible.

We would need to link to the system libc (probably) to support this. Which is something that I'd like to add support for at some point, but is a bit more work than just adding support for pkg-config.

CXXFLAGS on the other hand is something that we could definitely add support for, and wouldn't be terribly difficult.

@mappu
Copy link
Author

mappu commented Mar 1, 2025

Thank you for the update, i understand. There's no pressure on my side.

How does GOOS=windows work? Surely that targets the system libc, not musl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants