Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to point to C header files in GO?

New to GoLang so go easy on me. I installed this package for which are GO bindings for the HDF5s filesystem:

go get github.com/sbinet/go-hdf5

and I get

fatal error: hdf5.h: No such file or directory
// #include "hdf5.h"

the file hdf5.h (which comes from the original hdfs library, not the go package) is located in

usr/include/hdf5s/series

how do I tell the go compiler to look in the /user/include/hdf5s/series directory for this header file?

like image 779
Brom Quinn Avatar asked Jul 14 '16 18:07

Brom Quinn


People also ask

Does Go use header files?

Go does not use header files. Instead, each source file is part of a defined package. When a package defines an object (type, constant, variable, function) with a name starting with an upper case letter, that object is visible to any other file which imports that package. Go does not support implicit type conversion.

Where can I find C header files?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.

What is the point of header files C?

The header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to find one copy will result in inconsistencies within a program. In C, the usual convention is to give header files names that end with . h .

How do I make a header file in C?

To make a header file, we have to create one file with a name, and extension should be (*. h). In that function there will be no main() function. In that file, we can put some variables, some functions etc.


1 Answers

Pass the -I flag to the C compiler using the CGO_CFLAGS environment variable (documentation):

CGO_CFLAGS="-I/usr/include/hdf5s/series" go get -u github.com/sbinet/go-hdf5
like image 73
Tim Cooper Avatar answered Oct 11 '22 05:10

Tim Cooper