extern (C) private linking issue
Derek Parnell
derek at nomail.afraid.org
Sun Feb 25 21:27:41 PST 2007
On Sun, 25 Feb 2007 23:33:25 -0500, William R. DeVore wrote:
> I am running into an issue under windows during linking.
>
> I am getting an optlink error based on a private function in a module:
>
> [quote]
> C:\Working\D1.0\Derelict228\examples\graphical>build @simulation -full
> Using Double Precision
> OPTLINK (R) for Win32 Release 7.50B1
> Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
>
> Simulations\CylBoxSlide.obj(CylBoxSlide) Offset 01494H Record Type 00C3
> Error 1: Previous Definition Different : _collisionCallback
> [/quote]
>
> File CylVsSphere.d has:
> [code]
> extern (C) private void collisionCallback(void* data, dGeomID o1, dGeomID o2) {
> ...
> }
> [/code]
>
> and
> CylBoxSlide.d has:
> [code]
> extern (C) private void collisionCallback(void* data, dGeomID o1, dGeomID o2) {
> ...
> }
> [/code]
>
> Doesn't the private attribute hide the functions?
>
> These modules are imported in a factory module (SimFactory.d) as so:
> [code]
> module Simulations.SimFactory;
>
> import Simulations.ISimulation;
> import Simulations.CylVsSphere;
> import Simulations.CylBoxSlide;
> ...
> [/code]
>
> Linux linker respects the scope but window doesn't. I am using dmd 1.007
>
> Any suggestions? Should I submit a bugzilla?
> I really don't want to have a unique name for each collision callback function inside a module if I can avoid it.
I'll have a go at this one, but I'm just guessing...
The 'private' qualifier does "hide" is from the compiler's point of view.
But it is not so much "hiding" as "preventing access". That is, the
compiler will stop code in one module from trying to call a private
function in another module.
The "extern (C)" qualifier stops the compiler from mangling the name.
Without this qualifier, the compiler adds the module name, and the argument
signature to the name of a function in the object file. That means that two
functions with the same name, but in different modules get different
linkage names. However, by using "extern (C)" you override that so that
each module's object file will contain the same linkage name.
Why do you need to specify "extern (C)"?
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
26/02/2007 4:21:48 PM
More information about the Digitalmars-d
mailing list