Linking a C++ Hello World Application for macOS

From RAD Studio
Jump to: navigation, search

Go Up to XLINK.EXE, the macOS Linker

ILinkOSX.exe links the .a and .o files into a macOS application. Executable Mac app files typically have no file extension.

Application code

 
//hello.cpp 
#include<iostream> 
#include<string> 
int main(int, char**) 
{ 
  std::string s("Hello world"); 
  std::cout<<s; 
  return 0; 
}

Compiling

You can compile this source using:

> bccosx -c hello.cpp

You can alternatively remove the -c option and let the compiler invoke the linker if possible. This way the compiler can determine the correct library paths and set the linker options as appropriate.

Linking

Then link the .a and .o files into the App using the following command:

> xlink.exe hello.o start.o,hello,,libSystem.dylib libcgrtl.a libcgstl.a libcgunwind.1.0.dylib,, 

Now run the hello app, and you will see "Hello world" print on the screen.

Topics

See Also