Created
March 25, 2017 01:08
-
-
Save jinliangwei/441483e62934f7cf00bd2da37a8c3ac8 to your computer and use it in GitHub Desktop.
After "make all", running "julia helloworld.jl" causes abort due to "attempt to free invalid pointer". However, running "./test_main" works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace the string below with the absolute path to libtest.so | |
ccall((:helloworld, "[abosolute path to the libtest.so]"), Void, ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: libtest.so test_main | |
CXX = g++ -std=c++14 | |
test.pb: test.proto | |
protoc --cpp_out=. test.proto | |
test.pb.h: test.pb | |
test.pb.cc : test.pb | |
test.o: test.c test.pb.h | |
$(CXX) -fPIC $(CFLAGS) -c $< -o $@ | |
test_main: test_main.c | |
gcc $< -ldl -o $@ | |
test.pb.o: test.pb.cc | |
$(CXX) -fPIC $(CFLAGS) -c $< -o $@ | |
libtest.so: test.o test.pb.o | |
gcc -shared -Wl,-soname,libtest.so.0 -o libtest.so.0.0 \ | |
$^ -lprotobuf -ltcmalloc | |
ln -sf libtest.so.0.0 $@ | |
clean: | |
rm -f *.o test.pb.h test.pb.cc *.so *.so.* test_main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
extern "C" { | |
void helloworld() { | |
std::cout << "hello world!" << std::endl; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
message Test { | |
required int32 index = 1; | |
required string value = 2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlfcn.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
dlerror(); | |
void *lib = dlopen("/home/ubuntu/test_protobuf/libtest.so", RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND); | |
if (lib == NULL) { | |
const char* err_msg = dlerror(); | |
printf("something wrong: %s\n", err_msg); | |
return 1; | |
} | |
void *void_fptr = dlsym(lib, "helloworld"); | |
void (*fptr)(void); | |
fptr = (void (*)(void)) void_fptr; | |
if (void_fptr == NULL) { | |
const char* err_msg = dlerror(); | |
printf("something wrong: %s\n", err_msg); | |
return 1; | |
} | |
fptr(); | |
dlclose(lib); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment