Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go file not running which is not in main package

I have a very simple Go project setup. At root directory I have go.mod file and main.go and a folder called main2. Inside main2 folder there is main2.go file.

/
|_ go.mod
|_ main.go
|_ main2
   |_ main2.go

From root directory I am trying to run go run command

go run main2/main2.go

and it throws error:

package command-line-arguments is not a main package

Can someone help?

like image 787
mohit singla Avatar asked Dec 03 '25 16:12

mohit singla


1 Answers

The package of your main2.go file must be main. When there is a main package, and a function main in your project, the compiler knows it will be compiled as a executable, and not as a library.

So try to change package command-line-arguments to package main inside the main2/main2.go file.

like image 152
Alex Lucchesi Avatar answered Dec 06 '25 13:12

Alex Lucchesi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!