?
Solved

What does relocation error with link time reference mean?

Posted on 2007-10-09
6
Medium Priority
?
1,649 Views
Last Modified: 2008-01-09
Hi,

I am getting this error when I try to run my application.
relocation error: test: symbol _Z17DBReadLicenseFilePKcP10a_db_parms, version dbsrv_r.so not defined in file dbsrv_r.so with link time reference

What does this relocation error mean? How can I fix this?

Thanks
Jamie
0
Comment
Question by:jamie_lynn
  • 3
  • 2
6 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 20045074
This might be a problem with C++ name mangling ... try putting extern "C" {} around the include.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 total points
ID: 20047906
To add to above information:

'Z17DBReadLicenseFilePKcP10a_db_parms' is the name of the function 'ReadLicenseFile' after C++ name mangling. C++ name mangling was made by the compiler as you can use the same function name more thatn once in C++ if using different arguments (and maybe different return type). Hence, the compiler makes a unique function name by generating (cryptic) abbreviations for return type and argument types and adds them to the function name. That all works wonderful as long as there is no (pure) .c source in your project compiled with the C compiler. C doesn't know of C++ name mangling and simply uses the name 'ReadLicenseFile' as in C all function names need to be unique. C++ name mangling also goes wrong if you try to access a function in .so library by calling dlopen() and dlsym() using the unmangled name.

To come out of this, you need to tell the C++ compiler that the function 'ReadLicenseFile' needs to be left unmangled. You could do that by using the extern "C" keyword in the header file where the 'ReadLicenseFile' was declared.

extern "C"  DBRead* ReadLicenseFile(char*, db_parm*);

Unfortunately, the above wouldn't compile if you include that header in a C source. So, you have to to that:

#if defined(__cplusplus)
extern "C"
{
#endif

DBRead* ReadLicenseFile(char*, db_parm*);

#if defined(__cplusplus)
}
#endif

That makes, that the extern "C" only was applied if the header was compiled with a C++ source. In case of a C source only the prototype of the function was compiled. So, in both cases we have *no* mangling.

If the header file isn't your's you also could put the extern "C" around the #include statement of that header as Infinity has suggested:

// my.cpp
#extern "C"
{
    #include "readlicensefile.h"
}

Here we don't need any macros as my.cpp was compiled by C++ compiler only.

Regards, Alex
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 20047962
>> #extern "C"

just without the # ;)
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20048822
>>>> just without the # ;)

Most likely the compiler would have complained but thank you nevertheless for reading thoroughly ;-)

>>>> extern "C"  DBRead* ReadLicenseFile(char*, db_parm*);
Note the types were a guess only. I actually don't know the rules of name mangling and it differs between compilers.




0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20050644
Note that I said the same thing as in the accepted answer, just with less words ;)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question