<p dir="auto"><em>Please make sure that this is a bug. As per our <a href="https://github.com/tensorflow/tensorflow/blob/master/ISSUES.md">GitHub Policy</a>, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template</em></p>
<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04</li>
<li>Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:</li>
<li>TensorFlow installed from (source or binary): source</li>
<li>TensorFlow version (use command below): <code class="notranslate">42c4f4ab6b53bce8639c203d7839d27eac11bd2f</code></li>
<li>Python version: 3.7</li>
<li>Bazel version (if compiling from source): 0.21.0</li>
<li>GCC/Compiler version (if compiling from source): 5.4.0-6ubuntu1~16.04.10</li>
<li>CUDA/cuDNN version: 9.0 / 7</li>
<li>GPU model and memory: 8x GTX 1080 Ti 12GB</li>
</ul>
<p dir="auto">You can collect some of this information using our environment capture <a href="https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh">script</a><br>
You can also obtain the TensorFlow version with<br>
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"</p>
<p dir="auto"><strong>Describe the current behavior</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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: &quot;LOG&quot; 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()
 ^"><pre class="notranslate"><code class="notranslate">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()
 ^
</code></pre></div>
<p dir="auto"><strong>Describe the expected behavior</strong></p>
<p dir="auto">No leaking <code class="notranslate">platform/logging.h</code> and no those warnings about redefining <code class="notranslate">glog</code> macros.</p>
<p dir="auto"><strong>Code to reproduce the issue</strong><br>
Provide a reproducible test case that is the bare minimum necessary to generate the problem.</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#include &lt;glog/logging.h&gt;
#include &quot;tensorflow/core/public/session.h&quot;

int main() {
    tensorflow::SessionOptions gpu_option;
}"><pre class="notranslate">#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>glog/logging.h<span class="pl-pds">&gt;</span></span>
#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">"</span>tensorflow/core/public/session.h<span class="pl-pds">"</span></span>

<span class="pl-k">int</span> <span class="pl-en">main</span>() {
    tensorflow::SessionOptions gpu_option;
}</pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><span class="pl-k">export</span> TF_INC_DIR=/tmp/tensorflow/execroot/org_tensorflow/bazel-out/k8-opt/genfiles/tensorflow/include
g++ bug.cc -std=c++11 -I<span class="pl-smi">$TF_INC_DIR</span> -I<span class="pl-smi">$TF_INC_DIR</span>/external/com_google_absl</pre></div>
<p dir="auto"><strong>Other info / logs</strong><br>
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.</p>
<p dir="auto">I know TensorFlow has tried to avoid leaking the logging macros (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="207378417" data-permission-text="Title is private" data-url="https://github.com/tensorflow/tensorflow/issues/7480" data-hovercard-type="issue" data-hovercard-url="/tensorflow/tensorflow/issues/7480/hovercard" href="https://github.com/tensorflow/tensorflow/issues/7480">#7480</a>), but <a href="https://github.com/tensorflow/tensorflow/blob/42c4f4ab6b53bce8639c203d7839d27eac11bd2f/tensorflow/core/lib/core/refcount.h"><code class="notranslate">core/lib/core/refcount.h</code></a> is leaking them again. It seems that one way to fix it is to remove <code class="notranslate">#include "tensorflow/core/platform/logging.h"</code> from the headers and add them back in the <code class="notranslate">.cc</code> files. However, as said in <code class="notranslate">core/lib/core/refcount.h</code>, those are "Inlined routines, since these are performance critical" thus cannot be moved to a <code class="notranslate">.cc</code> file. But I'm sure there must be a way to stop leaking the logging macros.</p>
<p dir="auto">CHECK macros from <code class="notranslate">platform/logging.h</code> leak out into <code class="notranslate">core/public</code> headers which clash with users of glog.</p>
<p dir="auto">One path is through <code class="notranslate">core/platform/allocator.h</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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)                            \
 ^"><pre class="notranslate"><code class="notranslate">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)                            \
 ^
</code></pre></div>
<p dir="auto">This one is easy to fix by moving method implementation to allocator.cc.</p>
<p dir="auto">Another is through <code class="notranslate">core/lib/core/status.h</code>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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,"><pre class="notranslate"><code class="notranslate">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,
</code></pre></div>
<p dir="auto">This one is more work to fix because <code class="notranslate">TF_CHECK_OK</code> is used all over the code, but it does not seem to be necessary for <code class="notranslate">core/public</code>.</p>