asm-generic headers

Hi,

I'm trying to use the __cmpxchg_local_generic function I've found which on my ubuntu install is declared in:

/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h

it appears from the code that this function is in c, given that it uses 'new' as a parameter name.

What procedure should I use to access this function in c++ code?

Currently I've got the following in Main.cpp:
1
2
3
4
5
#include "asm-generic/cmpxchg-local.h"
int main(void)
{
    return 0;
}


compiled with:

g++ -I/usr/src/linux-headers-2.6.28-15/include Main.cpp

I get complaints about the 'new' token. So instead I compile with:

gcc -x c -I/usr/src/linux-headers-2.6.28-15/include Main.cpp

which produces the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h: In function ‘__cmpxchg_local_generic’:
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:25: error: ‘u8’ undeclared (first use in this function)
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:25: error: (Each undeclared identifier is reported only once
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:25: error: for each function it appears in.)
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:25: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:27: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:29: error: ‘u16’ undeclared (first use in this function)
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:29: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:31: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:33: error: ‘u32’ undeclared (first use in this function)
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:33: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:35: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:37: error: ‘u64’ undeclared (first use in this function)
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:37: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:39: error: expected expression before ‘)’ token
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h: At top level:
/usr/src/linux-headers-2.6.28-15/include/asm-generic/cmpxchg-local.h:51: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__cmpxchg64_local_generic’


I'm at the point now where I'm assuming the linux-headers-<x> are not intended as an api for user code, but rather for compiling your kernel? If that's the case, could someone point me towards an accessible implementation of this function, or explain how I can access this one (which lib to link against once the code has compiled would also be useful).

Cheers.

Rob
You are going to have to create a .c file and a .h file. The .c file (compiled as C) includes the C header and implements
a wrapper function using parameter names that aren't keywords. The .h file must prototype your function in an extern "C"
block and take care to be compilable with a C++ compiler.
OK, thanks, that clears up how I should make this function accesible from *other* cpp files, but it doesn't explain the weird u8 undeclared error I'm getting during compilation of Main.cpp as c code (note the "-x c" switch to gcc).

I assume this is caused by some expected include order not being honored when I directly include cmpxchg-local.h?

I'll just do a grep for u8's typedef and work it out from there I think. Cheers
Topic archived. No new replies allowed.