• MinGW - some APIs are undefined for console programs

    From Charlie Gibbs@21:1/5 to All on Mon May 16 23:49:29 2022
    Are there any MinGW gurus out there? Or is there a better place
    to ask these questions?

    I wrote a suite of programs years ago; I've been compiling
    the Win32 versions (a mix of console and GUI programs) with
    Borland C++ Builder. I'd like to switch to MinGW so I can
    use a more modern, advanced compiler. (I've been compiling
    Linux versions of these programs under gcc 8.)

    My ultimate goal is to build the latest version of OpenSSL, 3.0.2
    (which probably can't be done with the Borland compiler), and link it
    with the programs in my suite which support SSL. Ditto for LibSSH2.
    OpenSSL comes with build instructions for MinGW.

    I've installed MinGW and have successfully compiled and run small
    test programs, both console and GUI. So far, though, I've not
    succeeded in getting my suite to compile (although a few of the
    simplest programs, both console and GUI, do compile and run).
    The program I'm currently trying to compile is a console program
    which comes up with the following messages:

    gcc -c revdate.c
    gcc -DWIN32 -DMINGW -Wall -Wno-format-overflow -c adjcost.c
    gcc -Wall -Wl,--allow-multiple-definition -o MinGW/adjcost.exe adjcost.o revdate.o MinGW/genesis.a
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x4aea): undefined reference to `_imp__GetTextExtentPoint32A@16'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x580a): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5836): undefined reference to `_imp__GetTextMetricsA@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x592c): undefined reference to `_imp__GetDeviceCaps@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5a57): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x6e11): undefined reference to `_imp__GetTextMetricsA@8'
    collect2.exe: error: ld returned 1 exit status
    make: *** [MinGW/adjcost.exe] Error 1

    Yes, I know that these APIs are normally only used in GUI programs,
    but they're a part of a private library I link with all my programs,
    GUI or console. The Borland compiler handles this with no complaints.
    If I add the -mwindows parameter to the gcc calls, the error messages disappear. But I want a console program, not a GUI program; besides,
    for GUI programs compiled with MinGW, printf() doesn't print anything.

    There are other problems (see the -Wl,--allow-multiple-definition
    parameter above), but getting rid of the error messages above seems
    like a good place to start.

    Is there a good source of documentation for building Windows programs
    with MinGW? I've searched high and low, but when it comes down to the nitty-gritty I've found little information, especially on the magical incantations to include needed libraries (e.g. -lws2_32 for sockets,
    something I only found out from back-handed references in various
    discussion groups).

    If anyone can help, or point me to a better newsgroup, web site,
    or documentation source, I'd really appreciate it.

    --
    /~\ Charlie Gibbs | Life is perverse.
    \ / <cgibbs@kltpzyxm.invalid> | It can be beautiful...
    X I'm really at ac.dekanfrus | but it won't.
    / \ if you read it the right way. | -- Lily Tomlin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to Charlie Gibbs on Wed May 18 07:01:22 2022
    On Mon, 16 May 2022 23:49:29 GMT, Charlie Gibbs wrote:
    Are there any MinGW gurus out there? Or is there a better place
    to ask these questions?

    I wrote a suite of programs years ago; I've been compiling
    the Win32 versions (a mix of console and GUI programs) with
    Borland C++ Builder. I'd like to switch to MinGW so I can
    use a more modern, advanced compiler. (I've been compiling
    Linux versions of these programs under gcc 8.)

    My ultimate goal is to build the latest version of OpenSSL, 3.0.2
    (which probably can't be done with the Borland compiler), and link it
    with the programs in my suite which support SSL. Ditto for LibSSH2.
    OpenSSL comes with build instructions for MinGW.

    I've installed MinGW and have successfully compiled and run small
    test programs, both console and GUI. So far, though, I've not
    succeeded in getting my suite to compile (although a few of the
    simplest programs, both console and GUI, do compile and run).
    The program I'm currently trying to compile is a console program
    which comes up with the following messages:

    gcc -c revdate.c
    gcc -DWIN32 -DMINGW -Wall -Wno-format-overflow -c adjcost.c
    gcc -Wall -Wl,--allow-multiple-definition -o MinGW/adjcost.exe adjcost.o revdate.o MinGW/genesis.a
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x4aea): undefined reference to `_imp__GetTextExtentPoint32A@16'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x580a): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5836): undefined reference to `_imp__GetTextMetricsA@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x592c): undefined reference to `_imp__GetDeviceCaps@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5a57): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x6e11): undefined reference to `_imp__GetTextMetricsA@8'
    collect2.exe: error: ld returned 1 exit status
    make: *** [MinGW/adjcost.exe] Error 1

    Yes, I know that these APIs are normally only used in GUI programs,
    but they're a part of a private library I link with all my programs,
    GUI or console. The Borland compiler handles this with no complaints.
    If I add the -mwindows parameter to the gcc calls, the error messages disappear. But I want a console program, not a GUI program; besides,
    for GUI programs compiled with MinGW, printf() doesn't print anything.

    There are other problems (see the -Wl,--allow-multiple-definition
    parameter above), but getting rid of the error messages above seems
    like a good place to start.

    Is there a good source of documentation for building Windows programs
    with MinGW? I've searched high and low, but when it comes down to the nitty-gritty I've found little information, especially on the magical incantations to include needed libraries (e.g. -lws2_32 for sockets, something I only found out from back-handed references in various
    discussion groups).

    If anyone can help, or point me to a better newsgroup, web site,
    or documentation source, I'd really appreciate it.

    You're missing the Windows' DLL import libraries which are available from Windows SDK. But I don't know if the LIB files from it, are usable by MingW, cause its a *nix origin. If not, you'll need to manually create the import library files from the DLLs. FYI, Borland C++ Builder works out of the box, because it already include most of the import libraries.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to jj4public@gmx.com on Wed May 18 06:09:14 2022
    On 2022-05-18, JJ <jj4public@gmx.com> wrote:

    On Mon, 16 May 2022 23:49:29 GMT, Charlie Gibbs wrote:

    <snip>

    I've installed MinGW and have successfully compiled and run small
    test programs, both console and GUI. So far, though, I've not
    succeeded in getting my suite to compile (although a few of the
    simplest programs, both console and GUI, do compile and run).
    The program I'm currently trying to compile is a console program
    which comes up with the following messages:

    <snip>

    You're missing the Windows' DLL import libraries which are available from Windows SDK. But I don't know if the LIB files from it, are usable by MingW, cause its a *nix origin. If not, you'll need to manually create the import library files from the DLLs. FYI, Borland C++ Builder works out of the box, because it already include most of the import libraries.

    That sounds kind of familiar. I did once manage to build OpenSSL 1.0.1g
    with the Borland compiler. I used Borland's implib utility to convert
    the OpenSSL DLLs to library files that the Borland linker could use.
    (I prefer to link statically.) What puzzles me in this case, though,
    is that the error messages I mentioned in my original post disapper
    if I include the -mwindows parameter; this suggests that the library
    must be there, although -mwindows has other undesirable effects.

    I can't find any documentation of the various -l parameters - the
    one I did see mentioned, -lws2_32, brings in the socket libraries,
    but that isn't too intuitive.

    --
    /~\ Charlie Gibbs | Microsoft is a dictatorship.
    \ / <cgibbs@kltpzyxm.invalid> | Apple is a cult.
    X I'm really at ac.dekanfrus | Linux is anarchy.
    / \ if you read it the right way. | Pick your poison.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From ElChino@21:1/5 to Charlie Gibbs on Sun Jun 5 12:21:49 2022
    Charlie Gibbs wrote:

    gcc -c revdate.c
    gcc -DWIN32 -DMINGW -Wall -Wno-format-overflow -c adjcost.c
    gcc -Wall -Wl,--allow-multiple-definition -o MinGW/adjcost.exe adjcost.o revdate.o MinGW/genesis.a
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x4aea): undefined reference to `_imp__GetTextExtentPoint32A@16'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x580a): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5836): undefined reference to `_imp__GetTextMetricsA@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x592c): undefined reference to `_imp__GetDeviceCaps@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5a57): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x6e11): undefined reference to `_imp__GetTextMetricsA@8'
    collect2.exe: error: ld returned 1 exit status
    make: *** [MinGW/adjcost.exe] Error 1

    Easy, add '-lgdi32' to the link-command.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to ElChino on Sun Jun 5 19:40:52 2022
    On 2022-06-05, ElChino <elchino@cnn.cn> wrote:

    Charlie Gibbs wrote:

    gcc -c revdate.c
    gcc -DWIN32 -DMINGW -Wall -Wno-format-overflow -c adjcost.c
    gcc -Wall -Wl,--allow-multiple-definition -o MinGW/adjcost.exe adjcost.o revdate.o MinGW/genesis.a
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x4aea): undefined reference to `_imp__GetTextExtentPoint32A@16'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x580a): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5836): undefined reference to `_imp__GetTextMetricsA@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x592c): undefined reference to `_imp__GetDeviceCaps@8'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x5a57): undefined reference to `_imp__TextOutA@20'
    c:/Strawberry/c/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: MinGW/genesis.a(gensubs.o):gensubs.c:(.text+0x6e11): undefined reference to `_imp__GetTextMetricsA@8'
    collect2.exe: error: ld returned 1 exit status
    make: *** [MinGW/adjcost.exe] Error 1

    Easy, add '-lgdi32' to the link-command.

    Thanks, I finally managed to puzzle that one out by running
    a "strings" command on the various .a files in MinGW\lib
    and searching for "TextOut". It's clunky, but it lets me
    figure out just what -l parameters I have to add for other
    things as well.

    --
    /~\ Charlie Gibbs | Life is perverse.
    \ / <cgibbs@kltpzyxm.invalid> | It can be beautiful...
    X I'm really at ac.dekanfrus | but it won't.
    / \ if you read it the right way. | -- Lily Tomlin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)