[aspectc-user] Defining structure inside advice code

Daniel Lohmann daniel.lohmann at informatik.uni-erlangen.de
Mon Jun 7 16:48:02 CEST 2004


Bartosz,

This is a bug in the VisualStudio compiler/linker. They assign a linker 
symbol to the  _inline_ member of a  _function-local _ class, which 
should have no linkage in any case! The symbol is then exported by each 
.obj file that includes the  (aspect-)header, which in your case are 
main.obj (because the aspect is woven in there) and the *_LinkOnce.obj 
(because the aspect instance is defined there.)

Unfortunately the bug is not only present in VC6, but also in VS2003. It 
will even be  present in the upcoming Whidbey version. We opened an 
incident with MS about the problem, they confirmed the bug, but could 
not tell us when it will be solved... :-(  Probably in "one of the next 
service packs".

The suggested workarounds are  to either transform the class into a 
global class (not declared in function scope) or to use the  
/FORCE:MULTIPLE linker option. However, both of these "solutions"  have 
some nasty side effects.


Daniel




Bartosz Blimke wrote:

>Hi,
>
>C++ doesn't allow to have nested definition of functions,
>thats mean it will not allow to make definition like this.
>
>
>int func1()
>{
> int func2()
> {
>   return 5;
> }
>
> return func2();
>}
>
>Simple solution for this problem is to pack the nested
>function into structure
>
>int func1()
>{
> struct aa
> {
>   int func2()
>   {
>     return 5;
>   }
> } simpleStructInstance;
>
> return simpleStructInstance.func2();
>}
>
>C++ compiler compiles it without problems.
>
>Problem is with ac++ advice code:
>
>//main.cpp
>#include <stdio.h>
>
>
>void func () {
>
>   printf ("func\n");
>}
>
>
>int main (int argc, char * argv[]) {
>   func ();
>   return 0;
>}
>//end of main.cpp
>
>aspect Aspect {
>
>    pointcut methods() = execution("% func()");
>
>
>    advice methods() : before()
>    {
>      struct simpleStruct{
>	int methodOfStruct()
>        {
>	  return 0;
>	}
>      } instance;
>
>      instance.methodOfStruct();
>    }
>
>};
>
>Linking...
>main.obj : error LNK2005: "public: int __thiscall `public: void __thiscall
>Aspect::__a0_before(void)'::`2'::simpleStruct::methodOfStruct(void)"
>(?methodOfStruct at simpleStruct@?1??__a0_before at Aspect@@QAEXXZ at QAEHXZ)
>already defined in TestAspectProject_LinkOnce.obj
>Debug\TestAspectProject.exe : fatal error LNK1169: one or more multiply
>defined symbols found
>
>
>The same problem is with after().
>When I use around() problem is only if I use tjp->proceed()
>inside the body of advice code.
>
>If the structure is defined inside aspect body but outside the
>advice body problem dissapear.
>
>Is it another problem linked to vc++ compiler, or ac++ bug ?
>
>
>Greets,
>
>Bartosz Blimke
>
>
>
>
>
>_______________________________________________
>aspectc-user mailing list
>aspectc-user at aspectc.org
>http://www.aspectc.org/mailman/listinfo/aspectc-user
>  
>




More information about the aspectc-user mailing list