astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
https://astamm.github.io/nloptr/
Other
105 stars 35 forks source link

[2.0.0] fails to build on R 3.6.0 #105

Closed tuxmaster5000 closed 2 years ago

tuxmaster5000 commented 2 years ago

The build fails with:

[ 90%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/solver.cc.o
[ 92%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/local_optimizer.cc.o
[ 94%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/ags.cc.o
[ 96%] Linking CXX static library libnlopt.a
Error running link command: No such file or directory
make[2]: *** [libnlopt.a] Error 2
make[1]: *** [CMakeFiles/nlopt.dir/all] Error 2
gmake: *** [all] Error 2

build.log

I think the config step don't resect the fact, that R 3.6.0 don't have variables AR and RANLIB. And so the cmake defaults are overwritten with invalid values. I have attached an full build log.

tuxmaster5000 commented 2 years ago

building the bundled nlopt-2.7.1 works well.

cmake3 -DBUILD_SHARED_LIBS=OFF ..
 81%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/local_optimizer.cc.o
[ 82%] Building CXX object CMakeFiles/nlopt.dir/src/algs/ags/ags.cc.o
[ 84%] Linking CXX static library libnlopt.a
[ 87%] Built target nlopt
Scanning dependencies of target t_tutorial
Scanning dependencies of target testopt
[ 89%] Building CXX object test/CMakeFiles/t_tutorial.dir/t_tutorial.cxx.o
[ 91%] Building C object test/CMakeFiles/testopt.dir/testfuncs.c.o
[ 93%] Building C object test/CMakeFiles/testopt.dir/testopt.c.o
[ 94%] Building C object test/CMakeFiles/testopt.dir/__/src/util/timer.c.o
[ 96%] Building C object test/CMakeFiles/testopt.dir/__/src/util/mt19937ar.c.o
[ 98%] Linking CXX executable testopt
[ 98%] Built target testopt
[100%] Linking CXX executable t_tutorial
[100%] Built target t_tutorial

So the problem is the overwritten cmake variables.

tuxmaster5000 commented 2 years ago

Of course the lib will work. test.log

astamm commented 2 years ago

Thanks for reporting this. I will provide a solution in the next release, either by requiring R >= 4.0.x or by setting AR and RANLIB only if the detected version of R is >= 4.0.x. I will let you know if I implement the latter if you are willing to test if it works on your system.

tuxmaster5000 commented 2 years ago

Thanks, yes of course I can test it.

tuxmaster5000 commented 2 years ago

Here is the working patch, which can you use as an reference. r.patch.txt

astamm commented 2 years ago

Would you mind contributing it as a PR please?

tuxmaster5000 commented 2 years ago

I will try it tomorrow, because I must look how to detect the R major version.

eddelbuettel commented 2 years ago

because I must look how to detect the R major version.

> getRversion()
[1] ‘4.1.2’
> getRversion() > "3.6.0"
[1] TRUE
> getRversion() > "4.2.0"
[1] FALSE
> 

To a first appromixation, I wouldn't though. We are at 4.1.2 and 2 1/2 months away from R 4.2.0.