gcc compile error with sine and boost:interval - c++

I'm required to run some code on a linux (CentOs 6.7) server with gcc/g++ installed (7.2.0) and boost (1.66) (Edit: not only 1.66, an older version of boost interfered. Keep your machines clean guys). I specified my interval type with policies like so:
// test.cpp
#include <boost/numeric/interval.hpp>
namespace bn = boost::numeric;
namespace bi = bn::interval_lib;
using Interval = bn::interval<
double,
bi::policies<
bi::save_state<bi::rounded_transc_std<double> >,
bi::checking_base<double>
>
>;
Now I want to do some simple calculation like:
// still test.cpp
int main()
{
Interval iv_arg {1.0};
Interval res = sin(iv_arg);
}
On my local machine, a mac, compiling with clang works perfectly fine. However, as soon as I try to run it on the server, compiling with g++ -std=c++11 test.cpp I'm getting the error:
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:59: error:
'to_int' was not declared in this scope, and no declarations were
found by argument-dependent lookup at the point of instantiation
[-fpermissive] T int_down(const T& x) { this->downward(); return
to_int(x); }
~~~~~~^~~ /usr/include/boost/numeric/interval/rounded_arith.hpp:71:59: note:
declarations in dependent base
'boost::numeric::interval_lib::detail::c99_rounding' are not found by
unqualified lookup
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:59: note: use
'this->to_int' instead
There is some more info which seems irrelevant to the topic, but I can include it if it might help. I tried to google a little but couldn't find anything relevant. If possible, I would like to find a solution that doesn't require any changes on the server. Does anyone have an idea or encountered a similar problem before?

First version of boost that compiles this is 1.58
boost 1.57 ERROR
boost 1.58 OK

Related

cmath error on MacOS c++17: call to abs ambiguous

Having this error using c++17 on Mac OS.
As far as I can tell, code is correct and should work fine (compiles without issue w/ g++ and clang++ on linux).
Also, as far as I can tell, the current default mac version of clang [10.0.1] should support c++17 (full version info printout below).
So, my question is: is this actually a bug in my code, but it works by fluke on linux? Or is it an issue with MacOS clang e.g., not full c++17 implementation?
From cppref:
Defined in header (since C++17):
int abs( int n );
Other c++17 features seem to work completely fine.
#include <cmath>
// #include <cstdlib> //works if included
int main() {
int i = 1;
// return std::abs(1); // Works fine
return std::abs(i); // Fails
}
Compile with:
clang++ -std=c++17 test.cpp
Get this error:
test.cpp:7:10: error: call to 'abs' is ambiguous
return std::abs(i);
^~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/math.h:761:1: note:
candidate function
abs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);}
^
(... etc.)
1 error generated.
If you #include <cstdlib>, it works without error.
using -std=gnu++17 or -std=c++1z doesn't remove the problem either.
In the actual code (which is obviously more complex than the above, and actually uses c++17 features), the error happens depending on the order of my include files.
I can't replicate that in the simple example, but I assume it boils down to calling the cstdlib version instead of the cmath version.
Currently, my 'workaround' is to just put the header includes into the order that works..but this is hardly a long-term solution.
Does anyone know the cause?
Version info (error not specific to this MacOS version, also happens on my students' laptops):
Bens-iMac:test ben$ clang++ -v
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
See LWG Issue 2912
This has been fixed in libc++ trunk. I don't know if Apple has shipped this fix yet. As you found, including <cstdlib> is a workaround.

c++ BOOST_TEST not in scope

I'm using boost version 1.58
Boost appears to be installed correctly, and the following code compiles and runs correctly (giving an error on the third check):
#define BOOST_TEST_MODULE basics_test
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE( basics_test ) {
BOOST_CHECK(1 == 1);
BOOST_CHECK(1 + 2 < 4);
BOOST_CHECK(1 == 2);
}
However, when I attempt to run the second example from the site http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/testing_tools/boost_test_universal_macro.html, I get the error:
test.cpp: In member function ‘void test_op_reportings::test_method()’:
test.cpp:20:20: error: ‘BOOST_TEST’ was not declared in this scope
BOOST_TEST(a == b);
When I change each instance of BOOST_TEST to BOOST_CHECK, the code compiles and runs normally. I'm using g++; when I configure g++ to use c++11 as in g++ -std=c++11 test cpp -o main I get the same error.
How should I go about fixing this?
The documents you are looking at are for Boost 1.59, yet you are using boost 1.58. what makes you think BOOST_TEST existed in 1.58?
From the 1.58 documentation, I only see support for BOOST_TEST_MESSAGE and other alternatives.
Either upgrade your Boost to at least 1.59 where the documentation shows you have BOOST_TEST, or use the features available in 1.58 such as what you have already done.

boost accumulators example doesn't compile

I installed boost (1.60.0) on Linux Mint 17.3 Rosa and tried to compile the boost accumulator example (http://www.boost.org/doc/libs/1_60_0/doc/html/accumulators/user_s_guide.html) with the gcc compiler (v 4.8.4 64 bit) using this command:
>g++ -o exaccu exaccumulator.cpp -I/usr/local/lib/boost_1_60_0/
Compilation failed with a long list of error messages starting with:
>exaccumulator.cpp: In function ‘int main()’:
>exaccumulator.cpp:22:32: error: ‘accumulators’ has not been declared
>std::cout << "Moment: " << accumulators::moment<2>(acc) << std::endl;
After looking up accumulators.hpp I changed accumulators::moment<2> to moment<2>. This did the trick and the compilation (with the same flags) succeeded. Alternatively, prefixing "accumulators" with "boost::accumulators::moment<2>" worked too. So my question is: Is there something wrong with my installation of boost or is there a typo in the example from the tutorial ?
This seems to be a typo indeed.
You can use the whole boost namespace (bad idea) to make the example compile:
using namespace boost;
accumulators::moment<2>(acc);
Or, like you already did, just remove the accumulators:: specificier and only use namespace boost::accumulators;.
Or just specify it's fully qualified name : boost::accumulators::moment<2>(acc).

g++ error message "use 'this->equal' instead?"

I am trying to use stlplus ntree class and have written a program using it, and I have no problem compiling it in a Windows environment. I tried to port it into Ubuntu, but have errors.
stlplus ntree class uses template. Here is an example of my code
ntree<rule_node_struct> t;
ntree<rule_node_struct>::iterator cur_it;
if (cur_it == t.root())
{
// do something
}
When I compiled using g++, I get the following error message
In instantiation of ‘bool stlplus::ntree_iterator::operator==(const this_iterator&) const [with T = rule_node_struct; TRef = rule_node_struct&; TPtr = rule_node_struct*; stlplus::ntree_iterator::this_iterator = stlplus::ntree_iterator]’:
/usr/lib/stlplus3-03-08/containers/ntree.tpp:133:19: error: ‘equal’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
/usr/lib/stlplus3-03-08/containers/ntree.tpp:133:19: note: declarations in dependent base ‘stlplus::safe_iterator, stlplus::ntree_node >’ are not found by unqualified lookup
/usr/lib/stlplus3-03-08/containers/ntree.tpp:133:19: note: use ‘this->equal’ instead
Why does g++ has this error while Windows Visual Studio does not?
That seems to be a bug in the ntree class, as G++ does proper two-phase lookup of symbols, while VC seems to accept the broken code. Note that earlier versions of G++ also accepted this kind of code (AFAIK) and therefore it only got fixed in the latest version in the repository. Although that version is from 2010. It seems to me that it never made it into any release, so use the HEAD version or ask them to do a release.

getting started with boost cpu_timer, error: ‘boost::timer::cpu_timer’ has not been declared

I'm trying to compile this simple program to start learning how to use timers:
#include <boost/timer.hpp>
using boost::timer::cpu_timer;
//...
nanosecond_type last_checkpoint_time = 0;
cpu_timer checkpoint_timer; // start the timer
for (;;)
{
//process_a_transaction();
if (checkpoint_timer.elapsed().user - last_checkpoint_time > 5*1000000000LL)
{
//... create a checkpoint ...
last_checkpoint_time = checkpoint_timer.elapsed().user;
cout << checkpoint_timer.elapsed().user << endl;
}
}
I'm using gentoo linux and issuing the following command to compile:
g++ -I /usr/include/boost-1_46 timer1.cpp -o timer
I get these errors:
timer1.cpp:3:21: error: ‘boost::timer::cpu_timer’ has not been declared
timer1.cpp:5:1: error: ‘nanosecond_type’ does not name a type
timer1.cpp:6:1: error: ‘cpu_timer’ does not name a type
timer1.cpp:8:1: error: expected unqualified-id before ‘for’
timer1.cpp:8:8: error: expected unqualified-id before ‘)’ token
I was reading the docs under errors and warnings but the problem I am having is that I only have two libraries:
/usr/lib/libboost_test_exec_monitor-1_46.a
/usr/lib/libboost_test_exec_monitor-mt-1_46.a
Is this because I did not use the static-libs flag during compile of boost? Would I be better off using static-libs? Maybe this is a tangent. What else can cause the errors given above? Please forgive my ignorance as I am pretty new to C++/boost.
Thanks
I haven't been using cpu_timer my self, but a quick Google search seems to indicate you should include <boost/timer/timer.hpp> instead. As for the error of nanosecond_type you need to use another using statement for that.
I think I figured out what the problem is. I was quoting an example in my original post from the ver 1.49 documentation. cpu_timer was first discussed in the boost documentation in ver 1.48. The stable version on gentoo is currently 1.46 and testing only provides ver 1.47, ver 1.48 is hardmasked. So my only option is to remove boost from my system download the tar of 1.49 and possibly break my system wrt boost or wait for the hardmask to be removed from ver 1.48.
In any case, static-libs is certainly irrelevant because this is a compiler error, not a linker error. It doesn't look at the libraries until the linker stage, until then only the headers are relevant.