Here is how to create and use dynamic link libraries in Ubuntu. 1. Create the experiment program dll_fun.c # include & lt; stdio. h & gt; voiddll_function (constchar * szString) {& n
Here is how to create and use dynamic link libraries in Ubuntu.
1. Create the experiment program dll_fun.c
# Include
Void dll_function (const char * szString)
{
Printf ("% s \ n", szString );
}
2. compile and generate a dynamic link library
Generate an o file first
Gcc-c-fPIC dll_fun.c // The-fPIC option must be added here, otherwise the next compilation fails.
Compile again
Gcc-shared-fPIC-o libdllfun. so dll_fun.o // generate dynamic link library libdllfun. so
3. Copy the generated file to/usr/lib.
4. Create the main. c method to call the dynamic library
Void dll_function (const char * szString );
Int main ()
{
Dll_function ("This is the words of the dll function !!!!!! ");
Return 0;
}
5. Compile main. c to generate an executable file
6. Run./main to obtain This is the words of the dll function !!!!!!
7. Write main. jl of julia Program
Ccall (: dll_function, "libdllfun"), Void, (Ptr {Uint8},), "Hello GONG Qingkui ")
8. Compile and run julia main. jl.
The result is Hello GONG Qingkui.
Ps: use environment variables to indicate the link library file address export LD_LIBRARY_PATH =/home/owner/test/lib
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2