Tensorflow C++:You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler

When using the tensorflow C++ API, the error You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler.
The reason is as follows (see reference).

 

If you omit the COMPILER_MSVC definition, you will run into an error saying “You must define TF_LIB_GTL_ALIGNED_CHAR_ARRAY for your compiler.” If you omit the NOMINMAX definition, you will run into a number of errors saying “’(‘: illegal token on right side of ‘::’”. (The reason for this is that <Windows.h> gets included somewhere, and Windows has macros that redefine min and max. These macros are disabled with NOMINMAX.)

Solution 1:
Add at the beginning of the code

#pragma once

#define COMPILER_MSVC
#define NOMINMAX

Solution 2:

Take vs2017 as an example: attribute Manager — > C/C + + –> preprocessor definition

Paste in the following

COMPILER_ MSVC
NOMINMAX

put things right once and for all!

Read More: