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

  • Home
  • SEARCH
  • 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 7647017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:21:31+00:00 2026-05-31T10:21:31+00:00

I have a working python wrapper for C++ code (as suggested here Calling C/C++

  • 0

I have a working python wrapper for C++ code (as suggested here Calling C/C++ from python?
) using ctypes. But the problem is with main function of the code. When I do something like

         extern "C" {
             void call_main(){ main();}
         }

in my c++ code and then call this function via python wrapper

            ...
            lib = cdll.lib('./mylib.so')
            def run():
                lib.call_main()

-> I get “segmentation fault”.

The funny part is that when i copy paste my main method code into function called e.g. test (so it is int test() {….#pasted code…} in c++ code), extern it and then call lib.test()

=> And eveything works fine… So it must be a problem with the main function being called main or something

  • 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-31T10:21:32+00:00Added an answer on May 31, 2026 at 10:21 am

    In C++ calling main() recursively is not allowed ( see 3.6.1, basic.start.main, paragraph 3). Also, you need a C++ aware entry point when you want to call C++ functionality. You can sometimes get away with calling C++ functionality without this but what is going to work and what is not isn’t entirely straight forward. The obvious problem is with global objects needing initialization.

    Just put the code you want to call into a different function and call this.

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

Sidebar

Related Questions

I'm trying to simulate some code that I have working with SQL but using
I have recently been working with Python using Komodo Edit and other simpler editors
I'm working in Python and using the MySQLdb module. I have a working connection
I have emacs and python working on OSX, but I'd like to get a
I have a rather peculiar problem, when i'm working on Python in Max OSX
I have been teaching myself OpenGL programming using the Python wrapper PyOpenGL, and am
I have a working application using python and zeromq and I would like to
I need to have an at-home project now that I'm working on Python/Django at
I am working with Google App Engine and Python. I have a model with
I'm working on my first object oriented bit of python and I have the

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.