nlopt 无法使用 MSVC 2012 编译 cobyla.c

nlopt fails to compile cobyla.c with MSVC 2012

当我尝试使用 website 中提供的 Windows cmake 文件使用 Visual Studio Express 2013 编译 nlopt 时,配置通过build 子目录中的 cmake -DCMAKE_BUILD_TYPE=Release -DNLOPT_BUILD_SHARED=On -G"NMake Makefiles" .. 工作正常,但通过 nmake 编译失败并显示此错误消息:

[ 40%] Building C object CMakeFiles/nlopt.dir/cobyla/cobyla.c.obj
cobyla.c
e:\dev\nlopt\nlopt-2.4.1\cobyla\cobyla.c(1503) : fatal
 error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 228)
 To work around this problem, try simplifying or changing the program near the l
ocations listed above.
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information
INTERNAL COMPILER ERROR in 'c:\MSVS12\VC\bin\cl.exe'
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information
NMAKE : fatal error U1077: 'c:\MSVS12\VC\bin\cl.exe' : return code '0x1'
Stop.
NMAKE : fatal error U1077: 'c:\MSVS12\VC\bin\nmake.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'c:\MSVS12\VC\bin\nmake.exe' : return code '0x2'
Stop.
ERROR: Build script of nlopt failed with errorcode 1.

问题是导致 cl.exe 崩溃的优化标志 /O2。要仅使用 /O1 编译 cobyla.c,请照常执行 cmake 步骤,但在开始 nmake 之前更改以下文件:

在构建目录中打开CMakeFiles/nlopt.dir/build.make并找到构建cobyla.c.obj

的指令

在那里,大约在第 522 行更改

$(C_DEFINES) /FoCMakeFiles\nlopt.dir\cobyla\cobyla.c.obj

$(C_DEFINES) /O1 /FoCMakeFiles\nlopt.dir\cobyla\cobyla.c.obj

然后 运行 nmake 它将构建(同时发出警告 cl : Command line warning D9025 : overriding '/O2' with '/O1',但这正是我们想要的)。

当我尝试在 Release 模式下使用 VC12(Visual Studio 2013 中的编译器)构建 CMake 生成的 nlopt 项目时,我在 cobyla.c 中遇到编译错误 C1001 修复来自 https://connect.microsoft.com/VisualStudio/feedback/details/1028781/c1001-on-release-build。我需要在 cobyla.c.

中有问题的行之前放置一个 #pragma
i__1 = nact;
#pragma loop(no_vector) //line 1503
for (k = 1; k <= i__1; ++k) {

有了这个修复,我不需要删除优化标志。