[aspectc-user] LNK2005 with woven Codes

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Fri Oct 27 10:41:50 CEST 2006

Hello Yan,

let me explain COMDAT support with a simple code example:

inline int global_counter () {
   static int c = 0;
   return c++;

If this inline function is define in a *header* file, the compiler and 
linker have a problem, because the code is "seen" by the compiler in 
more than one translation unit. In this particular example this is no 
problem with the code for the function as it is inlined anyway. However, 
the function contains a static local variable, which means that some 
global storage has to be allocated. Although compiled in more than one 
translation unit, the compiler and linker have to make sure that this 
global storage is allocated only once! This is COMDAT support.

Normally it is implemented by a concept known as "vague linkage", i.e. 
symbols in different translation units marked as "vague" (or "link 
once") are regarded as *one* by the linker if they have the same name 
and size.

AspectC++ relies on this compiler/linker feature. This is normally no 
problem, but with your special build environment ...

Maybe you could check this with the simple example shown above.

Best regards,


Yan Mao wrote:
> Hallo Olaf,
> I did some experiments and I am now almost sure that, my tool works different as VS Tool.
> I tested the same woven codes with both VS Tool and my special Tool, they gave me too difference results. With My tool, Aspects are instantiated twice, but with VS Tool only once.
> I posted the woven codes and different results, please take a look, and maybe you can give me some advice, how to avoid the problem.
> And what is "COMDAT-support", how can I make sure, that if my tool has "COMDAT-support" or not?
> Thanks,
> Yan
> p.s. Because both English and German are not my mother language, and I am not sure that my German is much better than my English, so i still use English.
> -------- Original-Nachricht --------
> Datum: Tue, 24 Oct 2006 05:08:12 +0200
> Von: Olaf Spinczyk <Olaf.Spinczyk at informatik.uni-erlangen.de>
> An: Yan Mao <maoyan at gmx.net>
> Betreff: Re: [aspectc-user] LNK2005 with woven Codes
>> Hello Yan,
>> to be honest, your description of the problem is not very precise and I
>> have no chance to reproduce the misbehavior.
>> If both advices are defined in the same aspect and if you don't define
>> your own aspect instantiation strategy with "aspectof()", I don't see a
>> reason why there should be two aspect instances. Or do you use some
>> special linker that has no "COMDAT-support"? Could you send me more
>> information about your build environment? If it helps, you could also
>> write in german.
>> - Olaf
>> Yan Mao wrote:
>>> Hallo Olaf,
>>> thanks for the answer. I changed my codes, and they worked now well. 
>>> But as I tried to use the same aspect in another project, I got another
>> problem.  
>>> In my aspect,I want to break an action, if the execution time expands.
>>> In an advice of one pointcut I set the "start time", and in the other
>> advice of another pointcut, i'd like to read the "start time", so that i can
>> compare the "current time" with the "start time". 
>>> But unfortunately, i cant get the setted start time. 
>>> It seemes that, 2 Aspect object are created in der Laufzeit, where only
>> one object should be created. That's why I cant get the set value.
>>> Actually the AC woven codes are almost the same with the sample project,
>> which worked well. But They just don't work!
>>> To notice, that my current project are build on a system, which wraps
>> the Visual Studio APIs and Libraries, and offers its own APIs. And I must
>> also use its own Compiler to compile and link the projects, which should call
>> VS compiler cl.exe internally. 
>>> I suppose that it has somthing to with the compiler, but i dont know how
>> to get the wright way to solve the problem.
>>> Can you give me some tipps?
>>> Sorry for my poor English, if it is hard to read. But I really need
>> help!
>>> Thanks in advance,
>>> Yan
>>> -------- Original-Nachricht --------
>>> Datum: Sun, 22 Oct 2006 08:20:11 +0200
>>> Von: Olaf Spinczyk <Olaf.Spinczyk at informatik.uni-erlangen.de>
>>> An: Yan Mao <maoyan at gmx.net>
>>> Betreff: Re: [aspectc-user] LNK2005 with woven Codes
>>>> Hello Yan,
>>>> it looks as if you defined the member functions of "Profiling" as
>>>> non-inline functions in the aspect header file. If the aspect affects
>>>> more than one translation unit, the code will be generated more than
>>>> once and the linker complains. Better define the small functions as
>>>> inline functions.
>>>> Best regards,
>>>> Olaf
>>>> Yan Mao wrote:
>>>>> Hello,
>>>>> I got LNK2005 errors by linking the woven codes.
>>>>> it seems to me, that the same aspect is expanded in multiple cpp
>> files.
>>>>> I have #ifndef #define and #endif macros in every head file, and I
>> also
>>>> notice that AC++ compiler generate constant names  such as
>>>>> __ac_have_C__DA_ACSTUTest_aspects_Profiling_ah__
>>>>> __ac_need_C__DA_ACSTUTest_aspects_Profiling_ah__
>>>>> But they still dont work. What's wrong with my codes?
>>>>> I'd like to post the sample codes, hope anyone can help me!
>>>>> thanks in advance!!
>>>>> Yan

More information about the aspectc-user mailing list