swig工具介绍
来源:互联网 发布:淘宝直播小二钉钉群 编辑:程序博客网 时间:2024/05/21 02:54
SWIG 是一个非常优秀的开源工具,支持您将 C/C++
代码与任何主流(脚本)语言(Ruby、Perl、JAVA、c#)相集成。 能根据定义的规则(*.i)文件生成供其它主流(脚本)语言调用的代码。
基本的使用指南http://www.swig.org/tutorial.html
一个示例:
print_hello.h
#ifndef PRINT_HELLO_H__
#define PRINT_HELLO_H__
#ifdef __cplusplus
extern "C" {
#endif
void print();
#ifdef __cplusplus
}
#endif
#endif
print_hello.cpp
#include "print_hello.h"
#include <stdio.h>
void print()
{
printf("hello swig\n");
}
print_hello.i
%module print_hello
%{
extern void print();
%}
extern void print();
main.java
public class main {
public static void main(String argv[]) {
// System.out.println(System.getProperty("java.library.path"));
System.loadLibrary("print_hello");
print_hello.print();
}
}
build.sh
swig -java print_hello.i
gcc -fPIC -c print_hello.cpp print_hello_wrap.c -I/usr/lib/jvm/java-6-openjdk-amd64/include
gcc -shared print_hello.o print_hello_wrap.o -o libprint_hello.so
javac main.java
运行:
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
java main
输出:
hello swig
- swig工具介绍
- SWIG
- SWIG
- SWIG
- SWIG
- SWIG
- SWIG
- swig
- Swig封装C/C++——介绍
- 工具介绍
- 工具介绍
- 工具介绍
- 工具介绍
- 链接脚本语言和C/C++之间的最好的工具:SWIG
- android 使用swig工具, 依据JNI文件快速生成对应java文件
- swig教程
- swig入门
- swig 简介
- NYOJ44 - 子串和(最大连续子串和)
- ecg-id实验系统
- 匆匆的世界
- Java Persistence with MyBatis 3(中文版) 第五章 与Spring集成
- Jscharts 的属性和方法
- swig工具介绍
- C# 转换
- 破除关于比特币的谬论
- ACM进阶之路(转)
- linux系统在线求助 man page
- WordPress上传文件提示“无法建立目录uploads”的解决方法
- apache kafka性能测试命令使用和构建kafka-perf
- 【剑指offer】Q29:数组中出现次数超过一半的数字
- struts2 自定义表单