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

compile failed with undefined: C._Bool #3926

Closed
Patrick0308 opened this issue Sep 22, 2023 · 7 comments
Closed

compile failed with undefined: C._Bool #3926

Patrick0308 opened this issue Sep 22, 2023 · 7 comments

Comments

@Patrick0308
Copy link

Patrick0308 commented Sep 22, 2023

Environment:

tinygo version: 0.30.0
operating System: macOS
architecture: aarch64

Description:

Compilation brakes with an undefined C._Bool

Steps to reproduce:

Given the following Go-code:

package main

/*
  #include "stdbool.h"
  bool test() {
     return true;
  }
*/
import "C"

import "fmt"

func main() {
	fmt.Printf("%s", C._Bool(C.test()))
}

Run

tinygo run main.go

Expected behavior:

❯ tinygo run main.go
%!s(main._Ctype__Bool=true)%    

Actual behavior:

❯ tinygo run main.go
# command-line-arguments
main.go:14:19: undefined: C._Bool
@aykevl
Copy link
Member

aykevl commented Sep 22, 2023

Well this led me down a rather deep rabbit hole to improve CGo compatibility: #3927

I'll look at the actual bug next.

aykevl added a commit that referenced this issue Sep 22, 2023
This fixes #3926.

While working on this I've found another bug: if C.bool is referenced
from within Go, it isn't available anymore on the C side. This is an
existing bug that also applies to float and double, but may be less
likely to be triggered there.
This bug is something to be fixed at a later time (it has something to
do with preprocessor defines).
@aykevl
Copy link
Member

aykevl commented Sep 22, 2023

Here is a fix: #3928

@Patrick0308
Copy link
Author

#3928 is merged

@deadprogram
Copy link
Member

Reopening and tagging to close on next release.

@deadprogram deadprogram reopened this Oct 4, 2023
@deadprogram deadprogram added the next-release Will be part of next release label Oct 4, 2023
@Patrick0308
Copy link
Author

I build dev branch on my own computer. I tested

package main

/*
  #include "stdbool.h"
  bool test() {
     return true;
  }
*/
import "C"

import "fmt"

func main() {
	fmt.Printf("%s", C._Bool(C.test()))
}

It's ok.

However I tested fermyon/spin#1794 example but building painc.
The error log is

Building component tinygo-mysql with `/Users/patrick/projects/tinygo/build/tinygo build -target=wasi -gc=leaking -o main.wasm main.go`
# github.com/fermyon/spin/sdk/go/mysql
../../../tinygo/llvm-project/clang/lib/Headers/stdbool.h:20:14: undefined: C._Bool
Error: Build command for component tinygo-mysql failed with status Exited(1)

Is it another issue?

@Patrick0308
Copy link
Author

@aykevl Any idea?

crypto-smoke pushed a commit to meshnet-gophers/tinygo that referenced this issue Feb 14, 2024
This fixes tinygo-org#3926.

While working on this I've found another bug: if C.bool is referenced
from within Go, it isn't available anymore on the C side. This is an
existing bug that also applies to float and double, but may be less
likely to be triggered there.
This bug is something to be fixed at a later time (it has something to
do with preprocessor defines).
@aykevl
Copy link
Member

aykevl commented Feb 19, 2024

@Patrick0308 my guess is that they're shipping their own TinyGo variant, that is still the latest release (and not the dev branch).

@deadprogram deadprogram removed the next-release Will be part of next release label Feb 28, 2024
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

3 participants