본문 바로가기
C/SWIG

SWIG 라이브러리

by yororing 2024. 6. 24.

00 개요

  • To help build extension modules, SWIG is packaged with a library of support files that you can include in your own interfaces. 
  • These files often define new SWIG directives or provide utility functions that can be used to access parts of the standard C and C++ libraries. 
  • This chapter provides a reference to the current set of supported library files. 
  • Compatibility NOTE: Older versions of SWIG included a number of library files for manipulating pointers, arrays, and other structures. Most these files are now deprecated and have been removed from the distribution. Alternative libraries provide similar functionality. Please read this chapter carefully if you used the old libraries. 8.1 The %include directive and library search path

01 The %include directive and library search path

  • Library files are included using the %include directive. 
  • 파일을 찾을 때 다음과 같은 순으로 디렉토리들을 search함:
    1. 현재 디렉토리
    2. -I 옵션으로 지정된 디렉토리
    3. ./swig_lib
    4. SWIG library install location as reported by swig -swiglib (e.g., /usr/local/share/swig/1.3.30)
    5. On Windows, a directory Lib relative to the location of swig.exe is also searched
  • Within each directory, SWIG first looks for a subdirectory corresponding to a target language (e.g., python, tcl, etc.)
  • If found, SWIG will search the language specific directory first. This allows for language-specific implementations of library files.
  • You can ignore the installed SWIG library by setting the SWIG_LIB environment variable. Set the environment variable to hold an alternative library directory.
  • The directories that are searched are displayed when using -verbose commandline option

02 C Arrays and Pointers

  • library modules for manipulating low-level C arrays and pointers
  • The primary use of these modules is in supporting C declarations that manipulate bare pointers such as int *, double *, or void *
  • The modules can be used to allocate memory, manufacture pointers, dereference memory, and wrap pointers as class-like objects
  • Since these functions provide direct access to memory, their use is potentially unsafe and you should exercise caution

1. cpointer.i

  • The cpointer.i module defines macros that can be used to generate wrappers around simple C pointers
  • primary use: generating pointers to primitive datatypes such as int and double

2. carrays.i

  • This module defines macros that assist in wrapping ordinary C pointers as arrays
  • The module does not provide any safety or an extra layer of wrapping.
  • It merely provides functionality for creating, destroying, and modifying the contents of raw C array data.

3. cmalloc.i

  • This module defines macros for wrapping the low-level C memory allocation functions malloc(), calloc(), realloc(), and free()

4. cdata.i 

  • The cdata.i module defines functions for converting raw C data to and from strings in the target language.
  • primary applications: packing/unpacking of binary data structures---for instance, if you needed to extract data from a buffer.
  • The target language must support strings with embedded binary data in order for this to work.

03 C String Handling

1. Default string handling

2. Passing binary data 

3. Using %newobject to release memory

4. cstring.i 

04 STL/C++ Library

1. std_string.i

2. std_vector.i

3. STL exceptions 

 

 

05 Utility Libraries

1. exception.i

참조

  1. https://www.swig.org/Doc1.3/Library.html 
  2.  
  3.  
  4.  

'C > SWIG' 카테고리의 다른 글

SWIG (C/C++와 다른 언어 연결하는 도구)  (0) 2024.06.21