By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

Unix, "hello world"

P: n/a
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


From the hello world page:

#include <iostream>

int main()
{
std::cout << "Hello, world!\n";
}

If you are interested in various ways of doing hello world, you might find

http://www2.latech.edu/~acm/HelloWorld.shtml

ammusing.
Best

Kai-Uwe
Jul 22 '05 #2

P: n/a
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


#include <iostream>

int main()
{
std::cout << "hello world" << std::endl;
return 0;
}

- Pete
Jul 22 '05 #3

P: n/a
Matthew posted:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


#include <iostream>

int main(void)
{
std::cout << "Hello World!!";
}
Jul 22 '05 #4

P: n/a
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


Visual C++, AFAIK, is only capable of creating executable that run
on MS Windows. Older versions could create MS-DOS executables, and
there is a cross-compiler for Mac OS.

There is another way, though. You could use a third-party product
to run a Windows executable on Unix. I've heard of WinE and VMWare.
Both are kind of "virtual machines". They would run the executable,
but slower and with limited access to OS resources.

One thing you should know, every Unix-clone OS comes with its own
version of a C compiler (and often with a C++ compiler too). So,
in order to create a program on Unix, you don't need Visual C++.

Also, it's all irrelevant to comp.lang.c++ because it's all platform
specific. Please ask the question about creating an executable from
your code either in a newsgroup for your OS or for your compiler.

V
Jul 22 '05 #5

P: n/a
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.


Well, first, I'd trash VC and get a compiler that generates Unix
executables...
Jul 22 '05 #6

P: n/a
Matthew wrote:
How would I go about creating a simple "hello world" program that will
run in UNIX. I am using MS Visual C++.


You've got a few answers, but not really the whole picture yet.

Box, Pete and Kop showed you how to write source code that's portable to
UNIX. Just use only the ANSI interface, like what Bjarne Stroustrup
describes in The C++ Programming Language, and you'll be good.

To do much else in UNIX, you'll need to use POSIX, which is an API that
most, if not all, UNIX systems support fully, so you should check it
out. Any good book that talks about UNIX programming will cover POSIX.
Example: Advanced Programming in the UNIX Environment, by W. R. Stevens.

That's how to write code for UNIX.

The next group is talking about cross compilers. A cross compiler
compiles on one type of system (example: Win 32) to a different type of
system (example: UNIX). I can't think of any cross compilers off the
top of my head. GCC (the GNU compiler) will do it, but it's very
complicated. If someone hasn't made and maintain binaries to do what
you want, it may not be worth it to try to do this yourself. The GCC
Cross-Copmile HOWTO is stale (old, out-of-date) and might not be of much
help.

The alternative is to use a library to do your dirty work for you. Wine
was mentioned (www.winehq.org). This library emulates most (not all)
windows function calls, which allows you to run BINARY windows programs
on a UNIX system. I think it'll even run .exe files directly. Check it
out if this sounds like what you are after.

There are also libraries that allow UNIX programs to run on windows.
Cygwin (www.cygwin.com) is free and gives you an environment for running
UNIX programs. Cygwin also gives you a full UNIX development
environment, so this maybe is something you should consider seriously.
Instead of tediously switching computers to test your UNIX programs, or
using a dual-boot setup, you could just run cygwin and test and develop
there, and learn something about UNIX itself at the same time. All this
without ever having to leave windows! Plus it's free. Definitely check
this out.

Also, MinGW (www.mingw.org) is a free gcc compiler for windows. It only
gives you about 80% of the POSIX environment, but runs native UNIX
programs. It's better integrated into windows than Cygwin. And it can
even run UNIX configure scripts (with MSYS, available on the same site).
But it's not a full unix environment, just a gcc compiler for windows.
It's really designed for moving from UNIX to windows with GCC, not the
other way around. But it's still good so you might want to look at it.

Finally, the best way to go might just to get some neutral (neither
Win32 nor POSIX) library. This is the way to go if you're starting from
scratch (if you're porting a large existing code base, look into the
emulation libraries above). wxWindows (www.wxwindows.com) is a portable
GUI library that gives you much more than just POSIX (no GUI in POSIX),
and is also portable to a large number of systems, win32, UNIX and
UNIX-like. There's also SDL (www.libsdl.org) which is similar to
wxWindows but lighter weight and designed for media (games, etc.) type apps.

There you go!

Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.