Get the GPS data -- SITL

Hello, i’m trying to learn ardupilot basic codes to costum a flight controller so i’am started to create a sketch to display thr gps measurements by i get this error, how can i fix! thanks.

#include <AP_HAL/AP_HAL.h>   
#include <AP_InertialSensor/AP_InertialSensor.h>
#include <AP_GPS/AP_GPS.h>
#include <AP_Compass/AP_Compass.h>
#include <AP_Param/AP_Param.h>
#include <GCS_MAVLink/GCS_Dummy.h>
#include <AP_Notify/AP_Notify.h>
#include <AP_Notify/AP_BoardLED.h>
#include <AP_SerialManager/AP_SerialManager.h>
#include <AP_BoardConfig/AP_BoardConfig.h>
#include <SITL/SITL.h>
#include <AP_Scheduler/AP_Scheduler.h>
#include <AP_AHRS/AP_AHRS.h>

void setup();                                                   //This function is defined in most of the libraries. This function is called only once at boot up time. This function is called by main() function in HAL.
void loop();                                                    //This function is defined in most of the libraries. This function is called by main function in HAL. The main work of the sketch is typically in this function only.

const AP_HAL::HAL& hal = AP_HAL::get_HAL();                     //Declare "hal" reference variable. This variable is pointing to Ap_HAL::HAL class's object. Here, AP_HAL is library and HAL is a class in that library. This reference variable can be used to get access to hardware specific functions.                     

static AP_BoardConfig board_config;


#if AP_NOTIFY_GPIO_LED_3_ENABLED
// create board led object
AP_BoardLED board_led;
#endif

// create fake gcs object
GCS_Dummy _gcs;                                                 //gcs stands for Ground Control Station

const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
        AP_GROUPEND
};

#if AP_SIM_ENABLED
SITL::SIM sitl;
AP_Baro baro;
AP_Scheduler scheduler;
#endif

// This example uses GPS system. Create it.
AP_InertialSensor ins;
AP_GPS gps;
// Serial manager is needed for UART communications
static AP_SerialManager serial_manager;

//to be called only once on boot for initializing objects
void setup()
{
    hal.console->printf("HELLO AUTO library test\n");

    board_config.init();

}

void print_latlon(AP_HAL::BetterStream *s, int32_t lat_or_lon);
void print_latlon(AP_HAL::BetterStream *s, int32_t lat_or_lon)
{
    int32_t dec_portion, frac_portion;
    int32_t abs_lat_or_lon = labs(lat_or_lon);                  //The labs() function in C++ returns the absolute value of a long or long int data.

    // extract decimal portion (special handling of negative numbers to ensure we round towards zero)
    dec_portion = abs_lat_or_lon / 10000000UL;

    // extract fractional portion
    frac_portion = abs_lat_or_lon - dec_portion*10000000UL;

    // print output including the minus sign
    if( lat_or_lon < 0 ) {
        s->printf("-");
    }
    s->printf("%ld.%07ld",(long)dec_portion,(long)frac_portion);
}
void loop()
{ 
  // Reset the time of message
        gps.update();  
        const Location &loc = gps.location();
        // Print the contents of message
           hal.console->printf("Lat: ");
        /*print_latlon(hal.console, loc.lat);
        */
       /*print_latlon(hal.console, loc.lng);*/
       hal.console->printf(" Altitude: %.2f meter",
                    (double)(loc.alt * 0.01f));  
  hal.scheduler->delay(10);     
}
// Register above functions in HAL board level
AP_HAL_MAIN();
$ ./build/sitl/examples/Hello_code  -M quad -C
Starting sketch 'UNKNOWN'
Starting SITL input
Using Irlock at port : 9005
ERROR: segmentation fault - aborting
Running: sh Tools/scripts/dumpstack.sh 34949 >dumpstack.sh_Hello_code.34949.out 2>&1
dumpstack.sh has been run.  Output was: