Thread overview
optlink and weak symbols
Oct 17, 2012
Ellery Newcomer
Oct 17, 2012
Jacob Carlborg
Oct 18, 2012
Ellery Newcomer
Oct 18, 2012
Jacob Carlborg
Oct 18, 2012
Regan Heath
Oct 18, 2012
Ellery Newcomer
Oct 18, 2012
Jacob Carlborg
Oct 19, 2012
Ellery Newcomer
Oct 19, 2012
Jacob Carlborg
October 17, 2012
I am interfacing with some C code [python.dll], which has some structs declared like so:

PyTypeObject PyType_Type;

I wish to be able to link to PyType_Type like so:

extern(C) __gshared PyTypeObject PyType_Type;

in linux, I can do exactly that, but optlink is generating a new memory location for PyType_Type.

strings output suggests that my lib file contains the symbol PyType_Type.

Is this sort of thing supposed to work?
October 17, 2012
On 2012-10-17 07:07, Ellery Newcomer wrote:
> I am interfacing with some C code [python.dll], which has some structs
> declared like so:
>
> PyTypeObject PyType_Type;
>
> I wish to be able to link to PyType_Type like so:
>
> extern(C) __gshared PyTypeObject PyType_Type;
>
> in linux, I can do exactly that, but optlink is generating a new memory
> location for PyType_Type.
>
> strings output suggests that my lib file contains the symbol PyType_Type.
>
> Is this sort of thing supposed to work?

You need to declare the variable as "extern" if it's defined in the C code:

extern(C) extern __gshared PyTypeObject PyType_Type;

http://dlang.org/interfaceToC.html#C%20Globals

-- 
/Jacob Carlborg
October 18, 2012
On 10/16/2012 11:16 PM, Jacob Carlborg wrote:
>
> You need to declare the variable as "extern" if it's defined in the C code:
>
> extern(C) extern __gshared PyTypeObject PyType_Type;
>
> http://dlang.org/interfaceToC.html#C%20Globals
>

nice tip, but adding extern doesn't change link behavior at all.
October 18, 2012
On 2012-10-18 05:12, Ellery Newcomer wrote:

> nice tip, but adding extern doesn't change link behavior at all.

Hmm, are you linking with the DLL (the import library) ? In not, you need to use dlopen, or what the corresponding Windows function is.

-- 
/Jacob Carlborg
October 18, 2012
On Thu, 18 Oct 2012 07:41:16 +0100, Jacob Carlborg <doob@me.com> wrote:

> On 2012-10-18 05:12, Ellery Newcomer wrote:
>
>> nice tip, but adding extern doesn't change link behavior at all.
>
> Hmm, are you linking with the DLL (the import library) ? In not, you need to use dlopen, or what the corresponding Windows function is.

LoadLibrary[Ex]

R


-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
October 18, 2012
On 10/17/2012 11:41 PM, Jacob Carlborg wrote:
> On 2012-10-18 05:12, Ellery Newcomer wrote:
>
>> nice tip, but adding extern doesn't change link behavior at all.
>
> Hmm, are you linking with the DLL (the import library) ? In not, you
> need to use dlopen, or what the corresponding Windows function is.
>

I am using python27_digitalmars.lib, which is generated from libs\python27.lib with coffimplib, and it is linking my executables with python.dll.
October 18, 2012
On 2012-10-18 13:55, Ellery Newcomer wrote:

> I am using python27_digitalmars.lib, which is generated from
> libs\python27.lib with coffimplib, and it is linking my executables with
> python.dll.

Ok. Do you know how the corresponding C code would look like? Maybe you need to use the "export" attribute. It's the same as "__declspec(dllimport)", have a look:

http://dlang.org/htomodule.html

If that doesn't work then I'm out of suggestions, Windows is not my primary platform.

-- 
/Jacob Carlborg
October 19, 2012
On 10/18/2012 11:36 AM, Jacob Carlborg wrote:
> On 2012-10-18 13:55, Ellery Newcomer wrote:
>
>> I am using python27_digitalmars.lib, which is generated from
>> libs\python27.lib with coffimplib, and it is linking my executables with
>> python.dll.
>
> Ok. Do you know how the corresponding C code would look like? Maybe you
> need to use the "export" attribute. It's the same as
> "__declspec(dllimport)", have a look:
>
> http://dlang.org/htomodule.html
>
> If that doesn't work then I'm out of suggestions, Windows is not my
> primary platform.
>

ha HA!

extern(C) extern export PyTypeObject PyType_Type;

seems to do the trick (I'm using a boiled down case just now)!

High five to the [non-me] non-windows dev!
October 19, 2012
On 2012-10-19 02:30, Ellery Newcomer wrote:

> extern(C) extern export PyTypeObject PyType_Type;
>
> seems to do the trick (I'm using a boiled down case just now)!
>
> High five to the [non-me] non-windows dev!

Hehe, high five :)

-- 
/Jacob Carlborg