From 2d99a105f91a58198f21fa11a201b739a6a573a7 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Fri, 12 Apr 2019 18:29:51 +0200 Subject: [PATCH] Fix c89 build Closes #259 --- .travis.yml | 2 +- CMakeLists.txt | 2 +- appveyor.yml | 2 +- src/algs/ags/ags.h | 18 +++++++++--------- src/algs/cdirect/hybrid.c | 1 - src/util/qsort_r.c | 4 ++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index beeb1483..a555617d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ matrix: - pip install mkdocs python-markdown-math --user - PATH=$PATH:~/.local/bin mkdocs build - mkdir build && pushd build - - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_MATLAB=OFF -DNLOPT_FORTRAN=ON -DCMAKE_C_FLAGS='-Wall -Wextra' -DCMAKE_CXX_FLAGS='-Wall -Wextra' .. + - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_MATLAB=OFF -DNLOPT_FORTRAN=ON -DCMAKE_C_FLAGS='-Wall -Wextra -std=c89' -DCMAKE_CXX_FLAGS='-Wall -Wextra' .. - make install -j2 && ctest -j2 --output-on-failure - rm -rf * ~/.local - cmake -DCMAKE_INSTALL_PREFIX=~/.local -DNLOPT_PYTHON=OFF -DNLOPT_OCTAVE=OFF -DNLOPT_GUILE=OFF -DNLOPT_MATLAB=OFF -DNLOPT_FORTRAN=ON -DCMAKE_TOOLCHAIN_FILE=$PWD/../cmake/toolchain-x86_64-w64-mingw32.cmake .. diff --git a/CMakeLists.txt b/CMakeLists.txt index dba2f688..4110bc06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ if (NOT DEFINED HAVE_FPCLASSIFY) message(STATUS "Looking for fpclassify") file (WRITE ${PROJECT_BINARY_DIR}/fpclassify.c "#include \n") file (APPEND ${PROJECT_BINARY_DIR}/fpclassify.c "int main(void) {\n") - file (APPEND ${PROJECT_BINARY_DIR}/fpclassify.c "if (!fpclassify(3.14159)) fpclassify(2.7183);\n") + file (APPEND ${PROJECT_BINARY_DIR}/fpclassify.c "if (!fpclassify(3.14159)) fpclassify(2.7183); int subn = FP_SUBNORMAL;\n") file (APPEND ${PROJECT_BINARY_DIR}/fpclassify.c " return 0; }\n") try_compile (HAVE_FPCLASSIFY ${PROJECT_BINARY_DIR}/build_fpclassify diff --git a/appveyor.yml b/appveyor.yml index 3fa6abaf..17c174cc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,8 +9,8 @@ branches: - master environment: matrix: + - CMAKE_PLATFORM: "Visual Studio 14 2010" - CMAKE_PLATFORM: "Visual Studio 14 2015" - - CMAKE_PLATFORM: "Visual Studio 14 2015 Win64" install: - cinstall: python #- choco install swig diff --git a/src/algs/ags/ags.h b/src/algs/ags/ags.h index 809340a6..f6821d67 100644 --- a/src/algs/ags/ags.h +++ b/src/algs/ags/ags.h @@ -10,19 +10,19 @@ extern "C" { #endif -//The algorithm supports 3 types of stop criterions: stop by execution time, stop by value and stop by exceeding limit of iterations. +/* The algorithm supports 3 types of stop criterions: stop by execution time, stop by value and stop by exceeding limit of iterations. */ int ags_minimize(unsigned n, nlopt_func func, void *data, unsigned m, nlopt_constraint *fc, double *x, double *minf, const double *l, const double *u, nlopt_stopping *stop); -extern double ags_eps; //method tolerance in Holder metric on 1d interval. Less value -- better search precision, less probability of early stop. -extern double ags_r; //reliability parameter. Higher value of r -- slower convergence, higher chance to cache the global minima. -extern double eps_res; // parameter which prevents method from paying too much attention to constraints. Greater values of this parameter speed up convergence, -// but global minima can be lost. -extern unsigned evolvent_density; // density of evolvent. By default density is 2^-12 on hybercube [0,1]^N, -// which means that maximum search accuracyis 2^-12. If search hypercube is large the density can be increased accordingly to achieve better accuracy. -extern int ags_refine_loc; //refine the final optimum using built-in local optimizer -extern int ags_verbose; //print additional info +extern double ags_eps; /* method tolerance in Holder metric on 1d interval. Less value -- better search precision, less probability of early stop. */ +extern double ags_r; /* reliability parameter. Higher value of r -- slower convergence, higher chance to cache the global minima. */ +extern double eps_res; /* parameter which prevents method from paying too much attention to constraints. Greater values of this parameter speed up convergence, */ +/* but global minima can be lost. */ +extern unsigned evolvent_density; /* density of evolvent. By default density is 2^-12 on hybercube [0,1]^N, */ +/* which means that maximum search accuracyis 2^-12. If search hypercube is large the density can be increased accordingly to achieve better accuracy. */ +extern int ags_refine_loc; /* refine the final optimum using built-in local optimizer */ +extern int ags_verbose; /* print additional info */ #ifdef __cplusplus } diff --git a/src/algs/cdirect/hybrid.c b/src/algs/cdirect/hybrid.c index dee20d47..1bfb0b60 100644 --- a/src/algs/cdirect/hybrid.c +++ b/src/algs/cdirect/hybrid.c @@ -78,7 +78,6 @@ static nlopt_result optimize_rect(double *r, params *p) double minf; nlopt_stopping *stop = p->stop; nlopt_result ret; - nlopt_opt opt; if (stop->maxeval > 0 && *(stop->nevals_p) >= stop->maxeval) return NLOPT_MAXEVAL_REACHED; diff --git a/src/util/qsort_r.c b/src/util/qsort_r.c index 18907e11..550354f0 100644 --- a/src/util/qsort_r.c +++ b/src/util/qsort_r.c @@ -22,8 +22,8 @@ #include "nlopt-util.h" #include -#if defined(_MSC_VER) -#define inline __inline +#if (__STDC_VERSION__ < 199901L) +#define inline #endif typedef int cmp_t(void *, const void *, const void *);