Unix, "hello world"

M

Matthew

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

Pete C.

Matthew said:
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
 
V

Victor Bazarov

Matthew said:
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
 
J

JKop

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!!";
}
 
R

red floyd

Matthew said:
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...
 
M

markspace

Matthew said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hello World! 2
Hello World 1
Hello world 1
Hello World 2
Hello! 2
Hello everyone ! 4
Hello everyone 0
Hello to community. 3

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top