Discussion:
dllimport vs gcc
(too old to reply)
Paul Edwards
2020-04-03 12:58:58 UTC
Permalink
Hi all.

I am receiving messages like this on my main project:

Info: resolving ***@0 by linking to ***@0 (auto-import)
nmth000000.o(.idata$4+0x0): undefined reference to `***@0'

which go away if I add __declspec(dllimport) to the prototype
for GetCommandLineA (etc).

They also go away if I build my kernel32.c
code with Cygwin gcc instead of my own
custom-built gcc 3.2.3.

I'm not sure if adding dllimport is the
correct technical solution or not. Or if
my gcc is broken (and if so, whether it can
be fixed).

I have simplified the problem to a test
case which you can see here:

C:\devel\pdos\src\zzz>type k.c
/*__declspec(dllexport)*/ int foo(void)
{
return (5);
}

C:\devel\pdos\src\zzz>type main.c
/*__declspec(dllimport)*/ int foo(void);

int main(void)
{
return (foo());
}

void __main(void)
{
}

C:\devel\pdos\src\zzz>doit

C:\devel\pdos\src\zzz>gccwin -nostdinc -S -Os -I . k.c

C:\devel\pdos\src\zzz>aswin -o k.o k.s

C:\devel\pdos\src\zzz>del k.s

C:\devel\pdos\src\zzz>rem for some reason gccwin is not generating the correct

C:\devel\pdos\src\zzz>rem assembler code, so we override with gcc 4.8.2 from Cygwin

C:\devel\pdos\src\zzz>rem gcc -nostdinc -c -Os -I . k.c

C:\devel\pdos\src\zzz>ldwin -s -o k.dll --shared --kill-at k.o

C:\devel\pdos\src\zzz>dlltwin -S aswin -k --export-all-symbols -D k.dll k.o -l libk.a

C:\devel\pdos\src\zzz>gccwin -S -Os -I . -o main.s main.c

C:\devel\pdos\src\zzz>aswin -o main.o main.s

C:\devel\pdos\src\zzz>del main.s

C:\devel\pdos\src\zzz>ldwin -s -o main.exe main.o -lk -L.
Info: resolving _foo by linking to __imp__foo (auto-import)
ldwin: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
fu000001.o(.idata$3+0xc): undefined reference to `libk_a_iname'
nmth000000.o(.idata$4+0x0): undefined reference to `_nm__foo'



Any ideas?

Thanks. Paul.
Paul Edwards
2020-04-03 13:17:11 UTC
Permalink
A bit more information.

Here is the bad assembler produced by my
custom GCC 3.2.3:

C:\devel\pdos\src\zzz>type bad.s
.file "k.c"
.text
.globl _foo
_foo:
pushl %ebp
movl %esp, %ebp
movl $5, %eax
leave
ret



Here is Cygwin GCC 4.8.2:

C:\devel\pdos\src\zzz>type good.s
.file "k.c"
.text
.globl _foo
.def _foo; .scl 2; .type 32; .endef
_foo:
LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl $5, %eax
movl %esp, %ebp
.cfi_def_cfa_register 5
popl %ebp
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE0:
.ident "GCC: (GNU) 4.8.2"


I notice this:

.def _foo; .scl 2; .type 32; .endef

But don't know what it means.

Thanks. Paul.

Loading...