Unable to include OpenGL headers in a cc_library on Mac OS X
I am trying to include <OpenGL/OpenGL.h> in a sample cc_library on Mac OS X (10.10.3) but when doing so I am getting missing dependency declarations for OpenGL headers.
Build rule:
cc_library(
name = "hello-lib",
srcs = ["hello-lib.cc"],
hdrs = ["hello-lib.h",],
linkopts = ["-framework OpenGL"],
)
Program:
#ifndef EXAMPLES_CPP_HELLO_LIB_H_
#define EXAMPLES_CPP_HELLO_LIB_H_
#include <string>
#include <memory>
#include <OpenGL/gl.h>
namespace hello {
class HelloLib {
public:
HelloLib();
explicit HelloLib(const std::string &greeting);
void greet(const std::string &thing);
private:
std::unique_ptr<const std::string> greeting_;
};
} // namespace hello
#endif // EXAMPLES_CPP_HELLO_LIB_H_
Bazel output:
bazel build hello-lib
INFO: Found 1 target...
ERROR: /Users/trevorgray/src/github.com/google/bazel/examples/cpp/BUILD:3:1: undeclared inclusion(s) in rule '//examples/cpp:hello-lib':
this rule is missing dependency declarations for the following files included by 'examples/cpp/hello-lib.cc':
'/System/Library/Frameworks/OpenGL.framework/Headers/gl.h'
'/System/Library/Frameworks/OpenGL.framework/Headers/gltypes.h'
'/System/Library/Frameworks/OpenGL.framework/Headers/glext.h'.
Target //examples/cpp:hello-lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.512s, Critical Path: 0.42s
@Aragos - maybe we should add /System/Library/Frameworks into the darwin CROSSTOOL entry?
@hanwen: That sounds fine to me but I honestly have no knowledge of c++ compilation on Macs so I'm probably the wrong person to ask. :)
@trevorgray - there is a list of accepted include dirs here:
https://github.com/google/bazel/blob/master/tools/cpp/CROSSTOOL#L78
you could try adding an entry for /System/Library/Frameworks/
We're still discussing how to best pull in dependencies from the local machine; keep in mind that you also need to distinguish between different platforms, and possible different locations on identical platforms (for example: you may have a custom compiled libz on your machine which you want to use, where the headers are in /opt/usr/include, rather than in /usr/include).
For now, changing your CROSSTOOL is the easiest workaround, but keep in mind that bazel will not trigger on changes to those files; it assumes that files are immutable.
Trevor, can you try the suggestion and report back? Thanks!
The proposed fix of adding "/System/Library/Frameworks" to CROSSTOOL works.
Thanks, we'll update the CROSSTOOL then.