Help - How to create a global library or header file?

Hi,

In Developer Studio 2.1.0, I wanted to create a library or a header file, just like string.h or stdlib.h, where it can be included when I wanted to create a new project.
I have been trying this but to no avail. I believe this is possible.

Basically, what I wanted to achieve is that I have a few common functions which can be used whenever I create a new project.
Like, I have a function called IsValidName.

Scenario:

test_a.c
#include "string.h"

bool IsValidName(char *name) {
   ...
   return true;
}

void Hello(char *name) {
   bool ret = IsValidName(name);
   ...
}
test_b.c
#include "string.h"

bool IsValidName(char *name) {
   ...
   return true;
}

void Confirm(char *name) {
   bool ret = IsValidName(name);
   ...
}
void Save () { }

Expected:

common.h

#ifndef __COMMON_H__
#define __COMMON_H__

bool IsValidName(char *name);

#endif  /* __COMMON_H__ */

test_a.c
#include "string.h"
#include "common.h"

void Hello(char *name) { 
   bool ret = IsValidName(name);
   ...
}

test_b.c
#include "string.h"
#include "common.h"

void Confirm(char *name) {
   bool ret = IsValidName(name);
}
void Save () { }

Any help is very much appreciated.

Thanks.

This seems to be a basic question about ‘C’ program structure - nothing specifically to do with Open-AT or Developer Studio :question:

A “library” is not the same as a “header”

  • A Library contains a set of Definitions of code objects (functions, data);

  • A Header contains a set of Declarations for those objects which supply just enough information (name & type) for the compiler to be able to use them in other source files.

A Library can be supplied as either source files, or as a pre-compiled binary.

I would suggest that the simplest option for you to start with is to just create source files.

Funnily enough, as if to emphasise that point, I have just this minute finished an example of how to share objects from one .c source file to be used by other .c source files:

avrfreaks.net/comment/161010 … nt-1610106

See also: c-faq.com/decl/decldef.html

Some more ‘C’ learning/reference materials: blog.antronics.co.uk/2011/08/08/ … ng-with-c/

Hi awneil,

Thanks for the heads up and the explanation on how things work.
I will look into those examples.

Thanks.