Post Go back to editing

adxl345 : problems when compiling driver as module

Thread Summary

The user encountered compilation errors for the ADXL345 driver on a 3.5.0 kernel, primarily due to dereferencing pointers to incomplete types and unknown fields in struct initializers. The final answer suggests using a mainline driver and provides a working Makefile example, which includes the necessary header files and kernel source paths. The accompanying answer clarifies that the issue might be due to missing inclusion of the `adxl34x.h` header file.
AI Generated Content

Hi. I have problems when compiling the adxl345 driver as a module on the 3.5.0 kernel.

I'm using the classic method of create a makefile.

I get all those errors for the file adxl34x.c :

     c2a@boxC2A:~/test$ sudo make

     make -C /usr/src/linux-headers-3.5.0-28-generic SUBDIRS=/home/c2a/test modules

     make[1]: Entering directory `/usr/src/linux-headers-3.5.0-28-generic'

       CC [M]  /home/c2a/test/adxl34x.o

     /home/c2a/test/adxl34x.c: In function ‘adxl34x_get_triple’:

     /home/c2a/test/adxl34x.c:243:10: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘adxl34x_irq’:

     /home/c2a/test/adxl34x.c:311:14: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:315:13: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:343:12: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:372:14: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘__adxl34x_disable’:

     /home/c2a/test/adxl34x.c:408:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘__adxl34x_enable’:

     /home/c2a/test/adxl34x.c:413:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘adxl34x_calibrate_store’:

     /home/c2a/test/adxl34x.c:520:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:521:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:522:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘adxl34x_rate_store’:

     /home/c2a/test/adxl34x.c:554:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘adxl34x_autosleep_store’:

     /home/c2a/test/adxl34x.c:594:3: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c: In function ‘adxl34x_probe’:

     /home/c2a/test/adxl34x.c:735:10: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:755:30: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:812:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:830:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:832:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:834:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:836:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:837:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:838:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:839:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:840:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:841:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:842:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:843:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:844:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:845:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:846:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:847:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:849:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:850:2: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:855:3: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:858:3: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:862:3: error: dereferencing pointer to incomplete type

     /home/c2a/test/adxl34x.c:882:2: error: dereferencing pointer to incomplete type

     make[2]: *** [/home/c2a/test/adxl34x.o] Error 1

     make[1]: *** [_module_/home/c2a/test] Error 2

     make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-28-generic'

     make: *** [default] Error 2

And for the file adxl34x-i2c.c :

     c2a@boxC2A:~/test$ sudo make

     make -C /usr/src/linux-headers-3.5.0-28-generic SUBDIRS=/home/c2a/test modules

     make[1]: Entering directory `/usr/src/linux-headers-3.5.0-28-generic'

       CC [M]  /home/c2a/test/adxl34x-i2c.o

     /home/c2a/test/adxl34x-i2c.c:62:21: error: variable ‘adxl34x_smbus_bops’ has initializer but incomplete type

     /home/c2a/test/adxl34x-i2c.c:63:2: error: unknown field ‘bustype’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:63:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:63:2: warning: (near initialization for ‘adxl34x_smbus_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:64:2: error: unknown field ‘write’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:64:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:64:2: warning: (near initialization for ‘adxl34x_smbus_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:65:2: error: unknown field ‘read’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:65:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:65:2: warning: (near initialization for ‘adxl34x_smbus_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:66:2: error: unknown field ‘read_block’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:66:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:66:2: warning: (near initialization for ‘adxl34x_smbus_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:69:21: error: variable ‘adxl34x_i2c_bops’ has initializer but incomplete type

     /home/c2a/test/adxl34x-i2c.c:70:2: error: unknown field ‘bustype’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:70:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:70:2: warning: (near initialization for ‘adxl34x_i2c_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:71:2: error: unknown field ‘write’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:71:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:71:2: warning: (near initialization for ‘adxl34x_i2c_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:72:2: error: unknown field ‘read’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:72:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:72:2: warning: (near initialization for ‘adxl34x_i2c_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:73:2: error: unknown field ‘read_block’ specified in initializer

     /home/c2a/test/adxl34x-i2c.c:73:2: warning: excess elements in struct initializer [enabled by default]

     /home/c2a/test/adxl34x-i2c.c:73:2: warning: (near initialization for ‘adxl34x_i2c_bops’) [enabled by default]

     /home/c2a/test/adxl34x-i2c.c: In function ‘adxl34x_i2c_probe’:

     /home/c2a/test/adxl34x-i2c.c:89:2: error: implicit declaration of function ‘adxl34x_probe’ [-Werror=implicit-function-declaration]

     /home/c2a/test/adxl34x-i2c.c:89:5: warning: assignment makes pointer from integer without a cast [enabled by default]

     /home/c2a/test/adxl34x-i2c.c: In function ‘adxl34x_i2c_remove’:

     /home/c2a/test/adxl34x-i2c.c:105:2: error: implicit declaration of function ‘adxl34x_remove’ [-Werror=implicit-function-declaration]

     /home/c2a/test/adxl34x-i2c.c: In function ‘adxl34x_i2c_suspend’:

     /home/c2a/test/adxl34x-i2c.c:114:2: error: implicit declaration of function ‘adxl34x_suspend’ [-Werror=implicit-function-declaration]

     /home/c2a/test/adxl34x-i2c.c: In function ‘adxl34x_i2c_resume’:

     /home/c2a/test/adxl34x-i2c.c:124:2: error: implicit declaration of function ‘adxl34x_resume’ [-Werror=implicit-function-declaration]

     cc1: some warnings being treated as errors

     make[2]: *** [/home/c2a/test/adxl34x-i2c.o] Error 1

     make[1]: *** [_module_/home/c2a/test] Error 2

     make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-28-generic'

     make: *** [default] Error 2

Please anyone for help ?

C2A team

  • Hi,

    Looks like it is not including adxl34x.h

    -Michael

  • Wondering why you like to build out of tree?

    This driver is mainline since a long time...

    However this method works for me -

    michael@mhenner-D03:~/devel/git/foo$ ls

    adxl34x.c  adxl34x.h  adxl34x-i2c.c  adxl34x-spi.c  Makefile

    michael@mhenner-D03:~/devel/git/foo$ cat Makefile

    ifneq (${KERNELRELEASE},)

    obj-m := adxl34x.o

    adxl34x-y := adxl34x-i2c.o

    else

    KERNEL_SOURCE := /home/michael/devel/git/staging_3

    PWD := $(shell pwd)

    default:

        ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

    clean:

        ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean

    endif

    michael@mhenner-D03:~/devel/git/foo$ make -C /home/michael/devel/git/staging_3 M=$PWD

    make: Entering directory `/home/michael/devel/git/staging_3'

      LD      /home/michael/devel/git/foo/built-in.o

      CC [M]  /home/michael/devel/git/foo/adxl34x-i2c.o

      LD [M]  /home/michael/devel/git/foo/adxl34x.o

      Building modules, stage 2.

      MODPOST 1 modules

    WARNING: "adxl34x_remove" [/home/michael/devel/git/foo/adxl34x.ko] undefined!

    WARNING: "adxl34x_probe" [/home/michael/devel/git/foo/adxl34x.ko] undefined!

      CC      /home/michael/devel/git/foo/adxl34x.mod.o

      LD [M]  /home/michael/devel/git/foo/adxl34x.ko

    make: Leaving directory `/home/michael/devel/git/staging_3'

    michael@mhenner-D03:~/devel/git/foo$

  • Thanks for this quick answer !

    Please excuse me for my lack of knowledge in module compiling, but I thought that the line #include "adxl34x.h" in the .c files would include the file adxl34x.h at compilation if it is located in the same directory.

    Should I modify my Makefile to include this header file ?

    This is the Makefile I use :

         ifneq (${KERNELRELEASE},)

         obj-m := adxl34x.o

         adxl34x-y := adxl34x-i2c.o adxl34x-spi.o

         else

         KERNEL_SOURCE := /usr/src/linux-headers-3.5.0-28-generic

         PWD := $(shell pwd)

         default:

             ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

         clean:

             ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean

         endif

    Thanks

    C2A team