Skip to content

Commit 97636a9

Browse files
authored
"fix link error" (#13545)
1 parent efc2ac9 commit 97636a9

File tree

7 files changed

+47
-17
lines changed

7 files changed

+47
-17
lines changed

paddle/fluid/framework/eigen.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
// logging.h and windows.h conflict
17+
#define GLOG_NO_ABBREVIATED_SEVERITIES
18+
// solve static linking error in windows
19+
// https://github.com/google/glog/issues/301
20+
#define GOOGLE_GLOG_DLL_DECL
1621

1722
#include "paddle/fluid/framework/tensor.h"
1823
#include "unsupported/Eigen/CXX11/Tensor"
@@ -46,11 +51,13 @@ struct EigenTensor {
4651
using ConstType =
4752
Eigen::TensorMap<Eigen::Tensor<const T, D, MajorType, IndexType>>;
4853

49-
static Type From(Tensor& tensor, DDim dims) {
54+
static Type From(Tensor& tensor, DDim dims) { // NOLINT
5055
return Type(tensor.data<T>(), EigenDim<D>::From(dims));
5156
}
5257

53-
static Type From(Tensor& tensor) { return From(tensor, tensor.dims_); }
58+
static Type From(Tensor& tensor) { // NOLINT
59+
return From(tensor, tensor.dims_);
60+
} // NOLINT
5461

5562
static ConstType From(const Tensor& tensor, DDim dims) {
5663
return ConstType(tensor.data<T>(), EigenDim<D>::From(dims));
@@ -64,7 +71,8 @@ struct EigenTensor {
6471
template <typename T, int MajorType = Eigen::RowMajor,
6572
typename IndexType = Eigen::DenseIndex>
6673
struct EigenMatrix : public EigenTensor<T, 2, MajorType, IndexType> {
67-
static typename EigenMatrix::Type Reshape(Tensor& tensor, int num_col_dims) {
74+
static typename EigenMatrix::Type Reshape(Tensor& tensor, // NOLINT
75+
int num_col_dims) {
6876
int rank = tensor.dims_.size();
6977
PADDLE_ENFORCE(num_col_dims > 0 && num_col_dims < rank,
7078
"`num_col_dims` must be between (0, rank_of_tensor).");
@@ -86,11 +94,12 @@ template <typename T, int MajorType = Eigen::RowMajor,
8694
typename IndexType = Eigen::DenseIndex>
8795
struct EigenVector : public EigenTensor<T, 1, MajorType, IndexType> {
8896
// Flatten reshapes a Tensor into an EigenVector.
89-
static typename EigenVector::Type Flatten(Tensor& tensor) {
97+
static typename EigenVector::Type Flatten(Tensor& tensor) { // NOLINT
9098
return EigenVector::From(tensor, {product(tensor.dims_)});
9199
}
92100

93-
static typename EigenVector::ConstType Flatten(const Tensor& tensor) {
101+
static typename EigenVector::ConstType Flatten(
102+
const Tensor& tensor) { // NOLINT
94103
return EigenVector::From(tensor, {product(tensor.dims_)});
95104
}
96105
};
@@ -104,7 +113,7 @@ struct EigenScalar {
104113
using ConstType = Eigen::TensorMap<
105114
Eigen::TensorFixedSize<const T, Eigen::Sizes<>, MajorType, IndexType>>;
106115

107-
static Type From(Tensor& tensor) { return Type(tensor.data<T>()); }
116+
static Type From(Tensor& tensor) { return Type(tensor.data<T>()); } // NOLINT
108117

109118
static ConstType From(const Tensor& tensor) {
110119
return ConstType(tensor.data<T>());

paddle/fluid/framework/op_registry.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ limitations under the License. */
2323
#include <unordered_map>
2424
#include <unordered_set>
2525

26+
#if defined(_WIN32)
27+
#define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h
28+
#define GOOGLE_GLOG_DLL_DECL
29+
#endif
30+
2631
#include "glog/logging.h" // For VLOG()
2732
#include "paddle/fluid/framework/attribute.h"
2833
#include "paddle/fluid/framework/details/op_registry.h"
@@ -241,22 +246,20 @@ struct OpKernelRegistrarFunctorEx<PlaceType, false, I,
241246
* we will use and tell the compiler to
242247
* link them into target.
243248
*/
244-
#define USE_OP_ITSELF(op_type) \
245-
STATIC_ASSERT_GLOBAL_NAMESPACE( \
246-
__use_op_itself_##op_type, \
247-
"USE_OP_ITSELF must be called in global namespace"); \
248-
extern int TouchOpRegistrar_##op_type(); \
249-
static int use_op_itself_##op_type##_ __attribute__((unused)) = \
250-
TouchOpRegistrar_##op_type()
249+
#define USE_OP_ITSELF(op_type) \
250+
STATIC_ASSERT_GLOBAL_NAMESPACE( \
251+
__use_op_itself_##op_type, \
252+
"USE_OP_ITSELF must be called in global namespace"); \
253+
extern int TouchOpRegistrar_##op_type(); \
254+
UNUSED static int use_op_itself_##op_type##_ = TouchOpRegistrar_##op_type()
251255

252256
#define USE_OP_DEVICE_KERNEL(op_type, LIBRARY_TYPE) \
253257
STATIC_ASSERT_GLOBAL_NAMESPACE( \
254258
__use_op_kernel_##op_type##_##LIBRARY_TYPE##__, \
255259
"USE_OP_DEVICE_KERNEL must be in global namespace"); \
256260
extern int TouchOpKernelRegistrar_##op_type##_##LIBRARY_TYPE(); \
257-
static int use_op_kernel_##op_type##_##LIBRARY_TYPE##_ \
258-
__attribute__((unused)) = \
259-
TouchOpKernelRegistrar_##op_type##_##LIBRARY_TYPE()
261+
UNUSED static int use_op_kernel_##op_type##_##LIBRARY_TYPE##_ = \
262+
TouchOpKernelRegistrar_##op_type##_##LIBRARY_TYPE()
260263

261264
// TODO(fengjiayi): The following macros
262265
// seems ugly, do we have better method?

paddle/fluid/framework/operator.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14+
#define GLOG_NO_ABBREVIATED_SEVERITIES
15+
#define GOOGLE_GLOG_DLL_DECL
16+
1417
#include <gflags/gflags.h>
1518
#include <glog/logging.h>
1619

paddle/fluid/framework/operator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ limitations under the License. */
2020
#include <tuple>
2121
#include <unordered_map>
2222
#include <vector>
23+
#define GLOG_NO_ABBREVIATED_SEVERITIES
24+
#define GOOGLE_GLOG_DLL_DECL
2325

2426
#include "glog/logging.h" // For VLOG
2527
#include "paddle/fluid/framework/attribute.h"

paddle/fluid/inference/api/api_impl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@
1414

1515
#pragma once
1616

17+
// logging.h and windows.h conflict
18+
#define GLOG_NO_ABBREVIATED_SEVERITIES
19+
// solve static linking error in windows
20+
// https://github.com/google/glog/issues/301
21+
#define GOOGLE_GLOG_DLL_DECL
22+
1723
#include <glog/logging.h>
1824
#include <map>
1925
#include <memory>
2026
#include <string>
2127
#include <vector>
2228

29+
#include "paddle/fluid/inference/api/paddle_inference_api.h"
30+
2331
#include "paddle/fluid/framework/ddim.h"
2432
#include "paddle/fluid/framework/lod_tensor.h"
25-
#include "paddle/fluid/inference/api/paddle_inference_api.h"
2633
#include "paddle/fluid/inference/io.h"
2734
#include "paddle/fluid/platform/init.h"
2835
#include "paddle/fluid/platform/profiler.h"

paddle/fluid/platform/cudnn_helper_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15+
#define GLOG_NO_ABBREVIATED_SEVERITIES
16+
#define GOOGLE_GLOG_DLL_DECL
17+
1518
#include "paddle/fluid/platform/cudnn_helper.h"
1619
#include <gtest/gtest.h>
1720

paddle/fluid/platform/init.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ limitations under the License. */
1616
#include <string>
1717
#include <vector>
1818

19+
#define GLOG_NO_ABBREVIATED_SEVERITIES
20+
#define GOOGLE_GLOG_DLL_DECL
21+
1922
#include "gflags/gflags.h"
2023
#include "glog/logging.h"
2124

0 commit comments

Comments
 (0)