blog
Table des matières
- 2026:
- 2025:
12 billet(s) pour novembre 2026
| Notes conversion JSON YAML | 2026/11/13 11:16 | Jean-Baptiste |
| Git commit perdu | 2026/11/12 18:16 | Jean-Baptiste |
| Notes mojo lang | 2026/11/11 20:34 | Jean-Baptiste |
| Notes rust lang compilation | 2026/11/11 18:35 | Jean-Baptiste |
| Mémoire VSIZE VMSIZE SEGV lang C | 2026/11/11 15:59 | Jean-Baptiste |
| Ansible-navigator utilisation de ansible-vault | 2026/11/06 11:33 | Jean-Baptiste |
| Err Ansible - Module result deserialization failed No start of json char found | 2026/11/06 09:09 | Jean-Baptiste |
| Script Python conversion JSON vers CSV | 2026/11/06 08:14 | Jean-Baptiste |
| Filter Incoming IPv4 Packets Containing IP Options - cve-2026-98432 mitigation - Kernel TCP Use-After-Free | 2026/11/04 21:04 | Jean-Baptiste |
| Notes ZFS | 2026/11/03 18:04 | Jean-Baptiste |
| Diff image container | 2026/11/03 16:30 | Jean-Baptiste |
| Notes processus multi-thread | 2026/11/03 10:59 | Jean-Baptiste |
Err Go lang et langage C
Voir aussi :
Err: could not determine what C.factorial refers to
# command-line-arguments ./maint.go:25:43: could not determine what C.factorial refers to
Solution
Remplacer
package main // #include <stdio.h> // #include <stdlib.h> // // 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; // } // // return fact; // } import "C"
Par
package main // #include <stdio.h> // #include <stdlib.h> // // 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; // } // // return fact; // } import "C"
Il ne faut pas d'espace entre le bloque du code C et import "C"
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()
package main // #include <stdio.h> // #include <stdlib.h> // // 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; // } // // return fact; // } import "C" import "fmt" func main() { for i := range 10 { //fmt.Printf("i: %.3d;, fact: %.6d\n", i, C.factorial(i)) fmt.Printf("i: %.3d;, fact: %.6d\n", i, C.factorial(C.uint(i))) 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/cgo gcc: error: unrecognized command-line option ‘-mthreads’; did you mean ‘-pthread’? # runtime/cgo gcc: error: unrecognized command-line option ‘-mthreads’; did you mean ‘-pthread’?
Installer les deps pour compiler
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
./main.go:22:43: could not determine what C.factorial refers to
cgo:
x86_64-w64-mingw32-gcc errors for preamble:
./main.go:6:2: error: unknown type name 'uint'; did you mean 'int'?
6 | // uint factorial(uint N) {
| ^~~~
| int
./main.go:6:17: error: unknown type name 'uint'; did you mean 'int'?
6 | // uint factorial(uint N) {
| ^~~~
| int
Remplacer les unsigned int (uint) par des int
sed -i.bak -e 's/uint/int/g' main.go 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
Notes fichiers so linux - compiled library file - shared object file
Voir :
Lister toutes les fonctions
readelf -W -s /usr/lib/7zip/7z.so nm -D /usr/lib/7zip/7z.so
Notes windows EXE DLL
Voir :
cygwin1.dll
Go lang
Voir aussi (Linux) :
Voir les fonctions présentes dans le DLL
readpe -e msvbvm60.dll
winedump -j export msvbvm60.dll
Voir les DLL liées
i686-w64-mingw32-objdump -p win-cgo-test.exe | grep "DLL Name:"
DLL Name: ws2_32.dll
DLL Name: advapi32.dll
DLL Name: ntdll.dll
DLL Name: kernel32.dll
DLL Name: winmm.dll
DLL Name: msvcrt.dll
Appeler une fonction dans une DLL
Avec Go
En ligne de commande
Voir :
wine rundll32.exe user32.dll,MessageBoxW env LANG="fr_FR.UTF-8" wine rundll32.exe user32.dll,MessageBoxA "Titre de la fenêtre"
Inclure ASM dans Go lang
Voir :
Inclure du C dans Go lang
Voir :
Voir aussi :
Inversement - Inclure du Go dans du C :
package main // #include <stdio.h> // #include <stdlib.h> // // static void myprint(char* s) { // printf("%s\n", s); // } import "C" import "unsafe" func main() { cs := C.CString("Hello from stdio") C.myprint(cs) C.free(unsafe.Pointer(cs)) }
Source : https://pkg.go.dev/cmd/cgo
blog.txt · Dernière modification : de 127.0.0.1
