Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5985877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:35:36+00:00 2026-05-22T22:35:36+00:00

I am using ctypes to access a shared library written in C. The C

  • 0

I am using ctypes to access a shared library written in C. The C source of the shared library contains an enum like

enum {
   invalid = 0,
   type1   = 1,
   type2   = 2
} type_enum;

On the Python side I was intending to just define integer constants for the various enum values, like:

INVALID = 0
TYPE1 = 1
TYPE2 = 2  

And then use these numerical “constants” in the Python code calling the C functions. This seems to work OK, however I would strongly prefer to get the numerical values for the enums directly from the shared library (introspection?); however using e.g. nm on the shared library it does not seem to contain any of the symbols ‘invalid’, ‘type1’ or ‘type2’. So my question is:

  1. Is it possible to extract the numerical values from enum definitions from a shared library – or is the whole enum concept ‘dropped on the floor’ when the compiler is done?
  2. If the enum values exist in the shared library – how can I access them from Python/ctypes?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:35:37+00:00Added an answer on May 22, 2026 at 10:35 pm

    Enum definitions are not exported so your current solution is the only one available.

    In any case, C enum values are nothing much more than integer constants. There’s no type safety on the C side, you can pass any integer values to an enum parameter. So it’s not like the C compiler is doing much anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried loading C shared library .so in Python using ctypes.CDLL class (Linux). Here
I've written some function callbacks using python's ctypes to access functions in a DLL.
I've written Python bindings using ctypes for the units library . The bindings themselves
in my python project I call a c++ dll using ctypes library. That c++
I am trying to use a dll in Python source using the ctypes. I
I am trying to use Python's ctypes library to access some methods in the
I am using ImageMagick library with Python ctypes . I wrote a following simple
I'm attempting to convert a C header into a Python library using ctypes and
I'm using ctypes to load a DLL in Python. This works great. Now we'd
I'm calling a C function using ctypes from Python. It returns a pointer to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.