LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-27-2010, 10:00 AM   #1
i_r_tomash
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
error: was not declared in this scope compilation error


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);
}
[\code]

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]#
 
Old 05-27-2010, 10:42 AM   #2
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
I will respond to your C/C++ question shortly. For now, please edit your OP to use the correct tag for source code. It seems that you used backslash "\" instead of slash "/" as a terminator. Visit your orignial post (OP) and seelect the Edit button. Make your changes, then Save.

It also helps to limit your posted code to parts that are relevant chunks rather than long file inclusions. Use an attachment if you really must provide the entire
file ... or wait for folks to ask for more.

Here is your source code:
Code:
Here is some code
Here is your compiler output:
Code:
Here is
more code
Proper use of code-blocks is important for this sort of posting so that your readers might scroll separately within each block without scrolling the entire page.

Cheers,
~~~ 0;-Dan

Last edited by SaintDanBert; 05-27-2010 at 11:06 AM.
 
Old 05-27-2010, 11:00 AM   #3
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
When we think about "not in this scope" we must remember what the rules of scope tell us.

1. file scope -- declarations within the current file. Whatever gets declared is visible below the point of declaration. While header files are separate from a file system perspective, the #include semantics cause any header file contents to be considered as if they were in-line as a physical part of the file system file where #include <filename> appeared. Each such file+headers combination is known as a "compilation unit"

2. global scope -- declarations within a given file system file, but that appear outside of any function block. These items are available below again, and may be accessed by any function declared there after

3. local scope -- declarations that appear within a function block. These items are only available within this specific function block.

There are various ways to inform one compilation unit about declarations made in a different compilation unit. In addition, there are ways to make declarations visible when they might otherwise
be hidden. C++ expands on this with concepts like public and private in addition to local and global or internal and external.

In your case, I suspect you make reference to something fls before it is visible within the given compilation unit. Kernel and similar headers are notorious for use of conditional compilation and you might not have met the requirements for some part to get processed even though the relevant code fragment is available in the header files you used.

I hope that I've helped you plan ways to identify your specific situation. I'm not a kernel hacker, but I've written a lot of C/C++.

~~~ 8d;-Dan

Disclaimer -- I wasn't trying to deliver an exhaustive discussion of C/C++ scoping rules and details. The web and libraries are filled with books and articles that cover the topic much better than I ever will. In this case, I wanted to offer enough about the topic to jog the OP memory of details they might have forgotten or otherwise overlooked. I take full responsibility for any rust or dust evident in my choice of descriptive language.
 
  


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
Problem compiling (error: ‘strcmp’ was not declared in this scope) beboppinbobby Linux - Newbie 4 12-19-2009 01:33 AM
aria2, ‘assert’ was not declared in this scope , compiler error adityasharma Linux - Newbie 4 07-31-2009 05:51 AM
Compiling tesseract-2.03: error: ‘INT32’ was not declared in this scope J_Szucs Linux - Software 10 03-05-2009 02:35 PM
/ArgParser.cpp:207: error: 'atoi' was not declared in this scope Jane2008 Linux - Newbie 2 11-07-2008 09:23 AM
Error Prompt - 'Execute_command was not declared in this scope. Please help! thhuang Linux - Newbie 1 11-05-2007 12:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:41 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