Skip to content

Instantly share code, notes, and snippets.

@zhmz90
Last active Aug 28, 2016
Embed
What would you like to do?
#include "add2.h"
extern "C" {
int add2(int a , int b){
return a+b;
}
}
#ifdef __cplusplus
extern "C" {
#endif
int add2(int, int);
#ifdef __cplusplus
}
#endif
#include <stdio.h>
#include "add2.h"
int add3(int a, int b, int c){
return a+b+c;
}
int main(){
printf("test %d", add2(1,2));
}
add.so:*.c *.cpp *.h
gcc main.c add2.h add2.cpp -fpic -shared -o add.so
result = ccall((:add2,"/home/guo/Github/cpp/add.so"),Cint,(Cint,Cint),1,2)
println(result)
@zhmz90

This comment has been minimized.

Copy link
Owner Author

@zhmz90 zhmz90 commented Aug 28, 2016

使用 make 编译好shared library。

在Julia REPL中测试:

julia> ccall((:add2,"/home/guo/Github/cpp/add.so"),Cint,(Cint,Cint),1,2)
3

或者执行 julia test_shared_library_in_julia.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment