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 6766109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:47:29+00:00 2026-05-26T14:47:29+00:00

I am attempting to call a C++ API from python. Following is the code

  • 0

I am attempting to call a C++ API from python. Following is the code in the pseudo form.

class Engine { // Singleton Class which does a heavy duty work
public:
    static Engine* getEngine();
    bool init();
private:
    static Engine* m_instance;
    Engine();
};

// Following the code to wrap the call to engine to call from python
// Its only a simplified form

//engine_module.c
#include <Engine.h>
PyObject* initengine() {
    Engine* e = Engine::getInstance();
    e->init();
   // return the Py_BuildValue ...   
}

PyObject* initengine_module() {
//... init the module
}

// Python code
import engine_module
status = engine_module.init() 

Problem:
The Engine class is in libengine.so and when it inits it fails because internally dynamic_cast fails. The Engine in turns loads other libraries using dlopen(). I searched the net to add RTDL_GLOBAL and -E option while linking but still its not resolved. Am I supposed to add the -E option while compiling the python itself?
What could be the reason that Engine class works perfectly well when used in C++ code and does not work when used in python?

Edit 1:
To clarify on the question from Cat++:
libengine.so has many other classes which internally in Engine::init() uses dynamic_cast<>. The classes involved in dynamic_cast are not exposed to python at all. Only the Engine::init() is exposed.

Edit 2:
The platform is Red Hat Linux and the compiler is Intel

  • 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-26T14:47:29+00:00Added an answer on May 26, 2026 at 2:47 pm

    The question is how and when the dynamic library are loaded. The code
    you show in engine_module.c references Engine, so the library with
    Engine will be automatically loaded before any of the initialization
    code in engine_module.c is executed. Similarly, any libraries used by
    Engine will be loaded before the library with Engine is loaded. All
    of which will be loaded using the flags Python used to load its
    interface module. (RTDL_LOCAL is my guess.) Any dlopen you invoke
    later will find that the module has already been loaded, and ignore the
    request—including ignoring any options to dlopen you might have
    passed.

    The way we solved this was to create a special loader module, which
    contained no direct references to any of the other modules. Python
    loads this module, which implements the initxxx function. The
    initxxx function explicitly loads all of the other modules needed, in
    a dependency determined order. (If A used B, B will be loaded before A.)
    With RTDL_GLOBAL, of course. In your case, this would be the
    libraries used by Engine, then Engine. The last module to be loaded
    would be the one with the Python interface; we put the Python
    initialization code in the constructor of a static object, so it would
    be executed automatically when the object was loaded, but you can also
    put it in a named function, as long as you get the address of this
    function using dlsym, rather than declaring it extern in any
    fashion. The important thing is to ensure that all of the libraries are first loaded by your explicit dlopen, and not implicitly as a result of an undefined external in some library loaded earlier.

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

Sidebar

Related Questions

I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code
I'm attempting to call a method which is outside the class I'm working in
I'm attempting to expose a single API call using three different authentication mechanisms: django's
This is my first time attempting to call an ASP.NET page method from jQuery.
I'm attempting to load data from an undocumented API (OsiriX). Getting the NSManagedObject like
I'm trying to figure out how to launch a Service from a singleton class
Introduction I am attempting to replace an on-call cell phone which is carried by
I am attempting to call an ASP.NET page from a classic ASP page on
I am getting an error when attempting to call a stored proc from my
I'm attempting to do a Facebook FQL Multiquery (via JS SDK FB.api call) 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.