【问题标题】:Using two different math libraries in the same project confuses Visual C++在同一个项目中使用两个不同的数学库会混淆 Visual C++
【发布时间】:2020-03-12 16:05:13
【问题描述】:

我的项目需要同时使用 Micorsoft Visual C++ math.h 和 Intel MKL math.h

用详细的细节构建,我得到:

1>  Note: including file:        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\cmath
1>  Note: including file:         E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h
1>  Note: including file:          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h
1>  Note: including file:           C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdefs.h
1>  E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h(1577): warning C4005: 'HUGE_VALF' : macro redefinition
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h(104) : see previous definition of 'HUGE_VALF'
1>  E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h(1579): warning C4005: 'HUGE_VALL' : macro redefinition
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h(105) : see previous definition of 'HUGE_VALL'
1>  E:\3rdParty\MKL\2017.1.143\windows\compiler\include\math.h(1581): warning C4005: 'HUGE_VAL' : macro redefinition
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\../../vc/include/math.h(96) : see previous definition of 'HUGE_VAL'

“'HUGE_VALF' : 宏重新定义”消息让我产生了怀疑。

起初我只是禁用了该警告,但考虑到此选项只会掩盖潜在问题,我正在寻找替代解决方案。

从第 1 行和第 2 行可以看出,Visual Studio 的 cmath 不包括 Visual Studio 的 math.h,但它应该包含 MKL 的同名文件。

如何设置我的CMakeLists.txt 文件以便编译器可以选择正确的包含文件?

【问题讨论】:

  • 查看项目的Properties\Configuration Properties\C/C++\General 和顶部条目Additional Include DirectoriesE:\3rdParty\MKL\2017.1.143\windows\compiler\include 在吗?如果是,请尝试将C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include; 放在它前面(如果math.h 甚至在该目录中,您最好检查一下)。
  • @TedLyngmo - 路径已经按照您的指示进行了排序。我确认math.h 在那个包含目录中。
  • 好的,cmath 文件中是否有一些 #ifdef 阻止 cmath 访问 #includeing math.h

标签: c++ visual-c++ cmake redefinition


【解决方案1】:

只需包装一个库。

例如创建头文件:

#pragma once

namespace imath {
    double sin(double a);
}

在cpp中

#include "Wrapper.h"
#include <intel/math.h>

namespace imath {
    double sin(double a) {
        return ::sin(a);
    }
}

对您需要在公共源代码中使用的每个符号执行此操作。

并且不包括C 版本的math.h 你使用的是C++ 所以#include &lt;cmath&gt;

【讨论】:

    猜你喜欢
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多