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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:07:07+00:00 2026-05-23T02:07:07+00:00

In SWIG, what is the difference between the %include directive, and the standard C

  • 0

In SWIG, what is the difference between the “%include” directive, and the standard C “#include”?

For instance, in all the tutorials, why do they typically look something like this:

%module my_module

%{
#include "MyHeader.h"
%}

%include "MyHeader.h"

This seems redundant to me. Perhaps somebody with knowledge can clarify.

Is there a preferred method for including C++ code?

  • 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-23T02:07:08+00:00Added an answer on May 23, 2026 at 2:07 am

    The stuff in %{ ... %} is passed through directly to the output; it is not itself interpreted by SWIG. So the #include is there to make sure the generated C/C++ code includes that header.

    %include, by contrast, is a SWIG directive. It tells SWIG to process that header file before proceeding. This way SWIG will learn about (and generate wrappers for) the types and functions declared in that header file.

    If the header is very complex, it might confuse SWIG or result in very large output (as SWIG tries to generate a wrapper for everything within). In such cases, you are better off manually declaring just the parts of the header that you need SWIG to process, and omit the %include. But you still may want the #include in order for the generated C++ to compile.

    [update]

    As for “preferred”, SWIG is more about what works than what is “preferred”… If you have a very clean header file declaring a nice interface for a single class, you can just %include it and have SWIG automatically generate the wrappers. If your header file is very hairy (e.g. iostream), you should manually tell SWIG what to wrap. But there is no hard and fast rule.

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

Sidebar

Related Questions

The SWIG documentation explains how a variety of input types in C, like this:
I really like the idea of automatic binding generation like SWIG does. But it
I am using SWIG to pass numpy arrays from Python to C++ code: %include
My application is using SWIG to communicate between c++ and python on windows. suppose
Currently I have a set of SWIG wrappers for my classes and it all
I would like to use a .jar file generated by SWIG in an Android
This is a noob question. I'm trying to learn how to use SWIG to
This is a really specific compilation problem involving C++, SWIG and Lua. I have
This may or may not be a SWIG question. I am trying to return
I am totally new to SWIG interfaces and how to use this with C

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.