Makefile probleme



  • Ich habe ein Problem dabei ein Programm zu kompilieren

    hier der Code vom Programm:

    #include <stdio.h>
    #include <errno.h>
    #include <fcntl.h>
    #include <linux/ioctl.h>
    #include "../mymodule.h"
    
    int main()
    {
    	int rtn, i;
    	int gpio_fd = -1;
    	struct reg_ioctl_data it;
    	/* Actual value is not important */
    	it.data = 812;
    
    	/* Opening */
    	gpio_fd = open("/dev/mydevice", O_RDWR);
    	if(gpio_fd == -1){
    		perror("Couldn't open /dev/mydevice");
    		return 1;
    	}
    	printf("Got through opening /dev/reg\n");
    	printf("Will write value of it.data (%i) to reg.\n", it.data);
    
    	/* ioctl test */
    
    	rtn = ioctl(gpio_fd, REG_OUT, &it);
     	   /* rtn = 0 means success */
    	if(!rtn) printf("Woo hoo!  ioctl(REG_OUT) worked!\n");
    	else perror("Dang, ioctl(REG_OUT) didn't work");
    
    	   /* Again, value isn't important, as long as chagned */
    	it.data = 100;
    	printf("Now changed it.data to %i.\n", it.data);
    	printf("Will read reg into it.data to see 'it' change.\n");
    
    	printf("it.data = %i before ioctl(REG_IN)\n", it.data);
    	rtn = ioctl(gpio_fd, REG_IN, &it);
    
    	if(!rtn) printf("Woo hoo!  ioctl(REG_IN) worked!\n");
    	else perror("Dang, ioctl(REG_IN) didn't work");
    
    	printf("it.data = %i after ioctl(REG_IN)\n", it.data);
    
    	/* Closing */
    	if(close(gpio_fd)) perror("Couldn't close /dev/mydevice");
    	else printf("Closed /dev/reg\n");
    
    	return 0;
    }
    

    Hier der Code vom Makefile:

    TOOLPREFIX=/home/crosstool/bin/powerpc-405-linux-gnu-
    CC=$(TOOLPREFIX)gcc

    ARCH := ppc
    CROSS_COMPILE := /home/crosstool/bin/powerpc-405-linux-gnu-

    KERNELDIR := /home/user01/linux-2.6.18/

    PWD := $(shell pwd)

    all:
    $(MAKE) -C (KERNELDIR)ARCH=(KERNELDIR) ARCH={ARCH} CROSS_COMPILE=CROSS_COMPILEM={CROSS\_COMPILE} M=(PWD)

    clean:
    rm -rf *.o *.symvers

    obj-m := myapp.o

    Wenn ich das Makefile anwerfe, bekomme ich folgende Fehler:

    /home/heckmann/kernel_treiber/test/application/myapp.c:1:19: stdio.h: No such file or directory
    /home/heckmann/kernel_treiber/test/application/myapp.c:2:19: errno.h: No such file or directory
    /home/heckmann/kernel_treiber/test/application/myapp.c:3:19: fcntl.h: No such file or directory
    /home/heckmann/kernel_treiber/test/application/myapp.c:9: warning: function declaration isn't a prototype
    /home/heckmann/kernel_treiber/test/application/myapp.c: In function `main':
    /home/heckmann/kernel_treiber/test/application/myapp.c:17: warning: implicit declaration of function `open'
    /home/heckmann/kernel_treiber/test/application/myapp.c:17: error: `O_RDWR' undeclared (first use in this function)
    /home/heckmann/kernel_treiber/test/application/myapp.c:17: error: (Each undeclared identifier is reported only once
    /home/heckmann/kernel_treiber/test/application/myapp.c:17: error: for each function it appears in.)
    /home/heckmann/kernel_treiber/test/application/myapp.c:19: warning: implicit declaration of function `perror'
    /home/heckmann/kernel_treiber/test/application/myapp.c:22: warning: implicit declaration of function `printf'
    /home/heckmann/kernel_treiber/test/application/myapp.c:28: warning: implicit declaration of function `ioctl'
    /home/heckmann/kernel_treiber/test/application/myapp.c:47: warning: implicit declaration of function `close'
    /home/heckmann/kernel_treiber/test/application/myapp.c:10: warning: unused variable `i'
    

    Ich vermute es liegt irgendwie am Makefile. Kann mir da jemand mal kurz weiterhelfen?



  • ja, das Makefile oben ist für Module gedacht, du willst aber ein User Space Programm kompilieren, d.h. du musst es als user space programm kompilieren und nicht Kbuild kompilieren lassen, denn linux kennt stdio.h, stdlib.h, usw.

    TOOLPREFIX=/home/crosstool/bin/powerpc-405-linux-gnu- 
    CC=$(TOOLPREFIX)gcc 
    
    ALL: myapp
    


  • Okey, wieder einmal danke an supertux!
    Das mit den Makefiles ist auch wieder so eine Sache. Gibt so viele Dinge, in die man sich einlesen muß.

    Jetzt nur noch eine Frage:
    Bei dem Makefile von dir, wird die Architektur und Crosskompilierung nicht berücksichtigt. Reicht es aus, wenn ich dann wieder

    ARCH := ppc
    CROSS_COMPILE := /opt/crosstool/bin/powerpc-405-linux-gnu-
    

    mit in das Makefile eintrage???


Anmelden zum Antworten