Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MinGW - some APIs are undefined for console programs

14 views
Skip to first unread message

Charlie Gibbs

unread,
May 16, 2022, 7:49:34 PM5/16/22
to
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.
\ / <cgi...@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

JJ

unread,
May 17, 2022, 8:01:24 PM5/17/22
to
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.

Charlie Gibbs

unread,
May 18, 2022, 2:09:17 AM5/18/22
to
On 2022-05-18, JJ <jj4p...@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.
\ / <cgi...@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.

ElChino

unread,
Jun 5, 2022, 6:21:52 AM6/5/22
to
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.

Charlie Gibbs

unread,
Jun 5, 2022, 3:40:55 PM6/5/22
to
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.
0 new messages