I have to preface that I am beginner when it comes to using Go. I have cloned a project that can be found at https://gitlab.com/gitlab-org/security-products/analyzers/common.git
Before building, the environment variables for go are GOARCH=amd64 GOOS=linux.
After cloning the project I navigate to into the directory that has go files, that is command/, and run the following command go build -o analyzer
This outputs a file called analyzer. The one I noticed is that I can't execute this file unless I do chmod +x analyzer.
When I do execute the that binary I get an error
./analyzer: line 1: syntax error near unexpected token `newline'
./analyzer: line 1: `!<arch>'
That package is not a main package. Only main packages (with the package main statement) will build into executable files.
Related
I want to run a program on my Macbook.
First I run it with go run main.go. It is compiled successfully but indicates permission denied when running.
So I switch to sudo go run main.go. but it fails in the compiling stage, showing compile: version "go1.17.8" does not match go tool version "go1.18".
then after some tries, I find this file named ~/Library/Application\ Support/go/env which sets the configuration GOROOT=~/sdk/go1.17.8.
I cannot figure out what leads to these.
I've been attempting to implement the Perl script found here: best way to add license section to iOS settings bundle
I've followed the instructions given to a T but when I go to run my project I get the following error after changing the permissions of the script to CHMOD 755:
No such file or directory at ./LicenseScript.pl line 10.
Command /bin/sh failed with exit code 2
Why won't my app compile?
I have a Linux VM where I am trying to compile a simple Go package. The package was retrieved into my user directory with git:
$ git clone [...]/test.go
Cloning into 'test.go'...
done.
$ cd test.go/
$ ls
main.go
I set up the GOPATH and build:
$ export GOPATH=$PWD; echo $GOPATH
/home/vagrant/test.go
$ go build
$ ls
main.go test.go*
So far so good. But now when I try to build again, it fails:
$ go build
can't load package: package .: read /home/vagrant/test.go/test.go: unexpected NUL in input
Deleting the test.go file before building will allow it to build. But this is inconvenient because tools like github.com/codegangsta/gin which try to rebuild the package will fail.
The repository was named [...]/test.go, and the default container directory for git clone is the repo name, so the containing directory is named test.go\.
From go help build:
If the package is main and file names are provided, the file name
derives from the first file name mentioned, such as f1 for 'go build
f1.go f2.go'; with no files provided ('go build'), the output file
name is the base name of the containing directory.
In this case the output is a file called test.go. The problem is:
In the directory containing the package, .go, .c, .h, and .s files are considered part of the package
During a go build if the output from a previous build, test.go, exists, it will be treated as a source file, triggering the 'unexpected NUL in input' message.
The problem can be resolved by renaming the directory to avoid the build output having a name that will be considered part of the package.
I am new to SO and a relatively new beginner to GO. I was building and running GO code smoothly on my local server until I had to use some of the packages from Gorilla toolkit.
What I ran in the command line:
mkdir $HOME/mygo
export GOPATH=$HOME/mygo
cd mygo
go get github.com/gorilla/mux
I did this based on the example from here: http://golang.org/doc/articles/go_command.html. Under gettng started with the Go Command and here http://www.gorillatoolkit.org/.
After this, I imported my main.go code into the mygo folder. My directory folder looks like this:
Workspace
pkg
src
main.go
However, when I ran go build main.go, and tried to run ./main, I got
-bash: ./main.go: Permission denied
What is happening?? Please help. Thanks!
First I highly recommend reading http://linuxcommand.org/learning_the_shell.php, then going through the Go tour.
Second, like #JimB mentioned, you can't execute main.go directly like that (you can use binfmt_misc but I'm not gonna explain that here).
So the steps to run your executable are:
go build -o main
./main
Or directly:
go run main.go
I have added a new target with external build in xCode 4.3.2 which is suposed to run a shell script. The script is in a folder Scripts/update.sh in the project.
My external build tool configuration are:
Build Tool /bin/bash
Arguments ../Scripts/update.sh
But when i run i get:
/bin/bash: ../Scripts/update.sh: No such file or directory
How do i refer the file correct?
According to Apple's Documentation, it looks like you probably want refer to update.sh as:
${SRCROOT}/Scripts/update.sh