Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extern C function in a namespace cannot be accessed #22

Closed
yanghao opened this issue Nov 17, 2021 · 2 comments
Closed

extern C function in a namespace cannot be accessed #22

yanghao opened this issue Nov 17, 2021 · 2 comments

Comments

@yanghao
Copy link

yanghao commented Nov 17, 2021

I am new to cppyy, not sure if this is an issue or simply I didn't get the right way to use it.

It seems that if a function is declared as extern "C" then it is not accessible from cppyy.
Here is a quick way to test it:

$ cat test.h
namespace test {
        extern "C" int test_extern_c(void);
        int test_normal(void);
}
$ python3
Python 3.10.0+ (heads/v3.10-dirty:099a94fba3, Nov  5 2021, 13:02:25) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cppyy
>>> cppyy.include("test.h")
True
>>> cppyy.gbl.test.test_normal
<cppyy.CPPOverload object at 0x7f1dfb343340>
>>> cppyy.gbl.test.test_extern_c
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: <namespace cppyy.gbl.test at 0x561e5d770300> has no attribute 'test_extern_c'. Full details:
  type object 'test' has no attribute 'test_extern_c'
  'test::test_extern_c' is not a known C++ class
  'test_extern_c' is not a known C++ template
  'test_extern_c' is not a known C++ enum
>>>
>>> cppyy.gbl.test_extern_c
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: <namespace cppyy.gbl at 0x561e5bf3e580> has no attribute 'test_extern_c'. Full details:
  type object '' has no attribute 'test_extern_c'
  'test_extern_c' is not a known C++ class
  'test_extern_c' is not a known C++ template
  'test_extern_c' is not a known C++ enum
>>>

Did I miss anything?

Thanks a lot.

@wlav
Copy link
Owner

wlav commented Nov 18, 2021

Thanks for the report! Now fixed in repo: wlav/cppyy-backend@068e895

Applying the above, if used from source, requires both rebuilding cppyy-cling and cppyy-backend, which is a bit of a hassle, but I can't think of a workaround, other than providing a manual helper/wrapper. (Which should probably be fine if there are no more than a handful of these functions.)

@yanghao
Copy link
Author

yanghao commented Nov 18, 2021

@wlav Thanks for confirming this. Yes, right now I just pick up the definition from header files and using cppdef to define it again and it works perfectly fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants