Skip to content

compilation error in nlopt\src\algs\neldermead\nldrmd.c (beta redefined) #613

@p-j-miller

Description

@p-j-miller

What happened?

The issue is that some systems define beta in math.h and this causes a compilation error as there is a variable "beta" in the code.
The issue was found using C++ builder V12.1 on Windows which uses the clang compiler but a quick web search suggests the function double beta(double x, double y); was originally proposed in https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1292.pdf and is now present in a number of compiler header files.

How to reproduce the issue?

The actual problem is present on line 35 of nlopt\src\algs\neldermead\nldrmd.c :  

 static const double alpha = 1, beta = 0.5, gamm = 2, delta = 0.5;

The obvious fix is to rename beta (I used sbeta). This constant is only used in line 254 so that also needs to be changed:

  if (!reflectpt(n,xcur,c, fh <= fr ? -sbeta : sbeta, xh, lb,ub)) {

Version

2-10-0 (but I assume this is present in all versions of nlopt)

Operating System

unknown

Installation media

unknown

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions