integration with boost library.


kirill_igum
10-03-2011, 12:32 AM
i get a bunch of errors when i use both nr3.h and boost library.

I use ubuntu 10.04 with libboost1.40

try.cc:

#include "nr3.h"
#include <boost/algorithm/string/predicate.hpp>

int main(void) {
return 0;
}


i compile the code "g++ try.cc" and i get errors. if i comment out either the nr3.h line or the <boost ... > line, the code compiles fine.

here are the errors:


In file included from /usr/include/boost/assert.hpp:36,
from /usr/include/boost/range/iterator_range.hpp:31,
from /usr/include/boost/range/as_literal.hpp:22,
from /usr/include/boost/algorithm/string/predicate.hpp:19,
from boostnrexample.cc:2:
/usr/include/assert.h: In function ?void __assert_fail(const char*, const char*, unsigned int, const char*)?:
/usr/include/assert.h:73: error: expected primary-expression before ?,? token
/usr/include/assert.h: At global scope:
/usr/include/assert.h:73: error: declaration does not declare anything
/usr/include/assert.h: In function ?void __assert_perror_fail(int, const char*, unsigned int, const char*)?:
/usr/include/assert.h:79: error: expected primary-expression before ?,? token
/usr/include/assert.h: At global scope:
/usr/include/assert.h:79: error: declaration does not declare anything
/usr/include/assert.h: In function ?void __assert(const char*, const char*, int)?:
/usr/include/assert.h:85: error: expected primary-expression before ?,? token
/usr/include/assert.h: At global scope:
/usr/include/assert.h:85: error: declaration does not declare anything
In file included from /usr/include/c++/4.4/x86_64-linux-gnu/bits/messages_members.h:37,
from /usr/include/c++/4.4/bits/locale_facets_nonio.h:1905,
from /usr/include/c++/4.4/locale:43,
from /usr/include/boost/algorithm/string/compare.hpp:15,
from /usr/include/boost/algorithm/string/predicate.hpp:22,
from boostnrexample.cc:2:
/usr/include/libintl.h: In function ?char* gettext(const char*)?:
/usr/include/libintl.h:41: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:41: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* dgettext(const char*, const char*)?:
/usr/include/libintl.h:46: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:46: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* __dgettext(const char*, const char*)?:
/usr/include/libintl.h:48: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:48: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* dcgettext(const char*, const char*, int)?:
/usr/include/libintl.h:54: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:54: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* __dcgettext(const char*, const char*, int)?:
/usr/include/libintl.h:57: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:57: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* ngettext(const char*, const char*, long unsigned int)?:
/usr/include/libintl.h:64: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:64: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* dngettext(const char*, const char*, const char*, long unsigned int)?:
/usr/include/libintl.h:70: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:70: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* dcngettext(const char*, const char*, const char*, long unsigned int, int)?:
/usr/include/libintl.h:77: error: expected primary-expression before ?,? token
/usr/include/libintl.h: At global scope:
/usr/include/libintl.h:77: error: declaration does not declare anything
/usr/include/libintl.h: In function ?char* textdomain(const char*)?:
/usr/include/libintl.h:83: error: expected primary-expression before ?,? token
/usr/include/libintl.h: In function ?char* bindtextdomain(const char*, const char*)?:
/usr/include/libintl.h:88: error: expected primary-expression before ?,? token
/usr/include/libintl.h: In function ?char* bind_textdomain_codeset(const char*, const char*)?:
/usr/include/libintl.h:93: error: expected primary-expression before ?,? token



I also cross-listed the question on stackoverflow. i hope it's ok. http://stackoverflow.com/questions/7631334/integrating-boost-with-numerical-recipes-3-code

thank you for your help,
--Kirill

davekw7x
10-03-2011, 07:03 AM
i get a bunch of errors when i use both nr3.h and boost library...
This is due to the (unfortunate, in my opinion) design decision in the NR distribution to make a #defined macro for throw() in nr3.h (See Footnote.)

Here's something that you can try:
In nr3.h, change the two statements like the following

#define throw(....


to something like

#define nr3Throw(...


I haven't tested very much to see whether this screws the pooch in some way that hasn't occurred to me, but maybe it's a starting point for you.

Now, if it happens that you need (or desire) the NR3-defined throw() functionality for some NR3 library function, you can, maybe, modify the library function to use nr3Throw() instead.

For example: If you call the NR3 julday() function (in calendar.h) with year equal to zero, with unmodified nr3.h and unmodified calendar.h you get a specific error message, something like the following:

ERROR: julday: there is no year zero.
in file ../code/calendar.h at line 4
terminate called after throwing an instance of 'int'
Aborted


If you modify nr3.h according to my suggestion, but leave calendar.h alone, the (somewhat less informative) error message is just this:

terminate called after throwing an instance of 'int'
Aborted


Now, modify calendar.h to use nr3Throw() in places where it has throw(), and you will get the specific message about "no year zero."

Bottom line: I have used a modified nr3.h for some time with no problems. I didn't go through each and every NR3 file to change the throw() calls. If I get an exception that I don't understand, I make a copy of the NR3 file and change the throw() stuff to be consistent with the modified nr3.h

IWFMYMMV (It works for me; your mileage may vary!)


Regards,

Dave

Footnote:
There is a #define (BOOST_ENABLE_ASSERT_HANDLER, I think) that you may be able to use to allow the boost library to do its thing without including <assert.h>, and maybe you will want to investigate to see whether that is more appropriate. In the meanwhile, a simple change to <nr3.h> might get you started sooner.

kirill_igum
10-08-2011, 04:17 PM
thank you for the response.

Since I use only a few of the routines, I decided to just rewrite them.