Python ʹÓÃC´úÂë——swig
Ref : http://www.swig.org/translations/chinese/tutorial.html
¼ÙÉèÄãÓÐһЩcÄãÏëÔÙ¼ÓPython.¡£¾ÙÀýÀ´ËµÓÐÕâôһ¸öÎļþexample.c
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
½Ó¿ÚÎļþ
ÏÖÔÚ£¬ÎªÁËÔö¼ÓÕâЩÎļþµ½Äãϲ»¶µÄÓïÑÔÖУ¬ÄãÐèҪдһ¸ö½Ó¿ÚÎļþ£¨interface file£©Í¶Èëµ½swigÖС£ÕâЩC functionsµÄ½Ó¿ÚÎļþ¿ÉÄÜÈçÏÂËùʾ£º
/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
½¨Á¢PythonÄ£¿é
ת»»±àÂëC³ÉPythonÄ£¿éºÜ¼òµ¥£¬Ö»ÐèÒª°´ÈçÏÂ×ö¼´¿É£¨Çë¼ûÆäËû²Ù×÷ϵͳµÄSWIG ¹²Ïí¿â°ïÖúÊֲᣩ:
unix % swig -python example.i
unix % gcc -c -fPIC
-m32
example.c example_wrap.c \
-I/usr/(local/include/python2.1)include/python2.4
unix % (ld)gcc
-shared -m32
example.o example_wrap.o -o _example.so
¹ØÓÚÒÔÉϺìÀ¶ÂÌÑÕÉ«×Ö½âÊÍ£º
1. -
Ïà¹ØÎĵµ£º
±¾ÎÄÀ´×Ô£º http://blog.pfan.cn/xiuandfang/24935.html
±êÇ©:C C ++ string String Êý¾Ý½á¹¹
C×Ö·û´®´¦Àíº¯ÊýµÄʵÏÖ
C×Ö·û´®´¦Àíº¯ÊýµÄʵÏÖ£¨Linux£©
#include <stddef.h>
char * ___strtok = NULL;
char * strcpy(char * dest,const char *src)
&nb ......
CºÍC++ÓïÑÔѧϰ×ܽá(Ò»)
֪ʶ½á¹¹:
1¡¢if,for,switch,goto
2¡¢#define,const
3¡¢Îļþ¿½±´µÄ´úÂë,¶¯Ì¬Éú³ÉÄÚ´æ,¸´ºÏ±í´ïʽ,strcpy,memcpy,sizeof
4¡¢º¯Êý²ÎÊý´«µÝ,ÄÚ´æ·ÖÅ䷽ʽ,ÄÚ´æ´íÎó±íÏÖ,mallocÓënewÇø±ð
5¡¢ÀàÖØÔØ¡¢Òþ²ØÓ븲¸ÇÇø±ð,externÎÊÌâ,º¯Êý²ÎÊýµÄȱʡ
ÖµÎÊÌâ,ºê´úÂëÓëÄÚÁªº¯ÊýÇø±ð
6¡¢¹¹ÔìºÍÎö¹ ......
/*
coder: ACboy
date: 2010-3-14
result: 1A
description: UVa 327 Evaluating Simple C Expressions
*/
#include <iostream>
#include <algorithm>
using namespace std;
struct Node {
char name;
int value;
int lastValue;
int pos;
};
int cmp(const Node & a, const Node &a ......
GCC Ö§³ÖÁËÐí¶à²»Í¬µÄÓïÑÔ£¬°üÀ¨ C¡¢C++¡¢Ada¡¢Fortran¡¢Objective C,Perl¡¢Python ºÍ Ruby£¬ÉõÖÁ»¹ÓÐJava¡£
¡¡¡¡Linux Äں˺ÍÐí¶àÆäËû×ÔÓÉÈí¼þÒÔ¼°¿ª·ÅÔ´ÂëÓ¦ÓóÌÐò¶¼ÊÇÓà C ÓïÑÔ±àд²¢Ê¹Óà GCC ±àÒëµÄ¡£
¡¡¡¡±àÒëC++³ÌÐò£º
¡¡¡¡-c Ö»±àÒë²»Á¬½Ó
¡¡¡¡g++ file1 -c -o file1.o
¡¡¡¡g++ file2 -c -o file2.o
¡¡¡¡g++ f ......
CµÄ±ä²ÎÎÊÌâÓëprintº¯ÊýµÄʵÏÖ
ÎÒÃÇÔÚCÓïÑÔ±à³ÌÖлáÓöµ½Ò»Ð©²ÎÊý¸öÊý¿É±äµÄº¯Êý,ÀýÈçprintf() Õâ¸öº¯Êý,ËüµÄ¶¨ÒåÊÇÕâÑùµÄ: int printf( const char* format, ...);
Ëü³ýÁËÓÐÒ»¸ö²ÎÊýformat¹Ì¶¨ÒÔÍâ,ºóÃæ¸úµÄ²ÎÊýµÄ¸öÊýºÍÀàÐÍÊǿɱäµÄ,ÀýÈçÎÒÃÇ¿ÉÒÔÓÐÒÔϲ»Í¬µÄµ÷Ó÷½·¨:
printf("%d",i);
&nb ......