diff --git a/linker-builtin.go b/linker-builtin.go index ba63f827..c8987938 100644 --- a/linker-builtin.go +++ b/linker-builtin.go @@ -22,7 +22,7 @@ import "C" // Link invokes a linker with the given name and flags. // // This version uses the built-in linker when trying to use lld. -func Link(dir, linker string, flags ...string) error { +func Link(linker string, flags ...string) error { switch linker { case "ld.lld", commands["ld.lld"]: flags = append([]string{"tinygo:" + linker}, flags...) @@ -60,7 +60,6 @@ func Link(dir, linker string, flags ...string) error { cmd := exec.Command(linker, flags...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Dir = dir return cmd.Run() } } diff --git a/linker-external.go b/linker-external.go index d0c8126a..446b6808 100644 --- a/linker-external.go +++ b/linker-external.go @@ -13,10 +13,9 @@ import ( // Link invokes a linker with the given name and arguments. // // This version always runs the linker as an external command. -func Link(dir, linker string, flags ...string) error { +func Link(linker string, flags ...string) error { cmd := exec.Command(linker, flags...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Dir = dir return cmd.Run() } diff --git a/main.go b/main.go index 1ac46f4d..28cf34f3 100644 --- a/main.go +++ b/main.go @@ -191,7 +191,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act // Prepare link command. executable := filepath.Join(dir, "main") tmppath := executable // final file - ldflags := append(spec.LDFlags, "-o", executable, objfile) + ldflags := append(spec.LDFlags, "-o", executable, objfile, "-L", sourceDir()) if spec.RTLib == "compiler-rt" { ldflags = append(ldflags, librt) } @@ -229,9 +229,9 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act // Link the object files together. if linker, ok := commands[spec.Linker]; ok { - err = Link(sourceDir(), linker, ldflags...) + err = Link(linker, ldflags...) } else { - err = Link(sourceDir(), spec.Linker, ldflags...) + err = Link(spec.Linker, ldflags...) } if err != nil { return &commandError{"failed to link", executable, err}