hi all,
im getting the following compilation error when trying to compile a file under /proc using 5.5 RHEL
Code:
/*
* procfs1.c - create a "file" in /proc
*
*/
#include <linux/module.h> /* Specifically, a module */
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
#define procfs_name "helloworld"
/**
* This structure hold information about the /proc file
*
*/
struct proc_dir_entry *Our_Proc_File;
/* Put data into the proc fs file.
*
* Arguments
* =========
* 1. The buffer where the data is to be inserted, if
* you decide to use it.
* 2. A pointer to a pointer to characters. This is
* useful if you don't want to use the buffer
* allocated by the kernel.
* 3. The current position in the file
* 4. The size of the buffer in the first argument.
* 5. Write a "1" here to indicate EOF.
* 6. A pointer to data (useful in case one common
* read for multiple /proc/... entries)
*
* Usage and Return Value
* ======================
* A return value of zero means you have no further
* information at this time (end of file). A negative
* return value is an error condition.
*
* For More Information
* ====================
* The way I discovered what to do with this function
* wasn't by reading documentation, but by reading the
* code which used it. I just looked to see what uses
* the get_info field of proc_dir_entry struct (I used a
* combination of find and grep, if you're interested),
* and I saw that it is used in <kernel source
* directory>/fs/proc/array.c.
*
* If something is unknown about the kernel, this is
* usually the way to go. In Linux we have the great
* advantage of having the kernel source code for
* free - use it.
*/
int
procfile_read(char *buffer,
char **buffer_location,
off_t offset, int buffer_length, int *eof, void *data)
{
int ret;
printk(KERN_INFO "procfile_read (/proc/%s) called\n", procfs_name);
/*
* We give all of our information in one go, so if the
* user asks us if we have more information the
* answer should always be no.
*
* This is important because the standard read
* function from the library would continue to issue
* the read system call until the kernel replies
* that it has no more information, or until its
* buffer is filled.
*/
if (offset > 0) {
/* we have finished to read, return 0 */
ret = 0;
} else {
/* fill the buffer, return the buffer size */
ret = sprintf(buffer, "HelloWorld!\n");
}
return ret;
}
int init_module()
{
Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL);
if (Our_Proc_File == NULL) {
remove_proc_entry(procfs_name, &proc_root);
printk(KERN_ALERT "Error: Could not initialize /proc/%s\n",
procfs_name);
return -ENOMEM;
}
Our_Proc_File->read_proc = procfile_read;
Our_Proc_File->owner = THIS_MODULE;
Our_Proc_File->mode = S_IFREG | S_IRUGO;
Our_Proc_File->uid = 0;
Our_Proc_File->gid = 0;
Our_Proc_File->size = 37;
printk(KERN_INFO "/proc/%s created\n", procfs_name);
return 0; /* everything is ok */
}
void cleanup_module()
{
remove_proc_entry(procfs_name, &proc_root);
printk(KERN_INFO "/proc/%s removed\n", procfs_name);
}
here are the compilcation errors im getting:
Code:
[root@SRV-00-035 home]# g++ procfs1.cpp -o procfs1 -v -I /usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)
/usr/libexec/gcc/x86_64-redhat-linux/4.1.2/cc1plus -quiet -v -I /usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/ -D_GNU_SOURCE procfs1.cpp -quiet
-dumpbase procfs1.cpp -mtune=generic -auxbase procfs1 -version -o /tmp/ccD2mF0Q.s
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/x86_64-redhat-linux
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward
/usr/local/include
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include
/usr/include
End of search list.
GNU C++ version 4.1.2 20080704 (Red Hat 4.1.2-48) (x86_64-redhat-linux)
compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-48).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ad35c03ce9997656f54e642ebd49f167
In file included from /usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/lockdep.h:13,
from /usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/spinlock_types.h:18,
from /usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/spinlock.h:78,
from /usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/module.h:10,
from procfs1.cpp:6:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/list.h:1031:2: warning: #warning "don't include kernel headers in userspace"
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h: In function גint get_bitmask_order(unsigned int)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:15: error: גflsג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h: In function גint get_count_order(unsigned int)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:23: error: גflsג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h: In function גlong unsigned int hweight_long(long unsigned int)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:31: error: גhweight32ג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:31: error: גhweight64ג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h: In function גunsigned int fls_long(long unsigned int)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:99: error: גflsג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:100: error: גfls64ג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h: At global scope:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:103: error: ג__ffs64ג declared as an גinlineג variable
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:103: error: גu64ג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/bitops.h:104: error: expected ג,ג or ג;ג before ג{ג token
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h:180: error: expected ג,ג or ג...ג before גnewג
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h: In function גlong unsigned int __cmpxchg(volatile void*, long unsigned int, long unsigned int)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h:183: error: גsizeג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h:187: error: expected type-specifier before ג)ג token
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h:193: error: expected type-specifier before ג)ג token
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h:199: error: expected type-specifier before ג)ג token
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/asm/system.h:205: error: expected type-specifier before ג)ג token
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/spinlock.h: In function גvoid smp_mb__after_lock()ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/spinlock.h:257: error: גbarrierג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/marker.h: At global scope:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/marker.h:33: error: גva_listג has not been declared
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/percpu.h: In function גvoid* __alloc_percpu(size_t)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/percpu.h:51: error: גGFP_KERNELג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/percpu.h:51: error: גkmallocג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/percpu.h:53: error: גmemsetג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/percpu.h: In function גvoid free_percpu(const void*)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/percpu.h:58: error: גkfreeג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/module.h: At global scope:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/module.h:51: error: field גattrג has incomplete type
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/module.h:62: error: field גkobjג has incomplete type
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h:79: error: field גlistג has incomplete type
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h:249: error: expected ג,ג or ג...ג before גnewג
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h:264: error: field גvfs_inodeג has incomplete type
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h: In function גproc_inode* PROC_I(const inode*)ג:
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h:269: error: expected primary-expression before גstructג
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h:269: error: גvfs_inodeג was not declared in this scope
/usr/src/kernels/2.6.18-194.el5-xen-x86_64/include/linux/proc_fs.h:269: error: גcontainer_ofג was not declared in this scope
procfs1.cpp: In function גint procfile_read(char*, char**, off_t, int, int*, void*)ג:
procfs1.cpp:61: error: גKERN_INFOג was not declared in this scope
procfs1.cpp:61: error: גprintkג was not declared in this scope
procfs1.cpp:79: error: גsprintfג was not declared in this scope
procfs1.cpp: In function גint init_module()ג:
procfs1.cpp:91: error: גKERN_ALERTג was not declared in this scope
procfs1.cpp:92: error: גprintkג was not declared in this scope
procfs1.cpp:98: error: גS_IRUGOג was not declared in this scope
procfs1.cpp:103: error: גKERN_INFOג was not declared in this scope
procfs1.cpp:103: error: גprintkג was not declared in this scope
procfs1.cpp: In function גvoid cleanup_module()ג:
procfs1.cpp:110: error: גKERN_INFOג was not declared in this scope
procfs1.cpp:110: error: גprintkג was not declared in this scope
[root@SRV-00-035 home]#