mirror of
https://github.com/golang/go
synced 2024-11-25 00:07:56 -07:00
tutorial: show how to compile helloworld3, which depends on ./file
make shell prompts consistent R=rsc CC=golang-dev https://golang.org/cl/1824042
This commit is contained in:
parent
47b835e4a8
commit
708d7160fa
@ -650,20 +650,22 @@ We can now use our new package:
|
|||||||
21 }
|
21 }
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
The ''<code>./</code>'' in the import of ''<code>./file</code>'' tells the
|
The ''<code>./</code>'' in the import of ''<code>./file</code>'' tells the compiler
|
||||||
compiler to use the ''<code>file</code>'' package in the current directory
|
to use our own package rather than
|
||||||
rather than something from the directory of installed packages.
|
something from the directory of installed packages.
|
||||||
</p>
|
(Also, ''<code>file.go</code>'' must be compiled before we can import the
|
||||||
|
package.)
|
||||||
<p>
|
<p>
|
||||||
You must compile ''<code>file.go</code>'' before any package that imports it.
|
Now we can compile and run the program:
|
||||||
<p>
|
|
||||||
Finally we can run the program:
|
|
||||||
<p>
|
<p>
|
||||||
<pre>
|
<pre>
|
||||||
% helloworld3
|
$ 6g file.go # compile file package
|
||||||
|
$ 6g helloworld3.go # compile main package
|
||||||
|
$ 6l -o helloworld3 helloworld3.6 # link - no need to mention "file"
|
||||||
|
$ helloworld3
|
||||||
hello, world
|
hello, world
|
||||||
can't open file; err=No such file or directory
|
can't open file; err=No such file or directory
|
||||||
%
|
$
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
<h2>Rotting cats</h2>
|
<h2>Rotting cats</h2>
|
||||||
@ -827,11 +829,11 @@ even though under the covers it holds a pointer to a <code>struct</code>.
|
|||||||
Here it is in action:
|
Here it is in action:
|
||||||
<p>
|
<p>
|
||||||
<pre>
|
<pre>
|
||||||
% echo abcdefghijklmnopqrstuvwxyz | ./cat
|
$ echo abcdefghijklmnopqrstuvwxyz | ./cat
|
||||||
abcdefghijklmnopqrstuvwxyz
|
abcdefghijklmnopqrstuvwxyz
|
||||||
% echo abcdefghijklmnopqrstuvwxyz | ./cat --rot13
|
$ echo abcdefghijklmnopqrstuvwxyz | ./cat --rot13
|
||||||
nopqrstuvwxyzabcdefghijklm
|
nopqrstuvwxyzabcdefghijklm
|
||||||
%
|
$
|
||||||
</pre>
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
Fans of dependency injection may take cheer from how easily interfaces
|
Fans of dependency injection may take cheer from how easily interfaces
|
||||||
|
@ -471,15 +471,21 @@ We can now use our new package:
|
|||||||
|
|
||||||
--PROG progs/helloworld3.go /package/ END
|
--PROG progs/helloworld3.go /package/ END
|
||||||
|
|
||||||
The ''"./"'' in the import of ''"./file"'' tells the compiler to use our own package rather than
|
The ''"./"'' in the import of ''"./file"'' tells the compiler
|
||||||
|
to use our own package rather than
|
||||||
something from the directory of installed packages.
|
something from the directory of installed packages.
|
||||||
|
(Also, ''"file.go"'' must be compiled before we can import the
|
||||||
|
package.)
|
||||||
|
|
||||||
Finally we can run the program:
|
Now we can compile and run the program:
|
||||||
|
|
||||||
% helloworld3
|
$ 6g file.go # compile file package
|
||||||
|
$ 6g helloworld3.go # compile main package
|
||||||
|
$ 6l -o helloworld3 helloworld3.6 # link - no need to mention "file"
|
||||||
|
$ helloworld3
|
||||||
hello, world
|
hello, world
|
||||||
can't open file; err=No such file or directory
|
can't open file; err=No such file or directory
|
||||||
%
|
$
|
||||||
|
|
||||||
Rotting cats
|
Rotting cats
|
||||||
----
|
----
|
||||||
@ -549,11 +555,11 @@ even though under the covers it holds a pointer to a "struct".
|
|||||||
Here it is in action:
|
Here it is in action:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
% echo abcdefghijklmnopqrstuvwxyz | ./cat
|
$ echo abcdefghijklmnopqrstuvwxyz | ./cat
|
||||||
abcdefghijklmnopqrstuvwxyz
|
abcdefghijklmnopqrstuvwxyz
|
||||||
% echo abcdefghijklmnopqrstuvwxyz | ./cat --rot13
|
$ echo abcdefghijklmnopqrstuvwxyz | ./cat --rot13
|
||||||
nopqrstuvwxyzabcdefghijklm
|
nopqrstuvwxyzabcdefghijklm
|
||||||
%
|
$
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Fans of dependency injection may take cheer from how easily interfaces
|
Fans of dependency injection may take cheer from how easily interfaces
|
||||||
|
Loading…
Reference in New Issue
Block a user