Created
September 27, 2012 21:35
-
-
Save magnunleno/3796606 to your computer and use it in GitHub Desktop.
Exemplo de biblioteca estática em C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Cleaning build dir..." | |
rm build/* | |
echo | |
echo "Compiling files" | |
gcc -c lib/myprint.c -o build/myprint.o | |
echo | |
echo "Building lib archive" | |
ar rcs build/libmyprint.a build/myprint.o | |
echo | |
echo "libmyprint built with these files" | |
ar -t build/libmyprint.a | |
echo | |
echo "Simbols in libmyprint" | |
nm -s build/libmyprint.a | |
echo | |
echo "Coping definition file to build dir" | |
cp lib/myprint.h build/myprint.h | |
echo | |
echo "Cleaning .o files" | |
rm build/*.o | |
echo | |
echo "Compiling client program" | |
gcc -static src/main.c -L./build -I./build -lmyprint -o build/main.run | |
echo | |
echo "Running program" | |
./build/main.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* myprint.c | |
* | |
* Biblioteca de exemplo para a criação e uso de bibliotecas estáticas na | |
* linguagem C. | |
* | |
* Esta arquivo possui a implementação da função my_print. | |
* | |
* Licença: GPL 3.0 | |
* Mais informações: http://www.mindbending.org | |
* | |
*/ | |
#include <stdio.h> | |
#include "myprint.h" | |
void my_print(char *str){ | |
printf("My Print: %s\n", str); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* myprint.h | |
* | |
* Biblioteca de exemplo para a criação e uso de bibliotecas estáticas na | |
* linguagem C. | |
* | |
* Esta arquivo de cabeçalho possui apenas as definições de funções e rotinas. | |
* | |
* Licença: GPL 3.0 | |
* Mais informações: http://www.mindbending.org | |
* | |
*/ | |
#ifndef _MYPRINT_LIB_ | |
#define _MYPRINT_LIB_ | |
void my_print(char *str); | |
#endif // _MYPRINT_LIB_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* main.c | |
* | |
* Programa de exemplo para a criação e uso de bibliotecas estáticas na | |
* linguagem C. | |
* | |
* Esta arquivo se utiliza da biblioteca my_print.a construída anteriormente. | |
* | |
* Licença: GPL 3.0 | |
* Mais informações: http://www.mindbending.org | |
* | |
*/ | |
#include <myprint.h> | |
int main(int argc, char *argv[]){ | |
my_print("Teste!"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment