Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Created April 20, 2018 02:58
Show Gist options
  • Save jeffotoni/4f74ae6e55fb3e13687ab9c3e6f6809e to your computer and use it in GitHub Desktop.
Save jeffotoni/4f74ae6e55fb3e13687ab9c3e6f6809e to your computer and use it in GitHub Desktop.
/**
* @autor jeffotoni@gmail.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int main()
{
///declara ponteiro para receber lib
void *handle;
///assinatura da funcao Multi
unsigned long int (*Multi)(unsigned long int f);
///capturar o valor na tela..
int valorToGerar;
int n , i = 0, c;
///erro para tratar dlopen
char *error;
///dlopen => abrindo biblioteca
handle = dlopen("./C/libmulti.so",RTLD_LAZY);
if(!handle)
{
fprintf(stderr, "Erro: %s\n", dlerror());
exit(1);
}
///chando a funcao fibonancci
Multi = dlsym(handle, "Multi");
if((error = dlerror()) != NULL)
{
fprintf(stderr,"Erro: %s\n", error);
exit(1);
}
printf("Quantidade de termos da sequencia Multi:\n");
scanf("%d", &n);
for ( c = 1 ; c <= n ; c++ )
{
valorToGerar = c;
printf("Sequencia: %d * 2 = %lu\n",valorToGerar,(*Multi)(c));
i++;
}
dlclose(handle);
return 0;
}
@jeffotoni
Copy link
Author

python

import ctypes
lib = ctypes.CDLL("libmulti.so")
lib.Multi(100)
200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment