Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save deefdragon/2336e2404c468c3c59f1ef670745a920 to your computer and use it in GitHub Desktop.

Select an option

Save deefdragon/2336e2404c468c3c59f1ef670745a920 to your computer and use it in GitHub Desktop.

Revisions

  1. deefdragon revised this gist Dec 15, 2023. 1 changed file with 1 addition and 1 deletion.
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    tldr: go build only produces an executable for main packages.
    tldr: go build only produces an executable for main packages. Check the package name of your main file is main.


    I am an idiot. Its only through mistakes that you learn tho. I have recently been running into issues with my new golang projects. ONLY the new ones. Whenever I try to make a new project, it would always have issues. The biggest issue is the fact that "go build" would not produce an executable without "-o main.exe" as arguments. When an executable was produced, if I ran it I got
  2. deefdragon revised this gist Dec 15, 2023. 1 changed file with 5 additions and 2 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,14 @@
    tldr: go build only produces an executable for main packages.


    I am an idiot. Its only through mistakes that you learn tho. I have recently been running into issues with my new golang projects. ONLY the new ones. Whenever I try to make a new project, it would always have issues. The biggest issue is the fact that "go build" would not produce an executable without "-o main.exe" as arguments. When an executable was produced, if I ran it I got
    ```
    $ ./main.exe
    ./main.exe: line 1: syntax error near unexpected token \`newline\'
    ./main.exe: line 1: \`!<arch>\'
    ```

    I thought that this was something wrong with my install. Possibly my environmental varaibles. The fact that it was only new projects should have directed me more to how the project was set up. Digging through those proved not to help. Eventually I poked arround the go irc, (far and away the best place to go for help), and finally someone (Thank you neebs) was able to catch what I was doing wrong.
    I thought that this was something wrong with my install. Possibly my environmental varaibles. The fact that it was only new projects should have directed me more to how the project was set up. Digging through said vairables proved not to help. Eventually I poked arround the go irc, (~~far and away the best place to go for help~~ I'd actually go to the golang discord nowadays, but thats personal preference), and finally someone (Thank you neebs) was able to catch what I was doing wrong.

    It had been so long since I last created a project, and I had only ever created one mod project from scratch, that I was confusing the errors that I got, and I kept trying to compile the following to an executable.

    @@ -17,7 +20,7 @@ func main(){
    }
    ```

    The issue at hand is the package name. go build only produces an executable for main packages. IE "package main" with a func main().
    The issue at hand is the package name. go build **only produces an executable for main packages**. IE "package main" with a func main().

    ```
    package main
  3. deefdragon revised this gist Oct 8, 2018. 1 changed file with 4 additions and 2 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    I am an idiot. Its only through mistakes that you learn tho. I have recently been running into issues with my new golang projects. ONLY the new ones. whenever I try to make a new project, it would always have issues. THe biggest issue is the fact that the go build command wuold not produce an executable without -o main.exe. When an executable was produced, if I ran it I got
    I am an idiot. Its only through mistakes that you learn tho. I have recently been running into issues with my new golang projects. ONLY the new ones. Whenever I try to make a new project, it would always have issues. The biggest issue is the fact that "go build" would not produce an executable without "-o main.exe" as arguments. When an executable was produced, if I ran it I got
    ```
    $ ./main.exe
    ./main.exe: line 1: syntax error near unexpected token \`newline\'
    ./main.exe: line 1: \`!<arch>\'
    ```

    I thought that this was something wrong with my install. Possibly my environmental varaibles. Digging through those proved not to help. I poked arround the go irc, (far and away the best place to go for help), and finally someone was able to catch what I was doing wrong.
    I thought that this was something wrong with my install. Possibly my environmental varaibles. The fact that it was only new projects should have directed me more to how the project was set up. Digging through those proved not to help. Eventually I poked arround the go irc, (far and away the best place to go for help), and finally someone (Thank you neebs) was able to catch what I was doing wrong.

    It had been so long since I last created a project, and I had only ever created one mod project from scratch, that I was confusing the errors that I got, and I kept trying to compile the following to an executable.

  4. deefdragon revised this gist Oct 8, 2018. 1 changed file with 2 additions and 2 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    I am an idiot. Its only through mistakes that you learn tho. I have recently been running into issues with my new golang projects. ONLY the new ones. whenever I try to make a new project, it would always have issues. THe biggest issue is the fact that the go build command wuold not produce an executable without -o main.exe. When an executable was produced, if I ran it I got
    $ ./main.exe
    ./main.exe: line 1: syntax error near unexpected token `newline'
    ./main.exe: line 1: `!<arch>'
    ./main.exe: line 1: syntax error near unexpected token \`newline\'
    ./main.exe: line 1: \`!<arch>\'

    I thought that this was something wrong with my install. Possibly my environmental varaibles. Digging through those proved not to help. I poked arround the go irc, (far and away the best place to go for help), and finally someone was able to catch what I was doing wrong.

  5. deefdragon created this gist Oct 8, 2018.
    28 changes: 28 additions & 0 deletions golang syntax error near unexpected token `newline' build error.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    I am an idiot. Its only through mistakes that you learn tho. I have recently been running into issues with my new golang projects. ONLY the new ones. whenever I try to make a new project, it would always have issues. THe biggest issue is the fact that the go build command wuold not produce an executable without -o main.exe. When an executable was produced, if I ran it I got
    $ ./main.exe
    ./main.exe: line 1: syntax error near unexpected token `newline'
    ./main.exe: line 1: `!<arch>'

    I thought that this was something wrong with my install. Possibly my environmental varaibles. Digging through those proved not to help. I poked arround the go irc, (far and away the best place to go for help), and finally someone was able to catch what I was doing wrong.

    It had been so long since I last created a project, and I had only ever created one mod project from scratch, that I was confusing the errors that I got, and I kept trying to compile the following to an executable.

    ```
    package lab5
    import "fmt"
    func main(){
    fmt.Println("Hello World")
    }
    ```

    The issue at hand is the package name. go build only produces an executable for main packages. IE "package main" with a func main().

    ```
    package main
    import "fmt"
    func main(){
    fmt.Println("Hello World")
    }
    ```

    Not a mistake I will make again I think.