Discussion:
MinGW - some APIs are undefined for console programs
(too old to reply)
Charlie Gibbs
2022-05-16 23:49:29 UTC
Permalink
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 `***@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 `***@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 `***@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 `***@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 `***@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 `***@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.
\ / <***@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
2022-05-18 00:01:22 UTC
Permalink
Post by Charlie Gibbs
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
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
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.
Charlie Gibbs
2022-05-18 06:09:14 UTC
Permalink
<snip>
Post by JJ
Post by Charlie Gibbs
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
<snip>
Post by JJ
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.
\ / <***@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
2022-06-05 10:21:49 UTC
Permalink
Post by Charlie Gibbs
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
collect2.exe: error: ld returned 1 exit status
make: *** [MinGW/adjcost.exe] Error 1
Easy, add '-lgdi32' to the link-command.
Charlie Gibbs
2022-06-05 19:40:52 UTC
Permalink
Post by ElChino
Post by Charlie Gibbs
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
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.
\ / <***@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
Loading...