This is a sample of connecting a library class and an application.
#################### printMe.c #################### /* Application File */ #include "libPrintMe.h" int main (void) { char *myMainString; kellyClass testClass; myMainString = "world"; testClass.printMe(myMainString }; #################### build.sh #################### #!/bin/bash # build file echo "build libPrintme.a" g++ -c libPrintMe.cc -o libPrintMe.a echo "build printMe" g++ printMe.c -o printMe -I. libPrintMe.a #################### libPrintMe.cc #################### /* Library File */ #include <stdio.h> #include "libPrintMe.h" void kellyClass::printMe (char *myString) { printf("hello %s\n", myString); }; #################### libPrintMe.h #################### /* Public Header File */ class kellyClass { public: void printMe (char *myString); }; |
I wrote this code with some help from Jake to figure out just what
part
of the library code and library had to be duplicated in order to link
them. This is cool because you can write a library, compile it and only
give people the public .h file to compile against. This is really
rudimentary stuff. I had never done it.
No comments:
Post a Comment