How can I pass -ldflags="-w" to cmd.exec

I’m trying to call a command line for building go app using flag -ldflags="-w", but trting to do so using go file as:

//go:build tag_build
// +build tag_build

package main

import (
	"fmt"
	"os"
	"os/exec"
)

type platform struct {
	arch     string
	compiler string
}

type system struct {
	name string
	platform
}

func main() {
	var package_name = "goApp"
	var pwd = "D:/goEverywhere/go"
	var androidSDK = "C:/Users/hasan_yousef/AppData/Local/Android/Sdk"
	var ndk = androidSDK + "/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin"

        os.Setenv("GOOS", "android")
	os.Setenv("CGO_ENABLED", "1")

	// check existing archs as: $ go tool dist list

	android := []system{
		system{
			name: "android-armv7a",
			platform: platform{
				arch:     "arm",
				compiler: "armv7a-linux-androideabi33-clang",
			},
		},
		system{
			name: "android-arm64",
			platform: platform{
				arch:     "arm64",
				compiler: "aarch64-linux-android33-clang",
			},
		},
		system{
			name: "android-x86",
			platform: platform{
				arch:     "386",
				compiler: "i686-linux-android33-clang",
			},
		},
		system{
			name: "android-x86_64",
			platform: platform{
				arch:     "amd64",
				compiler: "x86_64-linux-android33-clang",
			},
		},
	}

	for _, s := range android {
		switch s.name {
		case "android-armv7a":
			os.Setenv("GOARM", "7")
		default:
			os.Setenv("GOARM", "")
		}
		os.Setenv("GOARCH", s.platform.arch)
		os.Setenv("CC", ndk+"/"+s.platform.compiler)
		args := []string{"build", "-ldflags=\"-w\"",
			"-buildmode=c-shared", "-o",
			pwd + "/" + s.name + "/lib" + package_name +".so", package_name}

        // or
		//	cmd := exec.Command(fmt.Sprintf("go build -ldflags=\"-w\" -buildmode=c-shared -o %s/%s/lib%s.so %s", pwd, s.name, package_nmae, package_nmae))
		//cmd := exec.Command("go", "build", `-ldflags="-w"`, "-buildmode=c-shared", "-o", pwd+"/"+s.name+"/libfoo.so", package_nmae)

		cmd := exec.Command("go", args...)
		out, err := cmd.CombinedOutput()
		if err != nil {
			fmt.Printf("cmd.Run() failed with %v:\n\noutput:\n\n%s\n", err, out)
		}
	}
}

While compiling I got the below error:

PS D:\goEverywhere\go> go run android_build.go
cmd.Run() failed with exit status 2:

output:

invalid value "\"-w\"" for flag -ldflags: missing =<value> in <pattern>=<value>
usage: go build [-o output] [build flags] [packages]
Run 'go help build' for details.

I found that The quotes are for your shell, and must not be part of the argument. I removed them and the code is working fine now as:

//go:build tag_build
// +build tag_build

package main

import (
	"fmt"
	"os"
	"os/exec"
)

type platform struct {
	arch     string
	compiler string
}

type system struct {
	name string
	platform
}

func main() {
	var package_name = "goApp"
	var pwd = "D:/goEverywhere/go"
	var androidSDK = "C:/Users/hasan_yousef/AppData/Local/Android/Sdk"
	var ndk = androidSDK + "/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/bin"
	os.Setenv("GOOS", "android")
	os.Setenv("CGO_ENABLED", "1")
	// go tool dist list
	android := []system{
		system{
			name: "android-armv7a",
			platform: platform{
				arch:     "arm",
				compiler: "armv7a-linux-androideabi33-clang",
			},
		},
		system{
			name: "android-arm64",
			platform: platform{
				arch:     "arm64",
				compiler: "aarch64-linux-android33-clang",
			},
		},
		system{
			name: "android-x86",
			platform: platform{
				arch:     "386",
				compiler: "i686-linux-android33-clang",
			},
		},
		system{
			name: "android-x86_64",
			platform: platform{
				arch:     "amd64",
				compiler: "x86_64-linux-android33-clang",
			},
		},
	}

	for _, s := range android {
		switch s.name {
		case "android-armv7a":
			os.Setenv("GOARM", "7")
		default:
			os.Setenv("GOARM", "")
		}
		os.Setenv("GOARCH", s.platform.arch)
		os.Setenv("CC", ndk+"/"+s.platform.compiler)
		//	args := []string{"build", "-ldflags=-w",
		//		"-buildmode=c-shared", "-o",
		//		pwd + "/" + s.name + "/lib" + package_name + ".so", package_name}

		cmd := exec.Command("go", "build", "-ldflags=-w", "-buildmode=c-shared", "-o", pwd+"/"+s.name+"/lib"+package_name+".so", package_name)
		//	cmd := exec.Command("go", args...)
		out, err := cmd.CombinedOutput()
		if err != nil {
			fmt.Printf("cmd.Run() failed with %v:\n\noutput:\n\n%s\n", err, out)
		}
	}
}