Issue 1:
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04

Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:

TensorFlow installed from (source or binary): source

TensorFlow version (use command below): 42c4f4ab6b53bce8639c203d7839d27eac11bd2f

Python version: 3.7

Bazel version (if compiling from source): 0.21.0

GCC/Compiler version (if compiling from source): 5.4.0-6ubuntu1~16.04.10

CUDA/cuDNN version: 9.0 / 7

GPU model and memory: 8x GTX 1080 Ti 12GB

You can collect some of this information using our environment capture script

You can also obtain the TensorFlow version with

python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the current behavior

In file included from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/platform/logging.h:25:0,
from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/lib/core/refcount.h:22,
from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/platform/tensor_coding.h:21,
from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/framework/resource_handle.h:19,
from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/framework/allocator.h:24,
from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/framework/tensor.h:22,
from /tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/public/session.h:24,
from bug.cc:2:
/tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include/tensorflow/core/platform/default/logging.h:95:0: warning: "LOG" redefined
#define LOG(severity) _TF_LOG_##severity
^
In file included from bug.cc:1:0:
/usr/local/include/glog/logging.h:506:0: note: this is the location of the previous definition
#define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
^

Describe the expected behavior

No leaking platform/logging.h and no those warnings about redefining glog macros.

Code to reproduce the issue

Provide a reproducible test case that is the bare minimum necessary to generate the problem.

#include <glog/logging.h>
#include "tensorflow/core/public/session.h"

int main() {
tensorflow::SessionOptions gpu_option;
}

export TF_INC_DIR=/tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include
g++ bug.cc -std=c++11 -I$TF_INC_DIR -I$TF_INC_DIR/external/com_google_absl

Other info / logs

Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

I know TensorFlow has tried to avoid leaking the logging macros (#7480), but core/lib/core/refcount.h is leaking them again. It seems that one way to fix it is to remove #include "tensorflow/core/platform/logging.h" from the headers and add them back in the .cc files. However, as said in core/lib/core/refcount.h, those are "Inlined routines, since these are performance critical" thus cannot be moved to a .cc file. But I'm sure there must be a way to stop leaking the logging macros.

Issue 2:
CHECK macros from platform/logging.h leak out into core/public headers which clash with users of glog.

One path is through core/platform/allocator.h:

In file included from external/org_tensorflow/tensorflow/core/platform/logging.h:25:0,
from external/org_tensorflow/tensorflow/core/framework/allocator.h:26,
from external/org_tensorflow/tensorflow/core/framework/tensor.h:21,
from external/org_tensorflow/tensorflow/core/public/session.h:23,
(snip)
external/org_tensorflow/tensorflow/core/platform/default/logging.h:224:0: note: this is the location of the previous definition
#define CHECK_OP_LOG(name, op, val1, val2) \
^

This one is easy to fix by moving method implementation to allocator.cc.

Another is through core/lib/core/status.h.

In file included from external/org_tensorflow/tensorflow/core/platform/logging.h:25:0,
from external/org_tensorflow/tensorflow/core/lib/core/status.h:24,
from external/org_tensorflow/tensorflow/core/lib/core/errors.h:19,
from external/org_tensorflow/tensorflow/core/framework/tensor_shape.h:24,
from external/org_tensorflow/tensorflow/core/framework/tensor.h:24,
from external/org_tensorflow/tensorflow/core/public/session.h:23,

This one is more work to fix because TF_CHECK_OK is used all over the code, but it does not seem to be necessary for core/public.