How to create and use dynamic link libraries in Ubuntu

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.