Initial Commit

This commit is contained in:
Aliberk Sandıkçı 2023-08-30 21:14:10 +03:00
commit 6ffed38462
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
6 changed files with 77 additions and 0 deletions

40
README.md Normal file
View file

@ -0,0 +1,40 @@
# Go Crosscompile
# Explanation
symbol() function in pkg/mypkg/symbol_linux.go and symbol_windows.go is different. When running and building program, GOOS choses right one. for more information run these in cmd/app/ directory:
```sh
go build .
./app
# Output:
#1+2=linux
#a/b/c
```
---
```sh
env GOOS=windows GOARCH=amd64 go build .
./app.exe
# Output:
# -Some random wine logs if running on linux with wine-
#1-2=windows
#a\b\c
```
---
```sh
file app*
# see information about executables
```
# HELP NEEDED
VSCode gives redecleration error when using same name as function names. How to solve this?
maybe see https://github.com/golang/go/issues/29202 ?
# Before trying
- make sure you have installed **wine** in your linux system
- or use a windows system too
# Resources
- https://www.digitalocean.com/community/tutorials/customizing-go-binaries-with-build-tags
- https://www.digitalocean.com/community/tutorials/building-go-applications-for-different-operating-systems-and-architectures
- https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-20-04
- https://opensource.com/article/21/1/go-cross-compiling

15
cmd/app/main.go Normal file
View file

@ -0,0 +1,15 @@
package main
import (
"fmt"
"path/filepath"
"git.aliberksandikci.com.tr/asandikci/go-crosscompile/pkg/mypkg"
)
func main() {
s := filepath.Join("a", "b", "c")
fmt.Println(mypkg.Symbol("1", "2"))
fmt.Println(s)
}

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module git.aliberksandikci.com.tr/asandikci/go-crosscompile
go 1.21.0

5
pkg/mypkg/main.go Normal file
View file

@ -0,0 +1,5 @@
package mypkg
func Symbol(a, b string) string {
return symbol(a, b)
}

View file

@ -0,0 +1,7 @@
// go:build linux
package mypkg
func symbol(a, b string) string {
return a + "+" + b + "=linux"
}

View file

@ -0,0 +1,7 @@
// go:build windows
package mypkg
func symbol(a, b string) string {
return a + "-" + b + "=windows"
}