-
April 7th, 2015, 08:04 AM
#1
Linker error undefined reference to .....
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
-
April 7th, 2015, 08:07 AM
#2
Re: Linker error undefined reference to .....
Looks like you may be confusing altera_16550_uart_init and alt_16550_uart_init
-
April 7th, 2015, 08:12 AM
#3
Re: Linker error undefined reference to .....
Code:
extern alt_llist alt_16550_uart_list;
This is a declaration of the variable alt_16550_uart_list. Where is this variable defined?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|