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