Solved Does the linker care about namespaces?
-
Noob question.
If a class/function of a library (static or dynamic) is declared (in a header file that will form part of the "includes") with something like:#ifdef USE_NAMESPACE namespace MyNameSpace{ #endif /*exported function/class*/ #ifdef USE_NAMESPACE } #endif
and
USE_NAMESPACE
is not defined when I compile the library. Can I then addUSE_NAMESPACE
to the definition of an application that links to that library? -
I am probably more Noob than you are.
So far I have rated namespace similar as class and struct for compilation and linking. This is meant in view of naming in the objects with C++ compilers. When the namespace adds something to the whole name in the object, you have to use it always the same everywhere.
You can do :
void foo () { do something; } namespace myspace { void foo () { do something else; } } void rou() { ::foo(); myspace::foo(); }
both routines do different thing and compiler and linker must distinguish by some naming convention.
-
-
@VRonin said in Does the linker care about namespaces?:
and
USE_NAMESPACE
is not defined when I compile the library. Can I then addUSE_NAMESPACE
to the definition of an application that links to that library?@JonB
He plans to use it inconsistently, isn't he? -
@VRonin said in Does the linker care about namespaces?:
Can I then add USE_NAMESPACE to the definition of an application that links to that library?
Nope. The linker very much cares about namespaces, to answer your title. The namespace identifier will be part of the fully qualified name of the symbol, so you need to link with code compiled with a compatible header.