kthohr / optim

OptimLib: a lightweight C++ library of numerical optimization methods for nonlinear functions

Home Page:https://optimlib.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Header-Only-Version Internal Namespace

alitteneker opened this issue · comments

I've only been using this library for a couple of days (and enjoying it so far), but I ran into an issue during integration that I didn't see in a quick scan here on github. I wanted to use a header only version of the library for quick integration into an existing codebase, but ran into a bunch of 'identifier not found' compiler errors.

After a little bit of inspection, the problem seemed to be that the configure script removes the internal:: namespace labels from everywhere in the library, which causes most of the internal functions in the script to disassociate from their forward declarations.

For example, look at line_search_mt in more_thuente.hpp. This calls mt_step in several places, with no internal namespace prefix. When line_search_mt is correctly defined as being in the internal namespace, the compiler correctly infers that mt_step is also in the internal namespace. However, by killing the internal:: from the definition, the compiler won't be looking in the right namespace for its forward declarations.

Fortunately, I found an easy fix for this: remove the replacement of internal:: from the sed in the header-only-version part of the configure script, so that it reads as follows.
sed -e '1,/\[OPTIM_BEGIN\]/ d' $WDIR/src/"$dir_"/"$file_".cpp | sed -e "s|optimlib_inline|inline|" -e "s|optim::||" >> "$file_".hpp

This fell through the cracks with a recent update. Thanks for pointing it out.