public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: Compiler
@ 1997-10-28 18:40 Colin Peters
  1997-10-29  8:46 ` Compiler Jason Zions
  0 siblings, 1 reply; 9+ messages in thread
From: Colin Peters @ 1997-10-28 18:40 UTC (permalink / raw)
  To: swarnerx3; +Cc: gnu-win32

>>From: "Scott Warner" <swarnerx3@acadia.net>
>>
>>Having trouble compiling Win32 programs.  Keep getting "undefined
>>reference" errors.  Is there a SET missing so the compiler can find the
>>libs?

Probably the problem is that you are not actually telling it what libraries
to look for. You have to explicitly link in any Win32 API libraries you
need functions from (except for kernel32, which you should never explicitly
link). Try adding -luser32 and -lgdi32 to your link command line and I
think many of your undefined references will go away.

Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Compiler
  1997-10-28 18:40 Compiler Colin Peters
@ 1997-10-29  8:46 ` Jason Zions
  1997-10-29 14:47   ` Compiler Bizzaro
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Zions @ 1997-10-29  8:46 UTC (permalink / raw)
  To: Colin Peters; +Cc: gnu-win32

> You have to explicitly link in any Win32 API libraries you
> need functions from (except for kernel32, which you should never explicitly
> link).

I'm curious about this. Why should one never explicitly link kernel32?

Jason
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Compiler
  1997-10-29  8:46 ` Compiler Jason Zions
@ 1997-10-29 14:47   ` Bizzaro
  0 siblings, 0 replies; 9+ messages in thread
From: Bizzaro @ 1997-10-29 14:47 UTC (permalink / raw)
  To: GNU Win 32

Jason Zions wrote:
> 
> > You have to explicitly link in any Win32 API libraries you
> > need functions from (except for kernel32, which you should never explicitly
> > link).
> 
> I'm curious about this. Why should one never explicitly link kernel32?

because it is automatically linked in.  There is a program called depends (think
it was in the lcc zip, if you want it drop me a note) that will list what dll's
a program loads up.  Running it on anything compiled with cygwin shows that it
is being loaded, as well as several other dlls.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: Compiler
@ 1997-10-29 17:07 Colin Peters
  0 siblings, 0 replies; 9+ messages in thread
From: Colin Peters @ 1997-10-29 17:07 UTC (permalink / raw)
  To: 'Jason Zions'; +Cc: 'GNU-Win32'

Jason Zions[SMTP:jazz@softway.com] wrote:
>> You have to explicitly link in any Win32 API libraries you
>> need functions from (except for kernel32, which you should never explicitly
>> link).
>
>I'm curious about this. Why should one never explicitly link kernel32?

As someone else mentioned, because it is automatically linked in. Of course,
that isn't actually a good reason to not explicitly link a library (except
if you are concerned with making your links go faster). However, the linker
right now has problems if you link the same import library more than once.
The whole import table gets messed up and your programs will crash under
mysterious circumstances. Until this gets fixed the workaround is to be
very, very careful and make sure you never link the same import library
more than once. Since kernel32 is automatically linked, you should never
put it on your link command line.

This is a (reasonably) well known gotcha (at least for "old timers" on
the list <creak> <creak>). Lots of programmers, including myself, have
been caught running a seemingly innocuous command like this:

  gcc -o hello.exe hello.o -luser32 -lgdi32 -lkernel32

It links fine, but crashes quite spectacularly. Worse is when it doesn't
crash right away, but only when you call some API function or other. Bleah!

Hope that makes it all clear,
Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: Compiler
@ 1997-10-29  2:35 Colin Peters
  0 siblings, 0 replies; 9+ messages in thread
From: Colin Peters @ 1997-10-29  2:35 UTC (permalink / raw)
  To: 'Scott Warner'; +Cc: 'GNU-Win32'

Scott Warner[SMTP:swarnerx3@acadia.net] wrote:
>Thank you for your help.  Linking to the specific Windows libraries with
>-luser32 took care of most of the undefined references.  Still getting
>
>D:\gnuwin32\b18\H-i386-cygwin32\i386-cygwin32\lib/libcygwin.a(libcmain.o)(.t
>ext+0x1e):libcmain.cc: undefined reference to `WinMain@16'
>G__~1.EXE: Internal compiler error: program ld got fatal signal 1
>
>in a simple "Hello World!" type program.  Is there a command switch or
>environmental variable I am missing, or a library I am not linking?

This means, I think, that your WinMain is not prototyped/defined
"properly". It should look like this:

int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmd, int nShow)

Especially important is the STDCALL (WINAPI will also do I think)
which gets that @16 tacked onto the end of the function name
and makes it have the proper calling convention.

If that's not the problem then I'm afraid I don't know what's wrong.

Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Compiler
@ 1997-10-28 18:40 Scott Warner
  0 siblings, 0 replies; 9+ messages in thread
From: Scott Warner @ 1997-10-28 18:40 UTC (permalink / raw)
  To: gnu-win32

Thank you for your help.  Linking to the specific Windows libraries with
-luser32 took care of most of the undefined references.  Still getting

D:\gnuwin32\b18\H-i386-cygwin32\i386-cygwin32\lib/libcygwin.a(libcmain.o)(.t
ext+0x1e):libcmain.cc: undefined reference to `WinMain@16'
G__~1.EXE: Internal compiler error: program ld got fatal signal 1

in a simple "Hello World!" type program.  Is there a command switch or
environmental variable I am missing, or a library I am not linking?

I use

g++ -c -o winhello.o winhello.c
g++ -o winhello.exe winhello.o -luser32

Lastly, how do I reply directly to the mailing list?  (Instead of sending a
new message each time to gnu-win32@cygnus.com)

My purpose is to learn Windows 95 programming; I have been studying MFC
with MSVC 1.5, and want to program some simple Win 95 apps.  ("Learn the
basics")

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Compiler
@ 1997-10-28  5:38 Earnie Boyd
  0 siblings, 0 replies; 9+ messages in thread
From: Earnie Boyd @ 1997-10-28  5:38 UTC (permalink / raw)
  To: swarnerx3; +Cc: gnu-win32

>From: "Scott Warner" <swarnerx3@acadia.net>
>To: "Earnie Boyd" <earnie_boyd@hotmail.com>
>Subject: Re: Compiler
>Date: Mon, 27 Oct 1997 17:28:12 -0500
>
>Having trouble compiling Win32 programs.  Keep getting "undefined
>reference" errors.  Is there a SET missing so the compiler can find the
>libs?
>
>

Scott,

Don't reply directly to me, send your replys to the list 
(gnu-win32@cygnus.com).  I might not know the answer.

Also, be specific about the errors.  "undefined references" to what?  
Examples or package name you are compiling. Etc.


-        \\||//
---o0O0--Earnie--0O0o----
-earnie_boyd@hotmail.com-
------ooo0O--O0ooo-------


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Compiler
@ 1997-10-27  5:28 Earnie Boyd
  0 siblings, 0 replies; 9+ messages in thread
From: Earnie Boyd @ 1997-10-27  5:28 UTC (permalink / raw)
  To: swarnerx3; +Cc: gnu-win32

Let me point you to:

ftp://ftp.cygnus.com/pub/gnu-win32/latest/

http://www.cygnus.com/pubs/gnupro/

http://www.cygnus.com/misc/gnu-win32/

http://www.cygnus.com/ml/gnu-win32

http://www.fu.is.saga-u.ac.jp/~colin/gcc.html

-        \\||//
---o0O0--Earnie--0O0o----
-earnie_boyd@hotmail.com-
------ooo0O--O0ooo-------


>From: "Scott Warner" <swarnerx3@acadia.net>
>To: <gnu-win32@cygnus.com>
>Subject: Compiler
>Date: Sat, 25 Oct 1997 14:57:51 -0400
>
>Is this product a 32-bit C++ compiler that will access Windows 95 APIs? 
>Right now I have MSVC++ for 16 bit only and want to write Win95 apps.
>
>-
>For help on using this list (especially unsubscribing), send a message 
to
>"gnu-win32-request@cygnus.com" with one line of text: "help".
>


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Compiler
@ 1997-10-25 12:02 Scott Warner
  0 siblings, 0 replies; 9+ messages in thread
From: Scott Warner @ 1997-10-25 12:02 UTC (permalink / raw)
  To: gnu-win32

Is this product a 32-bit C++ compiler that will access Windows 95 APIs? 
Right now I have MSVC++ for 16 bit only and want to write Win95 apps.

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1997-10-29 17:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-28 18:40 Compiler Colin Peters
1997-10-29  8:46 ` Compiler Jason Zions
1997-10-29 14:47   ` Compiler Bizzaro
  -- strict thread matches above, loose matches on Subject: below --
1997-10-29 17:07 Compiler Colin Peters
1997-10-29  2:35 Compiler Colin Peters
1997-10-28 18:40 Compiler Scott Warner
1997-10-28  5:38 Compiler Earnie Boyd
1997-10-27  5:28 Compiler Earnie Boyd
1997-10-25 12:02 Compiler Scott Warner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).