Function in same package undefined

前端 未结 9 2063
太阳男子
太阳男子 2020-12-28 12:17

My project structure is like this.

packagetest/
    main.go
    lib.go

In main.go, I have this code.

package m         


        
9条回答
  •  抹茶落季
    2020-12-28 12:45

    This is an old post but it didn't answer my issue clearly, so I'm posting for the benefit of others in the future.

    When run go run --help you will find this manual:

    Run compiles and runs the main package comprising the named Go source files. A Go source file is defined to be a file ending in a literal ".go" suffix.

    By default, 'go run' runs the compiled binary directly: 'a.out arguments...'.

    go run is used for small programs with just a few files. With several files you will run into an issue where your main.go cannot find other files because go run doesn't compile and link them implicitly unless named. That's why go build the project works.

    Alternatively, go run *.go (building all files) should work most of the time.

提交回复
热议问题