tech:err_go_lang_et_langage_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:err_go_lang_et_langage_c [2026/04/21 21:07] – créée Jean-Baptiste | tech:err_go_lang_et_langage_c [2026/04/21 21:37] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| # Err Go lang et langage C | # Err Go lang et langage C | ||
| + | Voir aussi : | ||
| + | * [[Inclure du C dans Go lang]] | ||
| ## Err: could not determine what C.factorial refers to | ## Err: could not determine what C.factorial refers to | ||
| Ligne 60: | Ligne 62: | ||
| - | FIXME | + | |
| + | ## Err: cannot use i (variable of type int) as _Ctype_uint value in argument to (_Cfunc_factorial) | ||
| + | |||
| + | ### Solution | ||
| + | |||
| + | Il faut caster. Ici dans notre exemple avec `C.uint()` | ||
| + | |||
| + | ~~~go | ||
| + | package main | ||
| + | |||
| + | // #include < | ||
| + | // #include < | ||
| + | // | ||
| + | // uint factorial(uint N) { | ||
| + | // int fact = 1, i; | ||
| + | // | ||
| + | // // Loop from 1 to N to get the factorial | ||
| + | // for (i = 1; i <= N; i++) { | ||
| + | // fact *= i; | ||
| + | // } | ||
| + | // | ||
| + | // | ||
| + | // } | ||
| + | import " | ||
| + | import " | ||
| + | |||
| + | func main() { | ||
| + | for i := range 10 { | ||
| + | // | ||
| + | fmt.Printf(" | ||
| + | i++ | ||
| + | } | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Err: go: no Go source files | ||
| + | |||
| + | Compilation croisée avec du code Go contenant du C | ||
| + | |||
| + | ~~~ | ||
| + | $ env GOOS=windows go build main.go | ||
| + | go: no Go source files | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Solution | ||
| + | |||
| + | ~~~ | ||
| + | $ env CGO_ENABLED=1 GOOS=windows go build main.go | ||
| + | # runtime/ | ||
| + | gcc: error: unrecognized command-line option ‘-mthreads’; | ||
| + | # runtime/ | ||
| + | gcc: error: unrecognized command-line option ‘-mthreads’; | ||
| + | ~~~ | ||
| + | |||
| + | Installer les deps pour compiler | ||
| + | ~~~bash | ||
| + | sudo apt-get install gcc-multilib gcc-mingw-w64 | ||
| + | ~~~ | ||
| + | |||
| + | Lancer la compilation | ||
| + | ~~~ | ||
| + | $ env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build main.go | ||
| + | # command-line-arguments | ||
| + | ./ | ||
| + | cgo: | ||
| + | x86_64-w64-mingw32-gcc errors for preamble: | ||
| + | ./ | ||
| + | 6 | // uint factorial(uint N) { | ||
| + | | ^~~~ | ||
| + | | int | ||
| + | ./ | ||
| + | 6 | // uint factorial(uint N) { | ||
| + | | | ||
| + | | int | ||
| + | ~~~ | ||
| + | |||
| + | Remplacer les unsigned int (uint) par des int | ||
| + | ~~~bash | ||
| + | sed -i.bak -e ' | ||
| + | env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build main.go | ||
| + | ~~~ | ||
| + | |||
| + | C'est tout de même problématique | ||
tech/err_go_lang_et_langage_c.1776798473.txt.gz · Dernière modification : de Jean-Baptiste
