* How to handle variables (data, etc.) in DLLs?
@ 1999-03-03 6:07 T J Harding
[not found] ` < 36DD41B4.BF1C00D7@quadstone.com >
1999-03-31 19:45 ` T J Harding
0 siblings, 2 replies; 8+ messages in thread
From: T J Harding @ 1999-03-03 6:07 UTC (permalink / raw)
To: cygwin
Hi
I was porting something to Cygwin and all was going swimmingly, until I
ran into problems building a DLL from object code with global data
symbols (i.e.
nm shows these symbols as type D or C).
Just to make it clearer, a trivial example:
main.c might contain:
extern int foo;
extern void bar(void);
int main ( int argc, char **argv )
{
foo++;
bar();
}
and foo.c might contain:
int foo=0;
void bar(void)
{
foo--;
}
It is foo.o that I want to include in a DLL.
I was using dllwrap 0.2.4 (and dlltool 2.9.4) with b20.1 (95 and NT).
"dllwrap --export-all-symbols" exports the data symbols to the .def
file, but
they seem to be exported as if they were functions, resulting in a core
dump
when a.exe is run. I've tried putting "DATA" after the symbol name in
the
.def file, which results in the symbol being undefined in the import-lib
libfoo.a, meaning I have to link foo.o in as well as libfoo.a.
So how should one best deal with this situation? It's not my code, so I
don't
want to have to alter it significantly just to port it.
Tim
begin:vcard
n:Harding;Tim
tel;cell:+44 961 444986
tel;fax:+44 131 220 4492
tel;work:+44 131 220 4491
x-mozilla-html:TRUE
url:www.quadstone.com
org:Quadstone
adr:;;16 Chester Street;Edinburgh;Scotland;EH3 7RA;United Kingdom
version:2.1
email;internet:tjh@quadstone.com
title:Decisionhouse Services
x-mozilla-cpt:;-1080
fn:Tim Harding
end:vcard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to handle variables (data, etc.) in DLLs?
[not found] ` < 36DD41B4.BF1C00D7@quadstone.com >
@ 1999-03-03 8:19 ` DJ Delorie
1999-03-04 1:32 ` T J Harding
1999-03-31 19:45 ` DJ Delorie
0 siblings, 2 replies; 8+ messages in thread
From: DJ Delorie @ 1999-03-03 8:19 UTC (permalink / raw)
To: tjh; +Cc: cygwin
DLLs *can't* export "data". They can only export pointers to data,
which is what they do. In older gccs, you'll need to do something
like this:
extern int *__imp_foo;
#define foo (*__imp_foo)
In newer gccs, do something like this:
extern int foo __attribute__((dllimport));
These tell gcc to dereference the imported pointer, rather than
thinking it's the data itself.
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to handle variables (data, etc.) in DLLs?
1999-03-03 8:19 ` DJ Delorie
@ 1999-03-04 1:32 ` T J Harding
[not found] ` < 36DE5309.24E587FB@quadstone.com >
1999-03-31 19:45 ` T J Harding
1999-03-31 19:45 ` DJ Delorie
1 sibling, 2 replies; 8+ messages in thread
From: T J Harding @ 1999-03-04 1:32 UTC (permalink / raw)
To: DJ Delorie; +Cc: cygwin
DJ Delorie wrote:
> DLLs *can't* export "data". They can only export pointers to data,
> which is what they do. In older gccs, you'll need to do something
> like this:
>
> extern int *__imp_foo;
> #define foo (*__imp_foo)
>
> In newer gccs, do something like this:
>
> extern int foo __attribute__((dllimport));
>
> These tell gcc to dereference the imported pointer, rather than
> thinking it's the data itself.
Thanks, that's useful to know (although there are about 250 of these
data symbols in the code!). I'd need to brush up on my C++ (yes, this
is actually C++ code) to figure out what's required.
Tim
begin:vcard
n:Harding;Tim
tel;cell:+44 961 444986
tel;fax:+44 131 220 4492
tel;work:+44 131 220 4491
x-mozilla-html:TRUE
url:www.quadstone.com
org:Quadstone
adr:;;16 Chester Street;Edinburgh;Scotland;EH3 7RA;United Kingdom
version:2.1
email;internet:tjh@quadstone.com
title:Decisionhouse Services
x-mozilla-cpt:;-1080
fn:Tim Harding
end:vcard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to handle variables (data, etc.) in DLLs?
[not found] ` < 36DE5309.24E587FB@quadstone.com >
@ 1999-03-04 15:13 ` Mikey
1999-03-31 19:45 ` Mikey
0 siblings, 1 reply; 8+ messages in thread
From: Mikey @ 1999-03-04 15:13 UTC (permalink / raw)
To: T J Harding, cygwin
yourfile.h
#define extern __attribute__((dllimport))
extern int yourdata_in_dll;
#undef extern
not sure about egcs-1.1 but 1.1.1 this will work.
On Thu, 04 Mar 1999 09:31:53 +0000, you wrote:
>DJ Delorie wrote:
>
>> DLLs *can't* export "data". They can only export pointers to data,
>> which is what they do. In older gccs, you'll need to do something
>> like this:
>>
>> extern int *__imp_foo;
>> #define foo (*__imp_foo)
>>
>> In newer gccs, do something like this:
>>
>> extern int foo __attribute__((dllimport));
>>
>> These tell gcc to dereference the imported pointer, rather than
>> thinking it's the data itself.
>
>Thanks, that's useful to know (although there are about 250 of these
>data symbols in the code!). I'd need to brush up on my C++ (yes, this
>is actually C++ code) to figure out what's required.
>
>Tim
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to handle variables (data, etc.) in DLLs?
1999-03-04 15:13 ` Mikey
@ 1999-03-31 19:45 ` Mikey
0 siblings, 0 replies; 8+ messages in thread
From: Mikey @ 1999-03-31 19:45 UTC (permalink / raw)
To: T J Harding, cygwin
yourfile.h
#define extern __attribute__((dllimport))
extern int yourdata_in_dll;
#undef extern
not sure about egcs-1.1 but 1.1.1 this will work.
On Thu, 04 Mar 1999 09:31:53 +0000, you wrote:
>DJ Delorie wrote:
>
>> DLLs *can't* export "data". They can only export pointers to data,
>> which is what they do. In older gccs, you'll need to do something
>> like this:
>>
>> extern int *__imp_foo;
>> #define foo (*__imp_foo)
>>
>> In newer gccs, do something like this:
>>
>> extern int foo __attribute__((dllimport));
>>
>> These tell gcc to dereference the imported pointer, rather than
>> thinking it's the data itself.
>
>Thanks, that's useful to know (although there are about 250 of these
>data symbols in the code!). I'd need to brush up on my C++ (yes, this
>is actually C++ code) to figure out what's required.
>
>Tim
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* How to handle variables (data, etc.) in DLLs?
1999-03-03 6:07 How to handle variables (data, etc.) in DLLs? T J Harding
[not found] ` < 36DD41B4.BF1C00D7@quadstone.com >
@ 1999-03-31 19:45 ` T J Harding
1 sibling, 0 replies; 8+ messages in thread
From: T J Harding @ 1999-03-31 19:45 UTC (permalink / raw)
To: cygwin
Hi
I was porting something to Cygwin and all was going swimmingly, until I
ran into problems building a DLL from object code with global data
symbols (i.e.
nm shows these symbols as type D or C).
Just to make it clearer, a trivial example:
main.c might contain:
extern int foo;
extern void bar(void);
int main ( int argc, char **argv )
{
foo++;
bar();
}
and foo.c might contain:
int foo=0;
void bar(void)
{
foo--;
}
It is foo.o that I want to include in a DLL.
I was using dllwrap 0.2.4 (and dlltool 2.9.4) with b20.1 (95 and NT).
"dllwrap --export-all-symbols" exports the data symbols to the .def
file, but
they seem to be exported as if they were functions, resulting in a core
dump
when a.exe is run. I've tried putting "DATA" after the symbol name in
the
.def file, which results in the symbol being undefined in the import-lib
libfoo.a, meaning I have to link foo.o in as well as libfoo.a.
So how should one best deal with this situation? It's not my code, so I
don't
want to have to alter it significantly just to port it.
Tim
begin:vcard
n:Harding;Tim
tel;cell:+44 961 444986
tel;fax:+44 131 220 4492
tel;work:+44 131 220 4491
x-mozilla-html:TRUE
url:www.quadstone.com
org:Quadstone
adr:;;16 Chester Street;Edinburgh;Scotland;EH3 7RA;United Kingdom
version:2.1
email;internet:tjh@quadstone.com
title:Decisionhouse Services
x-mozilla-cpt:;-1080
fn:Tim Harding
end:vcard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to handle variables (data, etc.) in DLLs?
1999-03-04 1:32 ` T J Harding
[not found] ` < 36DE5309.24E587FB@quadstone.com >
@ 1999-03-31 19:45 ` T J Harding
1 sibling, 0 replies; 8+ messages in thread
From: T J Harding @ 1999-03-31 19:45 UTC (permalink / raw)
To: DJ Delorie; +Cc: cygwin
DJ Delorie wrote:
> DLLs *can't* export "data". They can only export pointers to data,
> which is what they do. In older gccs, you'll need to do something
> like this:
>
> extern int *__imp_foo;
> #define foo (*__imp_foo)
>
> In newer gccs, do something like this:
>
> extern int foo __attribute__((dllimport));
>
> These tell gcc to dereference the imported pointer, rather than
> thinking it's the data itself.
Thanks, that's useful to know (although there are about 250 of these
data symbols in the code!). I'd need to brush up on my C++ (yes, this
is actually C++ code) to figure out what's required.
Tim
begin:vcard
n:Harding;Tim
tel;cell:+44 961 444986
tel;fax:+44 131 220 4492
tel;work:+44 131 220 4491
x-mozilla-html:TRUE
url:www.quadstone.com
org:Quadstone
adr:;;16 Chester Street;Edinburgh;Scotland;EH3 7RA;United Kingdom
version:2.1
email;internet:tjh@quadstone.com
title:Decisionhouse Services
x-mozilla-cpt:;-1080
fn:Tim Harding
end:vcard
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to handle variables (data, etc.) in DLLs?
1999-03-03 8:19 ` DJ Delorie
1999-03-04 1:32 ` T J Harding
@ 1999-03-31 19:45 ` DJ Delorie
1 sibling, 0 replies; 8+ messages in thread
From: DJ Delorie @ 1999-03-31 19:45 UTC (permalink / raw)
To: tjh; +Cc: cygwin
DLLs *can't* export "data". They can only export pointers to data,
which is what they do. In older gccs, you'll need to do something
like this:
extern int *__imp_foo;
#define foo (*__imp_foo)
In newer gccs, do something like this:
extern int foo __attribute__((dllimport));
These tell gcc to dereference the imported pointer, rather than
thinking it's the data itself.
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1999-03-31 19:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-03 6:07 How to handle variables (data, etc.) in DLLs? T J Harding
[not found] ` < 36DD41B4.BF1C00D7@quadstone.com >
1999-03-03 8:19 ` DJ Delorie
1999-03-04 1:32 ` T J Harding
[not found] ` < 36DE5309.24E587FB@quadstone.com >
1999-03-04 15:13 ` Mikey
1999-03-31 19:45 ` Mikey
1999-03-31 19:45 ` T J Harding
1999-03-31 19:45 ` DJ Delorie
1999-03-31 19:45 ` T J Harding
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).