[aspectc-user] Problems linking

Marc-André Laverdière ma_laver at ciise.concordia.ca
Mon Oct 2 23:01:56 CEST 2006


Trying to compile in C++ caused a lot of weird errors.

However, I was able to take it from there and use an old trick:

#ifdef __cplusplus
extern "C" {
#endif

/* rest of the header file here*/

#ifdef __cplusplus
}
#endif

I did the same with my C code and things are compiling. Working is 
another matter entirely ;)

Thanks for awaking me to the reality that C and C++ speak different 
languages when it comes to linking!

Olaf Spinczyk wrote:
> Hello Marc-André,
> 
> do you compile theofile.o with a C (not C++) compiler? [This is just a
> wild guess.] Did you consider the different name mangling schemes in C
> and C++?
> 
> There isn't much magic behind the gnu linker. Which symbol is undefined
> and where do you think should it be defined?
> 
> Olaf
> 
> Marc-André Laverdière schrieb:
>> Hello,
>>
>> I have been jammed on this for a few days now, and I'm out of clues
>> and good Google searches to make... I hope someone saw that before and
>> found a solution. :)
>>
>> I am doing a simple test. I have a few functions in a separate .o file
>> that I want to use in my aspect.
>>
>> ac++ -c cfile.c -a aspect.ah -p. --config ./puma.config  -o
>> aspectCoutput.cc
>>
>> which generates what it should
>>
>> Then, when I do
>>
>> g++ -Os -pedantic theofile.o aspectCoutput.cc -o executable -lm
>> -llibcrypt -llibssl -llibgnutls -llibgnutls-extra
>>
>> I obtain error messages that my functions that are defined in
>> theofile.o have undefined references.
>>
>> When I run objdump on theofile.o, I get all the symbols, but all
>> preceded by a '_'.
>>
>> Yet, that wasn't a problem when I did
>> gcc -ansi -std=c99 -fno-exceptions -Os -pedantic theofile.o
>> testCprogram.c -o otherexecutable -lm -llibcrypt -llibssl -llibgnutls
>> -llibgnutls-extra.
>>
>> So, my .o file is ok, at least when compiling C code. Why is it
>> non-functional when compiling C++ generated by AspectC++? How do I
>> make it work
>>
>> P.S. Tried to compile directly with ag++ with the same results...
>>
>> Regards,
>>

-- 
Marc-André LAVERDIÈRE, B. Eng., M. A. Sc. (in progress)
Computer Security Laboratory - Laboratoire de sécurité informatique
CIISE, Université Concordia University, Montréal, Québec, Canada
www.ciise.concordia.ca

/"\
\ /    ASCII Ribbon Campaign
  X      against HTML e-mail
/ \

"Perseverance must finish its work so that you may be mature and 
complete, not lacking anything." -James 1:4



More information about the aspectc-user mailing list