Mail Archives: cygwin/2002/02/08/06:06:01
PsychoSphere wrote:
> This is wrong... the .def file is never used when gcc
> is not linking a shared lib. You can see this by using
> a nonsense .def file, no errors are reported unless
> -shared is use
>
> I believe the __declspec(...) has a similar effect, in
> that it is ignored unless -shared is specified, or
> -mdll is used.
Ok, I didn't know that, but hey ... you learn almost every day
something new :)
> Also, the dllimport directive is never used unless an
> import library is created and used, which is not the
> idea here.
Well, that was my point - if you use dllexport you must
use dllimport, not LoadLibrary. Or maybe you can use it
but you must use the correct name - something like
__imp_foo_something and not just foo.
> The problem i beleive, is that gcc is unaware that the
> exe is going to be opened as a shared lib. I have some
Well, maybe this is the real problem - perhaps someone else
would comment too.
>
> Stephano Mariani
>
> Well, I think the problem is that you specify
> __declspec(dllexport) in
> the function declaration. If you do this then you're
> supposed to do
> extern __declspec(dllimport) void foo(void) in the
> source file
> which uses this function. If you want to use load
> library you have to
> remove the __declspec(dllexport) and replace it with
> an .def with
> EXPORTS section, then you list the exports in the .def
> file.
>
> just my 0.02 euro cents :P
>
> Larry Hall (RFK Partners, Inc) wrote:
>
>
>>I've never seen this attempted to access a function
>>
> not in a DLL, though
>
>>in theory (at least), what you're doing should work.
>>
>
>
>>Check the symbols in the resulting object file.
>>
> Make sure that the call
>
>>type is the same as you're referencing the function
>>
> by. In other words,
>
>>make sure that you call the function by the name as
>>
> the object file has
>
>>it (probably stdcall) rather than the name as you
>>
> write it (cdecl).
>
>>Change your definition call type or the calling name
>>
> itself so that the
>
>>call type matches. This might help.
>>
>>Larry Hall
>>
> lhall AT rfk DOT com
>
>>RFK Partners, Inc.
>>
> http://www.rfk.com
>
>>838 Washington Street (508)
>>
> 893-9779 - RFK Office
>
>>Holliston, MA 01746 (508)
>>
> 893-9889 - FAX
>
>>
>>
>>At 09:57 PM 2/6/2002, Kent Watsen wrote:
>>
>>
>>
>>>OK, so I've written the windows equivalent of my
>>>
> original program
>
>>>and still get the same error - is there some linking
>>>
> option I'm missine?
>
>>>Here is the new code, again just compile (gcc foo.c)
>>>
> and run (foo.exe):
>
>>>#include <stdio.h>
>>>#include <windows.h>
>>>
>>>extern __declspec(dllexport) void foo(void)
>>>{
>>> printf("hello\n");
>>>}
>>>
>>>int main(int argc, char *argv[])
>>>{
>>> void* dl = NULL;
>>> void* func = NULL;
>>>
>>> dl = (void *) GetModuleHandle (NULL);
>>> if (dl == NULL) {
>>> printf("GetModuleHandle() failed\n");
>>> exit(0);
>>> }
>>>
>>> func = (void*)GetProcAddress((HMODULE)dl, "foo");
>>> if (func == NULL) {
>>> printf("GetProcAddress() failed (code %u)\n",
>>>
> GetLastError());
>
>>> exit(0);
>>> }
>>>
>>> printf("do something meaningful\n");
>>>
>>> return 0;
>>>}
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>Kent Watsen wrote:
>>>
>>>
>>>
>>>>Hi,
>>>>
>>>>I've read the mailing list archives and searched
>>>>
> google trying
>
>>>>to figure out how to get the following program to
>>>>
> work. All
>
>>>>you have to do is save it to a file (foo.c),
>>>>
> compile (gcc foo.c),
>
>>>>and run - I always get "dlsym() failed."
>>>>
>>>>Note, I have tried many variations of extern and
>>>>
> _declspec
>
>>>>as well as looking for "_foo" in addition to "foo"
>>>>
> ("nm a.exe |
>
>>>>grep foo" returned "0040104c T _foo"...
>>>>
>>>>Here is the code - help would be greatly
>>>>
> appreciated - thanks!
>
>>>>#include <stdio.h>
>>>>#include <dlfcn.h>
>>>>#include <windows.h>
>>>>
>>>>extern __declspec(dllexport) void foo(void)
>>>>{
>>>> printf("hello\n");
>>>>}
>>>>
>>>>int main(int argc, char *argv[])
>>>>{
>>>> void* dl = NULL;
>>>> void* func = NULL;
>>>>
>>>> dl = dlopen(0 , RTLD_LAZY);
>>>> if (dl == NULL) {
>>>> printf("dlopen() failed\n");
>>>> exit(0);
>>>> }
>>>>
>>>> func = dlsym(dl, "foo");
>>>> if (func == NULL) {
>>>> printf("dlsym() failed\n");
>>>> exit(0);
>>>> }
>>>>
>>>> printf("do something meaningful\n");
>>>>
>>>> dlclose(dl);
>>>> return 0;
>>>>}
>>>>
>>>>
>>>>
>>>>
>>>>--
>>>>Unsubscribe info:
>>>>
> http://cygwin.com/ml/#unsubscribe-simple
>
>>>>Bug reporting: http://cygwin.com/bugs.html
>>>>Documentation: http://cygwin.com/docs.html
>>>>FAQ: http://cygwin.com/faq/
>>>>
>>>>
>>>
>>>--
>>>Unsubscribe info:
>>>
> http://cygwin.com/ml/#unsubscribe-simple
>
>>>Bug reporting: http://cygwin.com/bugs.html
>>>Documentation: http://cygwin.com/docs.html
>>>FAQ: http://cygwin.com/faq/
>>>
>>>
>>
>>--
>>Unsubscribe info:
>>
> http://cygwin.com/ml/#unsubscribe-simple
>
>>Bug reporting: http://cygwin.com/bugs.html
>>Documentation: http://cygwin.com/docs.html
>>FAQ: http://cygwin.com/faq/
>>
>>
>>
>>
>>
>
>
>
> --
> Unsubscribe info:
> http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting: http://cygwin.com/bugs.html
> Documentation: http://cygwin.com/docs.html
> FAQ: http://cygwin.com/faq/
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Send FREE Valentine eCards with Yahoo! Greetings!
> http://greetings.yahoo.com
>
>
>
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -