LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-09-2007, 05:52 AM   #1
halturata
Member
 
Registered: Aug 2005
Location: Sofia
Distribution: SuSE, ELinOS
Posts: 100

Rep: Reputation: 16
Question error: field has incomplete type


Hello there,

Here is how it goes - I have written a small test driver as an exercise to "Linux Device Drivers" and as a preparation for writing a real, functional driver.
For the sake of seeing how far I got it working (I already implemented the open(0, read(), write() and ioctl() calls) I wrote a simple programm which queries some information from the driver:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>       /* mmap() */
#include <fcntl.h>        /* open(), close(), etc. */
#include <unistd.h>       /* exit() */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/cdev.h>

#include "iptimer_ppc_linux26_fnc.h"
#include "iptimer_ppc_linux26_io.h"

int main(int argc, char ** args)
{
      int fd, status = 0;
      unsigned long quantum, qset;
      
      if( (status = open("/dev/iptimer0", O_RDWR)) < 0 ){
            perror("open");
            printf("Error opening /dev/iptimer device file, errno = %d\n", errno);
            exit (1);
      }
      
      if((status = ioctl(fd, IPTIMER_IOCTL_GET_QUANTUM, quantum)) < 0 ){
            perror("ioctl");
            printf("Error getting quantum, errno = %d\n", errno);
            exit (1);
      }
      printf("*** quantum = %d", quantum);

      if((status = ioctl(fd, IPTIMER_IOCTL_GET_QSET, qset)) < 0 ){
            perror("ioctl");
            printf("Error getting qset, errno = %d\n", errno);
            exit (1);
      }
      printf("*** qset = %d", qset);      
      
      return 0;
}
When I try to compile it however, I get the following errors:
Code:
 ~/src/rwtest # make
ppc_60x-gcc -c -o main.o -g main.c
In file included from main.c:13:
iptimer_ppc_linux26_fnc.h:32: error: field `iptimer_cdev' has incomplete type
iptimer_ppc_linux26_fnc.h:33: error: field `iptimer_sem' has incomplete type
make: *** [main.o] Error 1
Here is the struct in which the problem occurs:
Code:
struct iptimer_dev{
      iptimer_qset_t   *iptimer_data;      /* Pointer to first quantum set */
      int                    quantum;            /* The current quantum size */
      int                    qset;               /* The current array size */
      unsigned long int  size;             /* Amount of data stored */
      struct cdev           ptimer_cdev;  /* Char device structure */
      struct semaphore  iptimer_sem;       /* Mutual exclusion semaphore */
      int                       dev_minor;                        
};
So, this two structures of the char dev and the semaphore are defined without "typedef"-s or anithing else in the kernel source. Anyone ahs a clue how to get rid of this errors? I found a lot of threads in the forums, but not a single one states a clear solution...
As far as the compilation of the driver itself, everithing goes well.
Here's a link to the actual driver source code, which I wrote.

Any suggestions are welcome.

_______________________________
Code:
07-08-09 12:41 :( # uname -a
Linux 2.4.21-47.0.1.ELsmp #1 SMP Thu Oct 19 10:46:05 CDT 2006 i686 i686 i386 GNU/Linux
07-08-09 12:52 :( # $CC --version
ppc_60x-gcc (GCC) 3.4.4
 
Old 08-10-2007, 03:17 AM   #2
halturata
Member
 
Registered: Aug 2005
Location: Sofia
Distribution: SuSE, ELinOS
Posts: 100

Original Poster
Rep: Reputation: 16
OK, I found out what my stupid mistake was - I try to include the header file of the driver in a user space program, and while compiling the driver with -D__KERNEL__ goes fine, the user space doesn't recognize the definitions wrapped inside the #define __KERNEL__ macro.

So, hope that will help someone, someday...
 
Old 04-10-2008, 06:57 PM   #3
naresh5677
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Rep: Reputation: 0
Hello:

I am also getting same error..
can you please explain me in detail?? please...........

Thanks
 
Old 04-10-2008, 07:22 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
It really links using that? I can imagine it would compile, but I don't know how the kernel symbols are resolved at link time unless you aren't actually using any kernel code other than struct iptimer_dev. It doesn't look like you do, but I'd think that there would also be a user-space include for the macros.
ta0kira

Last edited by ta0kira; 04-10-2008 at 07:24 PM.
 
Old 04-11-2008, 05:01 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
I think the problem (at least the original problem) was that while the declaration of struct iptimer_dev was in the userspace namespace (i.e., visible without defining __KERNEL__), some of the types of its elements (namely struct cdev and struct semaphore ) had complete declarations visible only with __KERNEL__. Thus, the overall type struct iptimer_dev was “incomplete” (which means, among other things that you can’t compute its size, but you can have pointers to it, etc.).

So the moral of the story is that if you write a header file to be used in both userspace and kernelspace, armor the sections which you absolutely know that userspace will not need access to with “#ifdef __KERNEL__” and “#endif” to protect them from being visible.

I wonder how this affects naresh5677 (who was scarce on details) or why you are reviving a 6-month-old thread.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tai64nlocal.c:55: error: dereferencing pointer to incomplete type ExCIA Linux - General 1 03-31-2009 09:49 AM
error: dereferencing pointer to incomplete type ChullDouvre Programming 2 05-02-2007 12:16 AM
Error: dereferencing pointer to incomplete type cynthia_thomas Programming 1 05-01-2006 08:10 AM
sem has incomplete type error in building the filesystem image sudhirvemana Linux - Newbie 1 11-25-2004 01:45 PM
sem has incomplete type error in building the filesystem image sudhirvemana Linux - Software 0 11-25-2004 03:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration