Snippets‎ > ‎C++ Examples‎ > ‎

Hello World C++ Example for Cygwin

BY MARKUS SPRUNCK


You need a running installation of CYGWIN. If you haven't installed one, you may read Installing and Updating Cygwin for a detailed description. 

// Snippet #1 'hello.cpp'
#include <iostream>

int main() {
    std::cout << "Hello World!" << std::endl;
    return 0;
}
// Snippet #2 'makefile' 

This is a make file for gcc version 4.5.3 and target i686-pc-cygwin. 
TARGET    = hello.exe
OBJECT_01 = hello.o
SOURCE_01 = hello.cpp

$(TARGET): $(OBJECT_01)
   gcc -g -o $(TARGET) $(OBJECT_01) -lstdc++

$(OBJECT_01) : $(SOURCE_01)
   gcc -g -c $(SOURCE_01) -o $(OBJECT_01)

all : $(TARGET)

clean :
   -rm $(TARGET) $(OBJS)

Expected Result

Call make in the bash shell and don't forget to execute hello.exe with the current path (./hello.exe).


The file hello.exe has a size of 35.907 Bytes.

Links

Sponsored Link