Make a static, dynamic library file under LinuxUNIX

xiaoxiao2021-03-06  40

There is a friend reflecting the Log_Fun and DLL_Run of the downstairs, do not know how to use, sorry, did not write detailed usage, today, combined with the actual example to use the method of use of LOG_FUN. First compilation, static and dynamic library // below is made to copy my machine to test MakefileHomedir = / root / testuserlibdir = $ (Homedir) / lib_include = $ (HomeDir) / Pub_inc

INCLUDE = -i $ (userinclude) cflags = -c -o -wall -march = i686 -fpic

.c.o: CC $ (Include) $ (CFLAGS) $

DEFAULT: LoGERR SOLOG

LOG_OBJ = log_func.o LoGerr: $ (log_obj) Ar RCS $ (UserLibdir) / lib $ @. A $ (log_obj) so_obj = log_func.o Errproc.osolog: $ (SO_OBJ) CC -SHARED -W1,-Soname, Libsolog . So -O $ (userlibdir) / lib $ @. SO.1.0.0 $ (SO_OBJ) -lc make is OK. First write a simple test driver, as follows: #include #include #include "log_def.h"

INT main (void) {

FILE * FP; PUTS ("Testing Err_Write_Log"); if ((fp = fopen ("foPen (" R ")) == null) {Write_log (Error_Log,"% s |% D: Open the file does not exist! " , __ file __, __ line__);

} EXIT (EXIT_SUCCESS);} Compile loading static library file GCC Test.c -o test lib / libloGerr.a carrier library file GCC Test.c -o test lib / libsolog.so adds, in the C environment, to call Compiled good C library, must be declared: Extern "C" {int Write_log (int il_flag, const char * pformat, ...);}

转载请注明原文地址:https://www.9cbs.com/read-60723.html

New Post(0)