-2

Well as the title says, I keep getting an Undefined Reference to error but I don't know why..

I have a main routine which has the header of the function I wanna use included, which therefore is included by the cpp file which defines the function. I also included the path to the project settings

I know I should post code but I am not allowed to do that but still hope I can get some hints on solving this error.

Thanks in advance

UART_write(UARTvar, LVL);  //This is where I call the function

int UART_write(int uart, const char* var);//Declaration in the header

int UART_write(int uart, const char* var)
{
return (int)1;//just for testing
}

undefined reference to `UART_write'

jj01
  • 68
  • 1
  • 7
  • Also when I press F3(which is used to go to the declaration/definition, it finds the declaration and also the definition) – jj01 Feb 28 '13 at 09:58
  • It misses the needed library to link. – SChepurin Feb 28 '13 at 10:00
  • Can you me more specific? Exact error, part of your code? – Alex Feb 28 '13 at 10:00
  • 1
    "I know I should post code but I am not allowed to do that but still hope I can get some hints on solving this error." -1 Too localized. –  Feb 28 '13 at 10:03
  • 1
    Either there is an overload missing that the editor doesn't notice, or you are not linking all the files. We can't tell without seeing the error message and the source. – Bo Persson Feb 28 '13 at 10:04
  • Well I am linking them in the project settings(added the include paths of the header files) – jj01 Feb 28 '13 at 10:13
  • @Bo Persson - the project is so proprietary that even error messages should be kept secret. – SChepurin Feb 28 '13 at 10:30
  • @SChepurin: The error message is there since 29 minutes – jj01 Feb 28 '13 at 10:37
  • @aaj07 - Nope. You should copy-paste the exact error message output. – SChepurin Feb 28 '13 at 10:42
  • @aaj07 In addition to updating the include paths, you also have to update linker settings to list the path + name of the library which implements `UART_write` – simonc Feb 28 '13 at 10:42

1 Answers1

1

If you have the following project structure:

header.h:

#ifndef _HEADER_H_
#define _HEADER_H_

int UART_write(int uart, const char* var);

#endif

main.c:

#include "header.h"

int main()
{
    ...
    UART_write(UARTvar, LVL);
    ...
}

So please be sure that you have not defined _HEADER_H_ in any other place, as in this case UART_write() prototype will not be included in build.

Also please check if the UART_write() prototype is not placed between #if or #ifdef and #endif preprocessor commands.

And the last one, you can check above by adding #error "This code is compiled" before the UART_write() prototype in your header. If this part of code is compiled, so you will get compilation error This code is compiled.

Alex
  • 9,891
  • 11
  • 53
  • 87
  • Thanks for this hints :) Found the error: somehow it couldn't manage that the file was a *.cpp so after changing it to *.c it worked. – jj01 Feb 28 '13 at 13:18