[matroska-devel] Re: Namespace pb

Cyrius suiryc at yahoo.com
Tue Apr 8 14:28:29 CEST 2003

--- Steve Lhomme <steve.lhomme at free.fr> wrote:
> I saw on the IRC logs that Cyrius had problems with
> the namespaces of 
> libeml.
> The solution used is working but a dirty hack
> (#define uint8 
> LIBEBML_uint8 / #undef uint8).
> The problem you probably have is that all libebml
> classes are children 
> of VDub classes (am I right ?). If there is no
> specific need for that I 
> suggest you remove that depency because in this case
> you're mixing the 
> namespaces of VDub (if any) and the ones of
> libebml/libmatroska. So you 
> would need something like
> vdub_namespace::libebml::uint8 which is still 
> possible and cleaner to use.
> Other than that when you use some
> libebml/libmatroska elements in your 
> code you should use LIBEBML_NAMESPACE::uint8 instead
> of using namespace 
> LIBEBML_NAMESPACE (which led you to ambiguous code).
> After all the 
> namespaces are here to help you get rid of ambiguous
> definitions not to 
> annoy you !
> 2 cents
> http://www.matroska.org

Well the problem doesn't seem as simple as that.
First of all it is due to the fact that Avery
typedefed (u/s)int8/16/32/64, and that libebml also
typedefed (s)int8/16/32/64.

VirtualDub doesn't use a namespace for that (yet ? -
Avery uses namespaces in parts that have been added in
version 1.5.0). Moreover VirtualDub uses precompiled
headers. So the .cpp file has to #include "stdafx.h"
first, which then include the file containing the
Then I can #include my .h file that #include
libmatroska/libebml files. This lead to those errors :
.\mod\matroska\libebml\src\api/c/libebml_t.h(79) :
error C2371: 'int32' : redefinition; different basic
        ..\h\vd2/system/vdtypes.h(34) : see
declaration of 'int32'
.\mod\matroska\libebml\src\api/c/libebml_t.h(80) :
error C2371: 'int16' : redefinition; different basic
        ..\h\vd2/system/vdtypes.h(35) : see
declaration of 'int16'

(vdtypes.h is the VirtualDub file where are the
typedefs ;))

This happen even when I don't use 'using namespace
LIBMATROSKA_NAMESPACE;' or 'using namespace
As I can't possibly modify one of the two parts (if I
create a namespace for VirtualDub typedefs I would
have to write 'using namespace vdub_namespace;' in
eavery single file needing the typedefs ... i.e.
almost every file; if I modify something in libebml
typedefs I would have to change all the files too :p)

I also tried another odd thing : I put
around the typedefs in libebml_t.h (wasn't here sonce
this file is included insided the namespace in
libebml) and then the errors turned into :
.\mod\matroska\libmatroska\src\KaxBlock.h(58) : error
C2872: 'uint32' : ambiguous symbol
.\mod\matroska\libmatroska\src\KaxBlock.h(63) : error
C2872: 'uint32' : ambiguous symbol

which isn't better for me :p
So actually the dirty trick of
#define int8 LIBEBML_int8
#include libebml/libmatroska files
#undef int8

,which makes libebml typedef to
LIBEBML_(s)int8/16/32/64 instead of (s)int8/16/32/64
that are already typedefed by VirtualDub,
was the only working solution I found so far ...

But then I am not an expert in C++ nor in namespaces
and maybe there is something obvious I am missing ;)

Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more

More information about the Matroska-devel mailing list