bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Unable to include OpenGL headers in a cc_library on Mac OS X

Open trevorgray opened this issue 11 years ago • 7 comments

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

trevorgray avatar Mar 30 '15 20:03 trevorgray

@Aragos - maybe we should add /System/Library/Frameworks into the darwin CROSSTOOL entry?

hanwen avatar Apr 02 '15 05:04 hanwen

@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. :)

aragos avatar Apr 02 '15 17:04 aragos

@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/

hanwen avatar Apr 06 '15 19:04 hanwen

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.

ulfjack avatar Apr 07 '15 12:04 ulfjack

Trevor, can you try the suggestion and report back? Thanks!

hanwen avatar Apr 09 '15 17:04 hanwen

The proposed fix of adding "/System/Library/Frameworks" to CROSSTOOL works.

trevorgray avatar Apr 14 '15 18:04 trevorgray

Thanks, we'll update the CROSSTOOL then.

hanwen avatar Apr 15 '15 09:04 hanwen