Linux QT dynamic link library static Link Library learning notes

Source: Internet
Author: User

Http://hi.baidu.com/codeworkman/blog/item/32b6ccce51bf3622f9dc6141.html
==== Hello. h ====
# Ifndef hello_h
# Define hello_h
Extern "C" Void Hello (const char * Name );
# Endif

==== Hello. c ====
# Include <stdio. h>
# Include "Hello. H"
Void Hello (const char * name)
{
Printf ("Hello % s! \ N ", name );
}

==== Main. c ====
# Include "Hello. H"
Int main ()
{
Hello ("everyone ");
Return 1;
}

[Solution 0]
GCC hello. C main. c
GCC hello. C main. C-O hello

[Solution 1]
Gcc-C hello. c
Gcc-C main. c
GCC hello. O main. O-O hello

[Solution 2 static database]
Ar RCS libmyhello. A hello. o
Gcc-O hello main. C-static-L.-lmyhello

[Solution 3 dynamic library]
Gcc-shared-FPIC-O libmyhello. So hello. o
Gcc-O hello main. C-L.-lmyhello
MV libmyhello. So/usr/lib

[Partial options]
-Shared // specify to generate a dynamic link library, which is equivalent to an executable file.
-FPIC // indicates the code that is compiled into a separate position. Otherwise, the code segment cannot be shared;
-L. // indicates that the library to be linked is in the current directory.
-Ltest: // an implicit naming rule is used by the compiler to search for a dynamic library. That is, Lib is added before the given name, And. So is followed to determine the name.
LD_LIBRARY_PATH: // This variable indicates that the dynamic linker can load the path of the dynamic library.
LIBRARY_PATH: // specifies the path for searching files in the static Link Library of the program.

[Using static libraries in QT]
Add
Libs + = $ (outdir) libmyhello.
Libs + = $ (sourcedir)/libmyhello.
1st are output directories and 2nd source program directories. Choose one as you like, and copy the libmyhello. A file to your directory.
In the CPP file # include "Hello. H"

[Using dynamic libraries with QT]
Copy file libmyhello. So to the specified link library path/lib or/usr/local/lib
Add
Libs + = libmyhello. So
In the CPP file # include "Hello. H"

[Extern "C"]
The file hello. h contains the extern "C" keyword, indicating that the C function is called in the C ++ environment.
Qt itself is built by the C ++ class, so when using the. c file, this keyword must be added
 

 

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.