I have these files..
str.h
#ifndef _str_h_
#define _str_h_
struct STRSTR
{
char* MainStr;
char* SubStr;
};
char* str_str(int, int, struct STRSTR* sample);
void init(char*, struct STRSTR* sample);
#endif /* _str_h_ */
str.c
#include "str.h"
#include <stdio.h>
void init(char* str, struct STRSTR* sample){
sample->MainStr = str;
}
char* str_str(int index, int size, struct STRSTR* sample){
int length = 0;
while ( *(sample->MainStr + length)!= '\0' )
length++;
if (index > length)
printf( "ERROR!! Index value is greater than the actual size" );
else{
char temp[length];
int i;
for ( i = index; i < size; i++ ) {
temp[i] = *(sample->MainStr + i);
}
temp[size] = '\0';
sample->SubStr = temp;
}
return sample->SubStr;
}
main.c
#include "str.h"
#include <stdio.h>
int main() {
extern struct STRSTR sample;
init((char*)"Hello World", &sample);
char* out = str_str(0, 5, &sample);
printf("%s", out);
return 0;
}
and my Makefile
MAIN = main
HEADER_DEFINITIONS = str.c
CC = gcc
COMPILE = -c
EXE = $(MAIN)
OPTIMIZE = -Os
SHELL = /bin/bash
NO_WARNINGS = -w
VERBOSE = -v
all: link
@echo "Executing..........."
@echo " > > > > > > OUTPUT < < < < < < "
@$(SHELL) -c './$(EXE)'
link: compile
@echo -n "Linking............."
@$(SHELL) -c '$(CC) -o $(EXE) *.o'
compile: $(MAIN).c $(HEADER_DEFINITIONS)
@echo -n "Compiling........."
@$(SHELL) -c '$(CC) $(OPTIMIZE) $(COMPILE) $(NO_WARNINGS) $^'
clean:
@echo "Cleaning............"
@$(SHELL) -c 'rm -f *~ *.o $(EXE)'
This shows error like this
main.o: In function main': main.c:
(.text.startup+0x2): undefined reference tosample'
main.c:(.text.startup+0x11): undefined reference to
sample' collect2: error:
ld returned 1 exit status`
Please help me..Thanks in advance..