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

时间:2015-02-03 13:12:14

标签: visual-studio-2012 cl nlopt

当我尝试使用website中提供的Windows cmake文件使用Visual Studio Express 2013编译 nlopt 时,通过cmake -DCMAKE_BUILD_TYPE=Release -DNLOPT_BUILD_SHARED=On -G"NMake Makefiles" ..中的build进行配置子目录工作正常,但通过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.

2 个答案:

答案 0 :(得分:4)

当我尝试在发布模式下使用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) {

通过此修复,我不需要删除优化标记。

答案 1 :(得分:0)

问题是优化标志/ O2导致cl.exe崩溃。要使用/ 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',但这正是我们想要的)。