Dwith Swig / Examples /
Pragma
Difference (last change) (no other diffs, normal page display)
Deleted: 158,231d157
![]() |
|
C++ classes with pragma
This example has been constructed to illustrate the solution which I have developed to solve the /Problem. The example has a C++ header file defining two classes A and B. In the application B has a member A. As SWIG puts the D code into two separate files, the code for class B needs access to the definition of class A. This is achieved using an import statement in the D code. The insertion of extra code is handled using a pragma command within the SWIG interface file.
Code to be wrapped
example.h
![]() |
|
Interface File
example.i
![]() |
|
- This gives an example of use of the pragma command to define the import statement to be added. Each pragma command remains in force until another with the same name is given. This can be used to control different insertions into several classes.
- It also gives an example of the use of a predefined constant SWIGDMD which can be use to control different actions to be taken when wrapping for different target languages. See /MoreAboutSwig .
- Note also that in this case the class definition for D is not taken directly from the C++ header file.
Run SWIG
![]() |
|
In this case the command echoes the output from the processing of the pragma statement:
![]() |
|
The output is the following files
- example.d which is empty
- classA.d
- classB.d
- examplePINVOKE.d
- example_wrap.cxx
Example Application
runex.d
![]() |
|
Compile and Link
Linux
![]() |
|
Note that this case has no seperate C++ file of function bodies.
Windows to follow.
Output
![]() |
|