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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:06:48+00:00 2026-05-23T04:06:48+00:00

I am creating a python module that is implemented in C++. I am using

  • 0

I am creating a python module that is implemented in C++. I am using SWIG to create the interface. There are various ways to create the extension, I’m using the “preferred approach,” which is via python’s distutils and which is described here. The name of my module is “ParseEvents,” and to compile it I run the following two commands:

swig -c++ -python ParseEvents.i
python setup.py build_ext --inplace

The first command creates a file ParseEvents_wrap.cxx

The second command uses the following setup.py file:

from distutils.core import setup, Extension

ParseEvents_module = Extension('_ParseEvents',
                               sources=['ParseEvents_wrap.cxx',],
                               extra_compile_args=["-Wno-deprecated","-O3"],
                               )
setup (name = 'ParseEvents',
              ext_modules = [ParseEvents_module,],
              py_modules = ["ParseEvents"]
              )

Question: Where and how do I specify that I want my C++ code to be compiled with the -O3 compiler tag? I guessed that it would just be in the “extra_compile_args” part of the setup.py file, but that doesn’t seem to be the case. When I run the second command (python setup.py build_ext –inplace), here’s the output:

running build_ext
building '_ParseEvents' extension
creating build
creating build/temp.linux-x86_64-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c ParseEvents_wrap.cxx -o build/temp.linux-x86_64-2.4/ParseEvents_wrap.o -Wno-deprecated -O3
c++ -pthread -shared build/temp.linux-x86_64-2.4/ParseEvents_wrap.o -o _ParseEvents.so

Note that both the -O2 and -O3 flags are present in the second to last line in the output—I’d like to remove the -O2.

  • 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-23T04:06:48+00:00Added an answer on May 23, 2026 at 4:06 am

    The GCC doc explicitly says:

    http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Optimize-Options.html

    If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.

    This means your code will be compiled with -O3 in effect, just as you want it. No need to bother for duplicate optimization flags.

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

Sidebar

Related Questions

Is there any module for creating Excel charts with embedded charts in Python? The
If you are creating a 1d array in Python, is there any benefit to
I am using a module that is part of a commercial software API. The
I want to create a user group using python on CentOS system. When I
I need to install a python module in the site packages that also will
Which is better for creating a settings file for Python programs, the built-in module
I'm creating a basic database utility class in Python. I'm refactoring an old module
I'm creating a Python module. My question is how can I organize the distribution
I have a Python application (with GUI, using PyQt4) that gets spawned by the
I'm trying to expose one of my classes to python using boost's python module.

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.