Hullo everyone,

i have declared a function in the same source file where my main function is. I have added the header files where the function is implemented but when i compile my code, i get linker errors "undefined reference to ....". Can someone please help me. Thanks.


Code:
int main()
{
    alt_fd* fd = NULL ; //needs to be initialized with some value
    typedef struct altera_16550_uart_state_s altera_16550_uart_state;
    altera_16550_uart_state* sp;
    struct alt_dev_s alt_dev;
    alt_u32 irq_controller_id;
    alt_u32 irq;
    
     /*Open File Descriptor*/

     int file_desc = alt_dev.open(fd,"/dev/ttyUSB0",0,O_RDWR|O_NOCTTY|O_NONBLOCK);

       //Error Handling
	if ( file_desc < 0 )
	{
	printf("Error beim oeffnen");
	}
   
   altera_16550_uart_init(sp,irq_controller_id,irq);
   

    return 0;
}

void altera_16550_uart_init(altera_16550_uart_state* sp, alt_u32 irq_controller_id,  alt_u32 irq)
{
    extern alt_llist alt_16550_uart_list;
    void* base = sp->base;
    int error;
    alt_u32 regs;
  

    error = (alt_dev_llist_insert((alt_dev_llist*) sp, &alt_16550_uart_list));
    /* Initialize UART register */
    /* Flush Tx and Rx FIFO */
    IOWR_ALTERA_16550_UART_FCR(base, ALTERA_16550_UART_FCR_FIFOE_MSK);
    IOWR_ALTERA_16550_UART_FCR(base, ALTERA_16550_UART_FCR_FIFOE_MSK |
                                     ALTERA_16550_UART_FCR_FIFOR_MSK |
                                     ALTERA_16550_UART_FCR_XFIFOR_MSK);
    IOWR_ALTERA_16550_UART_FCR(base, 0x0);
    /* Clear any Error status */
    IORD_ALTERA_16550_UART_LSR(sp->base);
    IORD_ALTERA_16550_UART_RBR(sp->base);
    IORD_ALTERA_16550_UART_IIR(sp->base);
    IORD_ALTERA_16550_UART_MSR(sp->base);
    /* Configure default settings */
    IOWR_ALTERA_16550_UART_LCR(base, ((ODD_PARITY << 4) | ALTERA_16550_UART_LCR_PEN_MSK
                                      | (STOPB_1 << 2)| CS_8));
#ifdef ALTERA_16550_UART_USE_IOCTL                                   
    sp->termios.c_cflag = PAODD | PARENB | CSTOPB | CS8;
    sp->termios.c_ispeed = sp->termios.c_ospeed = B9600;
#endif

    /*
     * Initialise the read and write flags and the semaphores used to
     * protect access to the circular buffers when running in a multi-threaded
     * environment.
     */
    error = ALT_FLAG_CREATE (&sp->events, 0)    ||
            ALT_SEM_CREATE (&sp->read_lock, 1)  ||
            ALT_SEM_CREATE (&sp->write_lock, 1);

    if (!error)
    {
        /* register the interrupt handler */
    #ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
        alt_ic_isr_register(irq_controller_id, irq, altera_16550_uart_irq, sp, 0x0);
    #else
        alt_irq_register (irq, sp, altera_16550_uart_irq);
    #endif
	
	    /* enable interrupts at the device */
        regs = IORD_ALTERA_16550_UART_IER(sp->base);
        regs |= ALTERA_16550_UART_IER_ERBFI_MSK  |
                ALTERA_16550_UART_IER_ETBEI_MSK;
        IOWR_ALTERA_16550_UART_IER(base, sp->ctrl);

    }
}
Errors

In function `altera_16550_uart_init':
Ergo.c.text+0x5c): undefined reference to `alt_16550_uart_list'
Ergo.c.text+0x60): undefined reference to `alt_16550_uart_list'
Ergo.c.text+0x64): undefined reference to `alt_dev_llist_insert'
Ergo.c.text+0x70): undefined reference to `IOWR'
Ergo.c.text+0x7a): undefined reference to `IOWR'
Ergo.c.text+0x84): undefined reference to `IOWR'
Ergo.c.text+0x90): undefined reference to `IORD'
Ergo.c.text+0x9c): undefined reference to `IORD'
Ergo.c.text+0xa8): undefined reference to `IORD'


collect2: error: ld returned 1 exit status