> I am new to all this so dont get mad at me for posting
> a question like this, but I am using CodeWarrior 7 to
> build my palm programs and I have a number of
> functions that I have to use in every program. Can
> someone please tell me a way to make a lib out of them
> so I dont have to paste the code into each project

This is a good question, and I couldn't find the answer easily so hopefully
this will help.  And for posterity, I've included the following keywords to
make eScribe searches easier:

static library libraries common reusable code

which is what I searched on :)

So, this is for using CW7

1. Make a new C project.
2. In the CW settings for the project, in "Target Settings" set
"Post-Linker" to "None".
3. In the CW settings for the project, in "68K Target" set "Project Type" to
"Library", set "File Name" to "MYLIBNAME.lib" (obviously replace MYLIBNAME
with whatever you want the lib to be called) and set the radio buttons to
"PalmOS Library".
4. Write a bunch of code functions in a .c file, and add it to the project. 
5. Write a .h file w/ function prototypes for all the functions in the .c
file you want to be able to call from outside the library.  Make sure you
include "extern" in front.  

Example:  

In myfile.c:

void MyFunc1 (void) { WinDrawChars ("Something",10,10);}

In myfile.h:

extern void MyFunc1 (void);

6. Compile.  You should now have MYLIBNAME.lib
7. Make a new CW7 project.
8. Write some source code.  In the .c file you write, #include "myfile.h"
which you wrote in #5.  
9. Add MYLIBNAME.lib to your project; it should look like StartupCode.lib
after you add it (same icon).
10. Compile your project, and enjoy the reuse of your code from
MYLIBNAME.lib.
 
11. As per Jim Schram's post a few weeks ago, you really should put 
 
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
 
in your .h file before listing all the function prototypes, and
 
#ifdef __cplusplus
}
#endif /* __cplusplus */
 
after all your function prototypes.  This will allow you to call into your
library even with the C++ compiler activated.  If you don't, the C++
compiler will mangle the names of your library functions, so when you make a
call to them from your source, the linker will complain that it doesn't know
your function name.  An ounce of prevention is worth a pound of cure, so do
this so that you and others won't have a problem when you decide to write
some C++ code.
 
That should do it.
 
Cheers,
 
-DGA

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to