Giter Site home page Giter Site logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 23, 2024
I'm not quite sure what the right thing to do here is.  When there's a file in 
the top-level cmd folder, e.g. cmd1.go, the builder assumes that it's a 
stand-alone file that should be compiled into cmd1.exe.  If you create a 
sub-folder of cmd called "subf" and put the files in there, the builder will 
compile them together to make an executable called subf.exe.  This would solve 
the problem of referencing fromCmd1 and fromCmd2, but causes an error because 
of the redefinition of func main.

For reference executing 8g cmd1.go cmd2.go also results in an error: 
"cmd2.go:3: main redeclared in this block previous declaration at cmd1.go:3"

The other way to handle it, of course is to put fromCmd1 and fromCmd2 in 
packages under src/pkg.

Original comment by [email protected] on 3 Nov 2010 at 1:41

from goclipse.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 23, 2024
yes, you are right. I did not compile by hand the sample I gave you. Of course 
it would give an error about the redefinition of main. However I think it was 
my example that wrongly did this redefinition. The gocode has only one main 
function in the main package, as expected. 

so building with:

8g cmd1.go cmd2.go
8g cmd2.go cmd1.go
would generate .8 files for both cmd1 and cmd2

then the linker would be called only for the one that actually has main. They 
can still refer each other in other forms (through other functions)

Your suggestion is actually what I did to compile gocode. I moved all code from 
the main package to a new package in the pkg, then created a cmd that actually 
calls the main() function from gocode.go which is now well packed in it's 
package.
But this is not something we can ask of developers. If they decide to use 
multiple files at the main package level, I think they should be able to do it.

Original comment by [email protected] on 3 Nov 2010 at 2:05

from goclipse.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 23, 2024
Right, I had forgotten you were compiling gocode.  You can get it to work by 
putting all the top-level source files into a subfolder of cmd called "gocode". 
 Then put the "goconfig" files into src/pkg/configfile.  Then the only problem 
is the 'import cfg "./configfile"' in config.go.  If you change that to "import 
cfg "configfile"' it works fine.

So once again, it comes down to how to handle an import prefixed with "./"  Is 
the answer simply to look for local packages in the pkg folder?  If so, what is 
the best way to get the go toolchain to do that?

Original comment by [email protected] on 3 Nov 2010 at 7:36

from goclipse.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 23, 2024
I did not expect to have a folder in cmd. This works great :)

I think we do need to handle the ./ packages somehow. People seem to use it. I 
wonder how is usually handled in linux. Is the make build doing something to 
change the ./ notation to a global one? or the packaging works file with ./ ?

I've tried to find some docs about gopack but the only thing I found is a link 
to a different tool in Plan9 which has different sets of parameters now.

Original comment by [email protected] on 6 Nov 2010 at 6:52

from goclipse.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 23, 2024

Original comment by [email protected] on 10 Jun 2012 at 10:46

  • Changed state: Fixed

from goclipse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.