Next: , Previous: , Up: Top   [Contents][Index]

2 Import and Export

When gccgo compiles a package which exports anything, the export information will be stored directly in the object file. When a package is imported, gccgo must be able to find the file.

When Go code imports the package gopackage, gccgo will look for the import data using the following filenames, using the first one that it finds.


The compiler will search for these files in the directories named by any -I options, in order in which the directories appear on the command line. The compiler will then search several standard system directories. Finally the compiler will search the current directory (to search the current directory earlier, use ‘-I.’).

The compiler will extract the export information directly from the compiled object file. The file gopackage.gox will typically contain nothing but export data. This can be generated from gopackage.o via

objcopy -j .go_export gopackage.o gopackage.gox

For example, it may be desirable to extract the export information from several different packages into their independent gopackage.gox files, and then to combine the different package object files together into a single shared library or archive.

At link time you must explicitly tell gccgo which files to link together into the executable, as is usual with gcc. This is different from the behavior of other Go compilers.