问题现象
使用毕昇编译器编译openlb时,有如下报错:
问题分析
从报错日志可以看出contactAngle2d.o和mpiManager.o有重复定义的变量,查找该变量定义发现有两处地方。
1.src/dynamics/descriptorFunction.h定义了模板
2.src/dynamics/latticeDescriptors.h定义了模板特例化
template <>
constexpr int vicinity<2,9> = 1;
template <>
constexpr int c<2,9>[9][2] = {
{ 0, 0},
{-1, 1}, {-1, 0}, {-1,-1}, { 0,-1},
{ 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}
};
template <>
constexpr int opposite<2,9>[9] = {
0, 5, 6, 7, 8, 1, 2, 3, 4
};
template <>
constexpr Fraction t<2,9>[9] = {
{4, 9}, {1, 36}, {1, 9}, {1, 36}, {1, 9},
{1, 36}, {1, 9}, {1, 36}, {1, 9}
};
template <>
constexpr Fraction cs2<2,9> = {1, 3};
} mpiManager.o实例化了c<2,9>,contactAngle2d.o使用了特例化的c<2,9>,因此在链接的时候报重定义错误
解决方法:
1.使用inline修饰特例化模板。
2.删除特例化模板,统一使用模板。
问题现象
使用毕昇编译器编译openlb时,有如下报错:
问题分析
从报错日志可以看出contactAngle2d.o和mpiManager.o有重复定义的变量,查找该变量定义发现有两处地方。
1.src/dynamics/descriptorFunction.h定义了模板
template <unsigned D, unsigned Q> constexpr int vicinity = {}; template <unsigned D, unsigned Q> constexpr int c[Q][D] = {}; template <unsigned D, unsigned Q> constexpr int opposite[Q] = {}; template <unsigned D, unsigned Q> constexpr Fraction t[Q] = {}; template <unsigned D, unsigned Q> constexpr Fraction cs2 = {}; template <unsigned D, unsigned Q> constexpr Fraction lambda_e = {}; template <unsigned D, unsigned Q> constexpr Fraction lambda_h = {};2.src/dynamics/latticeDescriptors.h定义了模板特例化
template <> constexpr int vicinity<2,9> = 1; template <> constexpr int c<2,9>[9][2] = { { 0, 0}, {-1, 1}, {-1, 0}, {-1,-1}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1} }; template <> constexpr int opposite<2,9>[9] = { 0, 5, 6, 7, 8, 1, 2, 3, 4 }; template <> constexpr Fraction t<2,9>[9] = { {4, 9}, {1, 36}, {1, 9}, {1, 36}, {1, 9}, {1, 36}, {1, 9}, {1, 36}, {1, 9} }; template <> constexpr Fraction cs2<2,9> = {1, 3}; }mpiManager.o实例化了c<2,9>,contactAngle2d.o使用了特例化的c<2,9>,因此在链接的时候报重定义错误
解决方法:
1.使用inline修饰特例化模板。
2.删除特例化模板,统一使用模板。