I would like to build c project by Eclipse. The codes are ok (like following) but link is not worked. So I cannot build them.If the contents of sub() is defined in sub.h, build works fine.
I often use Microsoft visual studio, but I am a begginer of eclipse and I could not set the linker option.
What I want to do
How can I link and build devided c-sources by eclipse? I want to build the project by just clicking "Build All" button.
Error message
undefined reference to `sub'
collect2: error: ld returned 1 exit status
Eclipse setting
- OS: Ubuntu 16.04
- version: Eclipse Luna
- toolchain: Yocto toolchain (see http://variwiki.com/index.php?title=Yocto_Programming_with_Eclipse&release=RELEASE_MORTY_V1.0_DART-6UL)
- project property
main.c
#include <stdio.h>
#include "sub.h"
int main(void)
{
printf("sub() = %d\n", sub());
return 0;
}
sub.c
#include "sub.h"
int sub(void)
{
return 1;
}
sub.h
#ifndef SUB_H
#define SUB_H
int sub(void);
#endif