dbremner / mili

Automatically exported from code.google.com/p/mili
Boost Software License 1.0
0 stars 0 forks source link

Compilations problems in OS X #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the problem:

1. Include mili in a simple main class and use it. For example the 
example_stream-utils.cpp file which is included in mili repository.

2. Compile it using the g++ command.

The following compilation errors are shown:

In file included from mili/mili.h:67,
                 from example_stream-utils.cpp:27:
mili/string_utils.h:202: error: ‘toupper’ is not a valid template argument 
for type ‘int (*)(int)’ because function ‘int toupper(int)’ has not 
external linkage
mili/string_utils.h:202: error: invalid type in declaration before ‘;’ token
mili/string_utils.h:203: error: ‘tolower’ is not a valid template argument 
for type ‘int (*)(int)’ because function ‘int tolower(int)’ has not 
external linkage
mili/string_utils.h:203: error: invalid type in declaration before ‘;’ token
mili/string_utils.h: In function ‘std::string tolower(const std::string&)’:
mili/string_utils.h:207: error: invalid cast from type ‘const 
std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to 
type ‘lstring’
mili/string_utils.h: In function ‘std::string toupper(const std::string&)’:
mili/string_utils.h:212: error: invalid cast from type ‘const 
std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to 
type ‘ustring’

The GCC version used was the following:

i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)

The operating system was Mac OS X Version 10.6.7

Original issue reported on code.google.com by domedam...@gmail.com on 10 Jul 2011 at 9:03

GoogleCodeExporter commented 9 years ago
At least one of the problems seems that in mac, toupper and tolower are inlined 
functiosn (thus not having external linkage, so no pointer-to-function can be 
obtained and therefore passed to the template argument).
Please try the following solution:
in the template normalized_string template definition, receive a functor rather 
than a pointer to function.
Additionally, create a TO_UPPER_FUNCTOR implemented using toupper, similar with 
tolower.
Then, in the typedefs, use the newly created functors rather than the 
pointer-tu-functions.

This solution is globally better than the current implementation, and should 
work for most platforms.

Original comment by danielgutson@gmail.com on 10 Jul 2011 at 11:24

GoogleCodeExporter commented 9 years ago
(since it doesn't depend whether the toupper/tolower functions are inlined or 
not in the library implementation)

Original comment by danielgutson@gmail.com on 10 Jul 2011 at 11:26

GoogleCodeExporter commented 9 years ago
Please, run mili tests in osX and make sure they fail. If not, please add a 
test for this case.

Original comment by hugo.arregui on 11 Jul 2011 at 12:14

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r234.

Original comment by bombax on 31 Jul 2011 at 9:04