Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter 1 chat undefined: newRoom #69

Open
dprigh opened this issue Jan 3, 2020 · 4 comments
Open

chapter 1 chat undefined: newRoom #69

dprigh opened this issue Jan 3, 2020 · 4 comments

Comments

@dprigh
Copy link

dprigh commented Jan 3, 2020

$ go run main.go
$ go build main.go
command-line-arguments
./main.go: undefined: newRoom

$ go run room.go
$ go build room.go
command-line-arguments
./room.go: undefined: client

$ go run client.go
$ go build client.go
command-line-arguments
./client.go: undefined: room

$ go build -o chat
$ ./chat
chat can't run.

why? 'chat' file is not extension.
because add extension 'exe'
$ go build -o chat.exe
./chat.exe
Good run.

please saying.
What's wrong?

@hongliu9527
Copy link

$ go run main.go
$ go build main.go
command-line-arguments
./main.go: undefined: newRoom

$ go run room.go
$ go build room.go
command-line-arguments
./room.go: undefined: client

$ go run client.go
$ go build client.go
command-line-arguments
./client.go: undefined: room

$ go build -o chat
$ ./chat
chat can't run.

why? 'chat' file is not extension.
because add extension 'exe'
$ go build -o chat.exe
./chat.exe
Good run.

please saying.
What's wrong?

you can build the chat.exe like this go build -o chat.exe main.go client.go room.go。

@dprigh
Copy link
Author

dprigh commented Jan 17, 2020

you can build the chat.exe like this go build -o chat.exe main.go client.go room.go。

thank you!

@ZylleDK
Copy link

ZylleDK commented Jan 18, 2020

I had this problem too ...

You need to make sure your .go files are located inside a dirrectory, that is located inside the /src folder off your $GOPATH.

When calling go build, the golang only searches the src folder of your $GOPATH for files to include ... so that will fix your issue!

ex:
$GOPATH/src/chat/main.go

@ZylleDK
Copy link

ZylleDK commented Jan 18, 2020

Also .. you only need to call "go build" in the folder with all your files ...
this will create and executable the the same name as the folder your working in (chat, if you did like the book)

then you can call "go run chat"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants