tree: 29761ae4bc790a9aa5cf1e490cda8ebec5082525 [path history] [tgz]
  1. meta/
  2. test/
  3. BUILD.gn
  4. hello.cc
  5. hello_shared.cc
  6. hello_shared.h
  7. hello_static.cc
  8. hello_static.h
  9. README.md
src/hello_world/README.md

Hello World Example

The Hello, World sample introduces a Fuchsia component that prints “Hello, world” messages to the system log. The BUILD.gn file contains rules that demonstrate building a single binar with shared and static libraries as dependencies.

Source layout

  • hello.cc: Main entrypoint for the component binary
  • hello_shared: Shared library exposing functions to retrieve a greeting
  • hello_static: Static library exposing functions to retrieve a greeting

Before you begin

  1. Start a FEMU instance:

    $ ./third_party/fuchsia-sdk/bin/femu.sh -N
    
  2. Start a local package repository instance:

    $ ./third_party/fuchsia-sdk/bin/fserve.sh --image qemu-x64
    

Build the sample

  1. Run the build script to compile and package the sample:

    $ ./scripts/build.sh
    
  2. Publish the FAR package to your local package repository:

    $ ./third_party/fuchsia-sdk/bin/fpublish.sh out/x64/hello_world.far
    

Run the sample

  1. Launch the sample component using ffx component run. This resolves the component from the package repository and starts it:

    $ ffx component run fuchsia-pkg://fuchsia.com/hello_world#meta/hello_world.cm
    
  2. View the greeting messages in the system log using ffx target log:

    $ ffx target log watch
    ...
    [hello_world][I] pthreads: hello
    [hello_world][I] Hello, world
    [hello_world][I] cppthreads: hello