In the document of cgo, it says:
If the import of “C” is immediately preceded by a comment, that comment, called the preamble, is used as a header when compiling the C parts of the package.
For example, the following is correct:
// #cgo linux CFLAGS: -I/opt/jdk/include -I/opt/jdk/include/linux // #cgo linux LDFLAGS: -Llib -lhdfs -L/opt/jdk/jre/lib/amd64/server -ljvm // #cgo darwin CFLAGS: -I/usr/local/hdfs/include // #cgo darwin LDFLAGS: -L/usr/local/hdfs/lib -lhdfs -framework JavaVM // #include "hdfs.h" import "C"
But I inserted an empty line before #include "hdfs.h" in mistake, then all cgo directives (CFLAGS and LDFLAGS) disappeared from the command line invoking gcc, and on Mac OS X I got an error message “Undefined symbols for architecture x86_64:”, which led me to check whether I had built libhdfs correctly into x86_64 with my newly upgraded Mountain Lion and Xcode 4.5. This stupid checking cost me an hour!
A side effect is that I found go build -a -x is useful as it prints commands when building.
Hey, dear Go community, could you please change the rule to
all comments before the line #import "C" count as the preamble.