LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   u16 does not name a type (http://www.linuxquestions.org/questions/programming-9/%91u16%92-does-not-name-a-type-4175446686/)

CandyRedTele 01-21-2013 10:39 PM

u16 does not name a type
 
Hello,

I'm trying to compile a cpp file which includes ad799x.h and I get this error :

ad799x.h:121:2: error: u16 does not name a type

I would like to know what should I include or link to be able to compile?

Thanks

corp769 01-21-2013 11:00 PM

In your ad799x.h file, what is on line 121? And what is the purpose of your program/what does it do? By reading the error, it seems as you don't have a function, struct, etc properly defined. Also, if you could post more information about the header file, it would definitely help in further troubleshooting.

CandyRedTele 01-22-2013 09:03 AM

I'm trying to talk to the sensor AD7998, and to do that I'm supposed to use 'iio'.
The stucture is not defined in ad799x.h, that's why I think I have to include something else.

118
119 struct ad799x_platform_data {
120 u16 vref_mv;
121 };
122

You can find the header here :
http://wiki.analog.com/resources/too...98?force_rev=1

johnsfine 01-22-2013 09:59 AM

That code in ad799x.h is clearly assuming some previous include file defined u16 to be the same as __u16

But I can't see where in that project the definition of u16 is supposed to occur.

Somewhere there ought to be lines such as
Code:

typedef __u16 u16;
typedef __u8 u8;

But I'm not sure where those should be of whether that should be done in some way with more portability protection.

Another possibility is that you are supposed to include /usr/include/op_types.h

NevemTeve 01-22-2013 10:12 AM

Guess this source is meant for use in the kernel, where type 'u16' is defined. Try this:

Code:

#define __KERNEL__
#include <linux/types.h>
#include "ad799x.h"


CandyRedTele 01-27-2013 12:02 PM

I tried this :

#define __KERNEL__
#include <linux/types.h>
#include "ad799x.h"

But I got the same errors.
Any idea?

johnsfine 01-27-2013 12:09 PM

Maybe it varies by version, but the linux/types.h on my system does not declare u16 regardless of what #define's you might have.

The /usr/include/op_types.h does define u16 conditional on some #define.

Try looking at the .h file that you hope might solve your problem and see for yourself whether/when it declares u16

CandyRedTele 01-27-2013 01:00 PM

// This fixe the u16 error :
#define __KERNEL__
#include <asm-generic/int-ll64.h>
#include "ad799x.h"

g++ -I/usr/src/linux-headers-3.0.0-30-generic/include test.cpp
In file included from test.cpp:4:0:
ad799x.h:97:33: erreur: field ‘channel’ has incomplete type


channel is of type iio_chan_spec which is defined here in linux/iio/iio.h
But when I include it, I get Alot of errors

NevemTeve 01-27-2013 10:51 PM

Whenever you have a pre-processor related problem, ask cpp for help:

Code:

compilation: gcc <options> -c mysource.c -o mysource.o
pre-proc:    cpp <options> -dD mysource.c mysource.E

file mysource.E will contain the preprocessor's output.

NevemTeve 01-28-2013 02:54 AM

Made a few test that confirmed my original opinion: this source is meant for use in the kernel. It heavily depends on other kernel headers, not likely to be usable from user program.

mina86 01-28-2013 07:13 AM

Why are you using this header in user space? It's a kernel driver.

In general “u16” type is never declared by Linux headers included by user space and for user space use “__u16” is used instead. If you find yourself in need to define __KERNEL__ than you're most likely doing something you should not be doing (or there is a problem with the header file).

CandyRedTele 01-28-2013 09:05 AM

Ok thanks for your answers!

I'm probably doing something wrong. I thougth the driver would be the interface between the user space and the kernel. If I'm not supposed to use the driver from user space, does that mean that I have to compile a kernel module in order to be able to use the sensor AD7998? Or is there a 'normal' way to do that from user space?

mina86 01-28-2013 12:13 PM

Quote:

Originally Posted by CandyRedTele (Post 4879062)
I'm probably doing something wrong. I thougth the driver would be the interface between the user space and the kernel. If I'm not supposed to use the driver from user space, does that mean that I have to compile a kernel module in order to be able to use the sensor AD7998? Or is there a 'normal' way to do that from user space?

Since Linux 2.6.31 ad799x driver is in staging directory so you should use it instead of building the module itself.


All times are GMT -5. The time now is 09:55 PM.