I know how to run a file in go using go run file.go, but I want to compile it to an executable.
When I looked up, I found about 6g and 6l and it seems like they are outdated.
I want something like:
go-compiler -o output file.go
You want:
go build -o executable source.go
Related
I have some Go source files: one.go, two.go,main.go
I build them to C static library for using in my cross-platform application compilation.
There are 4 types of application compilation:
Compilation on Windows
Compilation on Ubuntu
Compilation on Mac
Cross-compilation for Windows from Ubuntu
For 1,2,3 I use:
go build -buildmode c-archive -o libxyz.a .
For 4, I use:
GOOS="windows" GOARCH="amd64" CGO_ENABLED="1" CXX="x86_64-w64-mingw32-g++" CC="x86_64-w64-mingw32-gcc" go build -buildmode c-archive -o libxyz.a .
Is it somehow possible to do that by the configure-make-make install procedure?
(There is no configure.ac file in the xyz Go source package)
Also, it possible to use pkg-config in that?
Is it somehow possible to do that by the configure-make-make install procedure [?]
Yes.
Should you do it, is this easy, is this sensible, does this provide any benefit? No, no, no, no.
If you want to type less: Write a small shell script (or a tiny Makefile if you insist on using make for whatever reason).
I'm trying to run a memory error detector (like Valgrind's Memcheck or Drmemory) on the ADB software. However, I'm having trouble figuring it how to build/compile the source code. I'm using linux (ubuntu).
https://github.com/aosp-mirror/platform_system_core/tree/master/adb
Do I need a makefile? Or is there something wrong with my understanding on how to go about doing this? Maybe there's a way that I can use Memcheck/Dr. Memory on the actual program when it's run in Android Studio? I don't believe there are any instructions, or a makefile in the source code.
I've tried compiling the main.cpp file in the client folder with g++, but it says it doesn't have access to the sysdep.h file.
Compiled using:
$ cd client
$ g++ -std=c++11 main.cpp -o main
Error message:
fatal error: sysdep.h: No such file or directory
Take a look at this documentation for the AOSP ADB tool:
https://source.android.com/setup/build/adb#building_adb_build-adb
From my understanding you need to download the AOSP source code then run the following commands:
source ~/aosp/build/envsetup.sh
cd ~/aosp/system/core/adb
mm # <- That's not a typo
This command should take a while (especially on the first run) but you should get a compiled adb executable in the ~/aosp/out folder somewhere (I can't verify on this computer as it doesn't have enough ram to complete a build...)
Also to show the help menu, type:
hmm
I want to build exe file on windows,
without need of vcruntime.
So I tried:
.cargo/config
[target.i686-pc-windows-msvc]
rustflags = ["-Clink-args=/MT"]
looks like cargo found config, because of cargo rebuild
whole project, but dumpbin /DEPENDENTS test.exe
still show VCRUNTIME140.dll as dependencies,
any ideas how link VCRUNTIME140 statically?
See this rfc
You can try it with rustc nightly:
c:\Users\IEUser\test2>rustc -Z unstable-options -C target-feature=+crt-static test.rs
user1034749 answer pertains to rustc. If you want to do this with cargo, the info is here: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc
I'm using go 1.5 and I'm cross compiling like specified here.
The problem is that when compiling the project it will override the binary the last compilation created. Moreover - I will never know which OS/ARCH the executable file that I'm running was compiled to (in any case that is not windows).
Is there a way to rename the file at compile command?
You could use the "-o" argument, like this:
GOOS=linux GOARCH=386 CGO_ENABLED=0 go build -o test/output/myapp
From the page you linked to:
-o may be used to alter the name and destination of your binary, but remember that go build takes a value that is relative to your $GOPATH/src, not your working directory, so changing directories then executing the go build command is also an option.
If you use GOOS and GOARCH in the name, you should be able to achieve what you want.
I'm trying to do a go install and rename the output with the -o flag.
go install -o bar.exe src/foo.go
But this fails with the error:
flag provided but not defined: -o
usage: install [build flags] [packages]
go help build shows -o as the correct build flag to rename the output binary. There is no mention that this flag is not defined for go install.
go run -o bar.exe src/foo.go fails with the same error.
go build -o bar.exe src/foo.go works. I get bar.exe.
So is this just an error of documentation, or have I missed something?
My version: go1.5 windows/386.
Thanks.
go build accepts the -o flag but go install does not.
go install will always output to $GOPATH/bin
If you want to install a custom binary name to your gopath you can do go build -o $GOPATH/bin/whatever and that will be roughly equivalent to go install
You can fake the -o flag, if all you care about is the location, and not the name of the binary. Define GOBIN for the install command:
GOBIN=`readlink -f my/location` go install some/persons/go-package
Caveat: This doesn't work for cross-compiled binaries.