First of all I am pretty much a beginner, so I am not sure how to explain what I need but I'll give it a try. (I searched but couldn't find a complete answer).
I am learning C on my own and using Code Blocks.
I want to create my own mini-library of custom functions to use in my programs.
I have a folder called "C". Inside "C", I have a folder called "Exercises" where I do all the little projects from a book.
Also inside "C", I wanna have another folder called "MyC" in which I would keep my own header files and the .c files containing the implementations of my custom functions. For example, these .h and .c would be saved in "MyC":
//test.h
#ifndef _TEST_H
#define _TEST_H
int mySum(int, int);
#endif // _TEST_H
//test.c
#include <stdio.h>
#include "test.h"
int mySum(int a, int b)
{
return a + b;
}
So now, what I'm trying to do is to be able to create a new project in "Exercises" and not having to bring a copy of both test.h and test.c into the project, but instead just #include my test.h and do something like:
//testMain.c
#include <stdio.h>
#include <test.h>
int main(void)
{
printf("\n2 + 1 = %d", mySum(2, 1));
return 0;
}
I know that <> are for the standard headers, but quotes are for headers in the current folder, and that's what I don't want.
Is it possible to do this? How?
I've read about going into settings>compiler and on Search Directories add the path where I have the header but didn't work. It gives me an error "undefined reference to 'mySum'" I tried quotes and brackets on the #include.
Can you guys please give a step-by-step for what it needs to be done to be able to do this?