Can I use std::string in an external library interface?

View: New views
2 Messages — Rating Filter:   Alert me  

Can I use std::string in an external library interface?

by Joost Kraaijeveld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am experimenting with embedding Cint in my own application and giving
it access to my own libraries. The interface of my libraries uses
"std::string", e.g:

class Library
{
public:
void fn(const std::string& a);
}



If I compile this library with makecint I get the following error:

G__cpp_myLibrary.cxx: In function ‘int G__myLibrary_46_0_2(G__value*,
const char*, G__param*, int)’:
G__cpp_myLibrary.cxx:83: error: ‘string’ was not declared in this scope
G__cpp_myLibrary.cxx:83: error: expected primary-expression before ‘)’
token
G__cpp_myLibrary.cxx: In function ‘void G__setup_memfuncLibrary()’:
G__cpp_myLibrary.cxx:243: error: expected primary-expression before
‘void’
G__cpp_myLibrary.cxx:243: error: expected `)' before ‘void’
make: *** [G__cpp_myLibrary.o] Error 1


If I change the above to

using std::string;
class Library
{
public:
void fn(const string& a);
}

it works OK.

Is this how it is supposed to be? Or can I somehow use std::string in my
interface headers, without resorting to dummy wrapper headers or magic
macros?

TIA

--
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl



Re: Can I use std::string in an external library interface?

by Axel Naumann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

CINT removed the namespace std by default. You have two options: build
CINT with -DG__STD_NAMESPACE (which is not exercised regularly and might
thus fail) or create a new header that's only used for the dictionaries
and which contains nothing but "namespace std{} using namespace std;"
You pass it to cint together with the actual headers when creating the
dictionary. That way your program will not use it, only the CINT
dictionaries will #include it.

Cheers, Axel.

Joost Kraaijeveld wrote on 10/29/2009 09:36 AM:

> Hi,
>
> I am experimenting with embedding Cint in my own application and giving
> it access to my own libraries. The interface of my libraries uses
> "std::string", e.g:
>
> class Library
> {
> public:
> void fn(const std::string& a);
> }
>
>
>
> If I compile this library with makecint I get the following error:
>
> G__cpp_myLibrary.cxx: In function ‘int G__myLibrary_46_0_2(G__value*,
> const char*, G__param*, int)’:
> G__cpp_myLibrary.cxx:83: error: ‘string’ was not declared in this scope
> G__cpp_myLibrary.cxx:83: error: expected primary-expression before ‘)’
> token
> G__cpp_myLibrary.cxx: In function ‘void G__setup_memfuncLibrary()’:
> G__cpp_myLibrary.cxx:243: error: expected primary-expression before
> ‘void’
> G__cpp_myLibrary.cxx:243: error: expected `)' before ‘void’
> make: *** [G__cpp_myLibrary.o] Error 1
>
>
> If I change the above to
>
> using std::string;
> class Library
> {
> public:
> void fn(const string& a);
> }
>
> it works OK.
>
> Is this how it is supposed to be? Or can I somehow use std::string in my
> interface headers, without resorting to dummy wrapper headers or magic
> macros?
>
> TIA
>