[Ubuntu-BR] Problemas na compilação C

guto carvalho listas em gutocarvalho.net
Quarta Outubro 17 19:54:34 UTC 2007


Você instalou os headers e source do seu kernel?

Em Qua, 2007-10-17 às 14:52 -0300, Khristian escreveu:
> Eis o código que dá pau. Não tente achar um uso pro código, ele só
> imprime algo quando carrega e descarrega (o printk funciona, mas o
> printf não). Testei essa compilação numa máquina com Ubuntu na
> universidade, e também não achou os stdio.h, stdlib.h...
> 
> -bash-3.00$ cat Lab5.c
> /* hello.c
>  *
>  * "Hello, world" − the loadable kernel module version.
>  *
>  * Compile this with
>  *
>  *           gcc −c hello.c −Wall
>  */
> /* Declare what kind of code we want from the header files */
> #define MODULE
> #include <linux/module.h>
> #include <linux/tty.h>       /* console_print() interface */
> #include <linux/sched.h>
> #include <linux/time.h>
> #include <stdio.h>
> #include <time.h>
> 
> extern struct timespec xtime;
> 
> /* Initialize the LKM */
> int init_module()
> {
>    printk("Módulo Lab5 inserido");
>    //printk("Hello, world − this is the kernel speaking with unsigned
> long long : %llu\n", (unsigned long long)xtime.tv_sec);
>     //printk("Hello, world − this is the kernel speaking with char:
> %s\n", (char*)xtime.tv_sec);
>    /* More normal is printk(), but there's less that can go wrong with
>       console_print(), so let's start simple.
>    */
>    /* If we return a non zero value, it means that
>     * init_module failed and the LKM can't be loaded
>     */
>    return 0;
> }
> /* Cleanup − undo whatever init_module did */
> void cleanup_module() {
>   printk("Short is the life of an LKM\n");
> }
> 
> char *read() {
> /* time_t tempo;
> tempo = xtime.tv_sec;
> printf("Tempo: %s",(char *)ctime(&tempo));
>    //strcat(temp,xtime.tv_sec);*/
> return "blablabla";
> }
> 
> ---------
> O makefile usado:
> -bash-3.00$ cat Makefile
> obj-m += Lab5.o
> 
> all:
>         make -C /lib/modules/$(shell uname -r)/build -I /usr/include
> M=$(PWD) modules
> 
> clean:
>         make -C /lib/modules/$(shell uname -r)/build -I /usr/include
> M=$(PWD) clean
> 
> 
> ----
> Curiosidade extra: tive a idéia de mandar compilar o arquivo no
> servidor de arquivos (via ssh), e ocorreu o contrário agora:
> 
> -bash-3.00$ gcc -c Lab5.c -Wall
> Lab5.c:11:26: linux/module.h: No such file or directory
> Lab5.c:12:61: linux/tty.h: No such file or directory
> Lab5.c:13:25: linux/sched.h: No such file or directory
> Lab5.c:14:24: linux/time.h: No such file or directory
> Lab5.c: In function `init_module':
> Lab5.c:23: warning: implicit declaration of function `printk'
> 
> Alguma nova idéia?
> Valeu,
> Khristian
> 
> >
> > Message: 2
> > Date: Wed, 17 Oct 2007 12:03:09 -0300
> > From: Jonh Wendell <wendell em ubuntu.com>
> > Subject: Re: [Ubuntu-BR] Problemas na compilação C
> > To: Lista de discussão do LoCoTeam Brasileiro
> >         <ubuntu-br em lists.ubuntu.com>
> > Message-ID: <1192633389.5671.8.camel em wendell-laptop>
> > Content-Type: text/plain; charset=utf-8
> >
> > Em Qua, 2007-10-17 às 11:58 -0300, Khristian escreveu:
> > > respondendo às 2 mensagens:
> > > 1- sim, o gcc tá instalado, porque eu consigo compilar módulos do
> > > kernel. o problema é quando eu tento imprimir texto no console
> > > (blarg).
> > >
> > > 2- eu já havia dito no email anterior que o libc6-dev e o
> > > build-essential (além de uma porrada de -devs) estão instalados.
> >
> > Manda um pedaço do código.
> >
> > T+,
> > --
> > Jonh Wendell
> > jonh.wendell em gmail.com
> >
> >
> >
> >
> > ------------------------------
> 
> -- 
> Khristian Alexander Schönrock
> http://agilizando.blogspot.com - Notícias Quentinhas de Tecnologia!
> http://derkosak.blogspot.com - Meu blógue!





More information about the ubuntu-br mailing list