 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Richard M. Ulrich Guest
|
Posted: Tue Mar 06, 2007 7:18 pm Post subject: ILINK32 options for simple hello world console program |
|
|
Hello,
I have BCB 6 Prof. My son is working through an online C++ course and I'm
trying to set up BCC32 and ILINK32 so that he can compile and run the sample
console programs, and am having a tough time getting the options (especially
linker options) to make it work.
The first program is very simple, and compiles fine:
#include <iostream.h>
void main()
{
cout << "Hello World";
}
When I link it, one of the following things happen: (1) unresolved external
__turboFloat, (2) unresolved external WinMain, or (3) it creates an EXE that
crashes and wants to tell Microsoft about it.
Ok, I give up. What are the parameters to give BCC32 and ILINK32 necessary
to say hello to the old DOS console?
Thanks!
--
Richard M. Ulrich
Ulrich Associates, Inc. |
|
| Back to top |
|
 |
Alan Bellingham Guest
|
Posted: Tue Mar 06, 2007 7:27 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
"Richard M. Ulrich" <RichardU (AT) UlrichAssociates (DOT) com> wrote:
| Quote: | My son is working through an online C++ course and I'm
trying to set up BCC32 and ILINK32 so that he can compile and run the sample
console programs, and am having a tough time getting the options (especially
linker options) to make it work.
The first program is very simple, and compiles fine:
#include <iostream.h
void main()
{
cout << "Hello World";
}
|
*cough*splutter*
Please let me know which online course this is, so that I can warn
people against it. The above is *not* valid C++. If they're giving it as
an example of the language, then I'd strongly distrust anything else
they taught.
I have BCB5, not BCB6, so I'm afraid I can't really help you with your
actual problem, but it's possibly worth mentioning that <iostream.h>
isn't a standard C++ header (unlike <iostream>), so there may be
problems due to that.
What happens with an actual C++ program?
#include <iostream>
int main()
{
std::cout << "Hello World";
}
Does that still cause problems?
Alan Bellingham
--
10th Anniversary ACCU Conference: 11-14 April 2007 - Oxford, UK
(Booking now open: see http://accu.org/index.php/conferences for details) |
|
| Back to top |
|
 |
Richard M. Ulrich Guest
|
Posted: Tue Mar 06, 2007 8:04 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
| Quote: |
*cough*splutter*
Please let me know which online course this is, so that I can warn
people against it. The above is *not* valid C++. If they're giving it as
an example of the language, then I'd strongly distrust anything else
they taught. [snip]
|
"OOP Using C++ Series", http://www.e-learningcenter.com/c_programming.htm
I'm not sure why you say the code is wrong ... to me, it just looks like
"old style" which is supposed to be supported, since there are mountains of
legacy code out there still using that style.
| Quote: |
What happens with an actual C++ program?
#include <iostream
int main()
{
std::cout << "Hello World";
}
|
Very puzzling.
I made the above changes (just two), and BCC32 compiled AND linked it with
no fuss.
Ok, so what is going on, I asked. I changed <iostream> back to
<iostream.h> and it still worked. I then changed std::cout back to cout and
.... it still worked! I reverted back to the version I KNOW did not work
before, and it works. Something peculiar is going on.
R |
|
| Back to top |
|
 |
Alan Bellingham Guest
|
Posted: Tue Mar 06, 2007 8:22 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
"Richard M. Ulrich" <RichardU (AT) UlrichAssociates (DOT) com> wrote:
| Quote: | I'm not sure why you say the code is wrong ... to me, it just looks like
"old style" which is supposed to be supported, since there are mountains of
legacy code out there still using that style.
|
main() should not return void. It never did in C, and it never did in
C++. (Java, allowably, is another matter.) Compilers will often accept
it - they're not required to fail to produce an executable in such a
case, but on the other hand, if BCB6 is refusing to generate something
valid here, it's not *technically* a bug, since it's not *technically* a
valid C++ program that you've fed it.
Sadly, a huge number of code examples do show void main(), with both
Borland and Microsoft ones among them.
Using <iostream.h>, which is a pre-standardisation header, is
potentially a bigger problem. That header may not exist. If it *does*
exist (and it usually will in *older* compilers), then it may differ in
all sorts of subtle ways from what <iostream> will provide. The student
may then think that the behaviour resulting from <iostream.h> is correct
and that from <iostream> is wrong when he encounters the latter.
For a course that supposedly teaches one how to do the right thing to
have two egregious errors in such a short example is worrying.
| Quote: | Ok, so what is going on, I asked. I changed <iostream> back to
iostream.h> and it still worked. I then changed std::cout back to cout and
... it still worked! I reverted back to the version I KNOW did not work
before, and it works. Something peculiar is going on.
|
Sometimes that can be the case. Something gets misbuilt (for whatever
reason), and then doesn't get rebuilt.
Alan Bellingham
--
10th Anniversary ACCU Conference: 11-14 April 2007 - Oxford, UK
(Booking now open: see http://accu.org/index.php/conferences for details) |
|
| Back to top |
|
 |
Richard M. Ulrich Guest
|
Posted: Tue Mar 06, 2007 8:38 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
| Quote: |
For a course that supposedly teaches one how to do the right thing to
have two egregious errors in such a short example is worrying.
|
I'd guess what is going on is that this course was developed 15 years ago,
and they have never updated it. Yes, worrying, because all sorts of other
things might be out of date.
Thanks for your help!
R |
|
| Back to top |
|
 |
Ebbe Kristensen Guest
|
Posted: Tue Mar 06, 2007 8:53 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
Alan Bellingham wrote:
| Quote: | *cough*splutter*
...
What happens with an actual C++ program?
#include <iostream
int main()
{
std::cout << "Hello World";
}
|
Shouldn't this be:
#include <iostream>
int main()
{
std::cout << "Hello World";
return 0;
}
in order to be correct? :-)
Ebbe |
|
| Back to top |
|
 |
Ed Mulroy Guest
|
Posted: Tue Mar 06, 2007 9:29 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
It is not a course but you might get something from this site. It deals
with beginning to use the command line compiler and tools and shows a hello
world example.
http://www.mulroy.org/howto.htm
Items specific to your situation:
- The compiler and linker are able to create an executable (EXE),
a dynamic linked library (DLL) and some other items. Each can
be created to be dynamic linked or static linked. You must tell
the tools what it is that you wish to create.
- If the command line option -c (or /c) is used then the compiler
will stop after compilation. If that option is omitted then it will
call the linker itself.
- To create a command line program give the option -WC to the
compiler. For dynamic linked either of the combination -WR -WC
or a single -WCR is used.
Assuming that your source file is hello.cpp then command lines
used might be:
Console mode, static linked, compiler calls linker
bcc32 -WC hello
Console mode, static linked, you call linker
bcc32 -c -WC hello
ilink32 /Tpe/ap/x/c/Gn c0x32 hello,hello,,import32 cw32
Console mode, dynamic linked, compiler calls linker
bcc32 -WCR hello
Console mode, dynamic linked, you call linker
bcc32 -c -WCR hello
ilink32 /Tpe/ap/x/c/Gn c0x32 hello,hello,,import32 cw32i
Mr Bellingham's comments about correctly following the language are valid
although I think at your level first getting something to work may be the
more important issue. Strict language compliance is an easier goal to
accept once one has achieved some results.
.. Ed
| Quote: | Richard M. Ulrich wrote in message
news:45ed69de$1 (AT) newsgroups (DOT) borland.com...
I have BCB 6 Prof. My son is working through an online C++ course and I'm
trying to set up BCC32 and ILINK32 so that he can compile and run the
sample console programs, and am having a tough time getting the options
(especially linker options) to make it work.
The first program is very simple, and compiles fine:
#include <iostream.h
void main()
{
cout << "Hello World";
}
When I link it, one of the following things happen: (1) unresolved
external __turboFloat, (2) unresolved external WinMain, or (3) it creates
an EXE that crashes and wants to tell Microsoft about it.
Ok, I give up. What are the parameters to give BCC32 and ILINK32
necessary to say hello to the old DOS console? |
|
|
| Back to top |
|
 |
Alan Bellingham Guest
|
Posted: Tue Mar 06, 2007 9:31 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
"Ebbe Kristensen" <ebbe (AT) ekologic (DOT) dk> wrote:
| Quote: | Shouldn't this be:
#include <iostream
int main()
{
std::cout << "Hello World";
return 0;
}
in order to be correct?
|
Well noticed!
Actually, there's a special case rule in C++ that says,
5 A return statement in main has the effect of leaving the main
function (destroying any objects with automatic storage duration) and
calling exit with the return value as the argument. If control
reaches the end of main without encountering a return statement, the
effect is that of executing
return 0;
(3.6.1 - [basic.start.main])
So your code and mine were directly equivalent. It should be noticed
that this rule about not needing to return a value applies only to
main(), which is a very special function indeed and has a whole section
devoted to the rules about it.
Alan Bellingham
--
10th Anniversary ACCU Conference: 11-14 April 2007 - Oxford, UK
(Booking now open: see http://accu.org/index.php/conferences for details) |
|
| Back to top |
|
 |
Richard M. Ulrich Guest
|
Posted: Thu Mar 08, 2007 7:18 pm Post subject: Re: ILINK32 options for simple hello world console program |
|
|
Thanks, Ed! I wish the Help system had given such examples!
| Quote: |
Mr Bellingham's comments about correctly following the language are valid
although I think at your level first getting something to work may be the
more important issue. Strict language compliance is an easier goal to
accept once one has achieved some results.
|
I suppose. As soon as he has figured out how classes and inheritance work,
I'll be having him switch to BCB rather than the command line tools. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|