`
hanyh
  • 浏览: 235396 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

so description

阅读更多
How to generate a shared object: (Dynamically linked object library file.) Note that this is a two step process.

   1. Create object code
   2. Create library
   3. Optional: create default version using a symbolic link.

gcc -Wall -L/home/hanyh/workspace/cplusplus/linux prog.c -lctest -o prog
export LD_LIBRARY_PATH=/home/hanyh/workspace/cplusplus/linux/so:$LD_LIBRARY_PATH


Library creation example:

        gcc -Wall -fPIC -c *.c
        gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0   *.o
        mv libctest.so.1.0 /opt/lib
        ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so
        ln -sf /opt/lib/libctest.so.1.0 /opt/lib/libctest.so.1
             

    This creates the library libctest.so.1.0 and symbolic links to it.

    Compiler options:

        * -Wall: include warnings. See man page for warnings specified.
        * -fPIC: Compiler directive to output position independent code, a characteristic required by shared libraries. Also see "-fpic".
        * -shared: Produce a shared object which can then be linked with other objects to form an executable.
        * -W1: Pass options to linker.
          In this example the options to be passed on to the linker are: "-soname libctest.so.1". The name passed with the "-o" option is passed to gcc.
        * Option -o: Output of operation. In this case the name of the shared object to be output will be "libctest.so.1.0"

    Library Links:

        * The link to /opt/lib/libctest.so allows the naming convention for the compile flag -lctest to work.
        * The link to /opt/lib/libctest.so.1 allows the run time binding to work. See dependency below.

Compile main program and link with shared object library:

    Compiling for runtime linking with a dynamically linked libctest.so.1.0:

        gcc -Wall -I/path/to/include-files -L/path/to/libraries prog.c -lctest -o prog
    Use:
        gcc -Wall -L/opt/lib prog.c -lctest -o prog
         

    Where the name of the library is libctest.so. (This is why you must create the symbolic links or you will get the error "/usr/bin/ld: cannot find -lctest".)
    The libraries will NOT be included in the executable but will be dynamically linked during runtime execution.

List Dependencies:

The shared library dependencies of the executable can be listed with the command: ldd name-of-executable

    Example: ldd prog

            libctest.so.1 => /opt/lib/libctest.so.1 (0x00002aaaaaaac000)
            libc.so.6 => /lib64/tls/libc.so.6 (0x0000003aa4e00000)
            /lib64/ld-linux-x86-64.so.2 (0x0000003aa4c00000)
       

Run Program:

    * Set path: export LD_LIBRARY_PATH=/opt/lib:$LD_LIBRARY_PATH
    * Run: prog
Prototype include file for the library: ctest.h

    #ifndef CTEST_H
    #define CTEST_H

    #ifdef __cplusplus
    extern "C" {
    #endif

    void ctest1(int *);
    void ctest2(int *);

    #ifdef __cplusplus
    }
    #endif

    #endif
         

    Use the notation extern "C" so the libraries can be used with C and C++. This statement prevents the C++ from name mangling and thus creating "unresolved symbols" when linking.

       nm - list symbols from object files
分享到:
评论

相关推荐

    Essbase在Unix or Linux下使用ODBC数据源

    Description=Oracle Wire Protocol HostName=buzhidao PortNumber=1521 SID=orcl [ODBC] IANAAppCodePage=113 InstallDir=/u01/hyperion/common/ODBC/Merant/5.2 Trace=0 TraceDll=/u01/hyperion/common/ODBC/...

    BIEE配置ODBC连接impala

    Description=Oracle7.1ImpalaWireProtocol ArraySize=1024 Database=default DefaultLongDataBuffLen=1024 DefaultOrderByLimit=-1 EnableDescribeParam=0 HostName=10.159.12.20 LoginTimeout=30 LogonID=...

    linux下通过unixODBC连接gbase8s.docx

    Description=GBASE ODBC DRIVER Database=sysmaster LogonID=gbasedbtpwd Servername=gbasedb ``` 这里,`gbasedb`是DSN,`iclit09b.so`是GBase8s的ODBC驱动程序,`sysmaster`是默认的数据库,`LogonID`和`...

    oracle访问mysql配置

    Driver=/usr/lib64/libmyodbc5a.so Description=MySQL Server Server=192.168.9.151 Port=3306 User=odbc Password=odbc Database=test Option=3 Socket= ``` 并更改 `odbc.ini` 的所有者为 `oracle` ...

    essbase安装和odbc的配置

    Description=DataDirect6.0OracleWireProtocol AlternateServers= ApplicationUsingThreads=1 ArraySize=60000 AuthenticationMethod=1 BulkBinaryThreshold=32768 BulkCharacterThreshold=-1 ...

    Android Studio 导入第三方库中so文件的导入方法

    task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") { destinationDir file("$projectDir/libs") baseName "Native_Libs" extension "jar" from fileTree(dir: "libs", ...

    QT5 odbc驱动 libqsqlodbc.so

    接下来,为了编译和链接`libqsqlodbc.so`,你需要下载QT5的源代码,并找到ODBC相关的模块进行编译。通常,这个过程涉及到以下步骤: 1. 下载QT5源码: ```bash wget ...

    gps_description.zip

    URDF(Unreal Robot Description Format)和XACRO(eXtensible ACRObat Robot Description Format)是两种常见的ROS机器人模型描述语言。URDF是一种XML格式,用于定义机器人的几何、关节、传感器等属性。XACRO则是对...

    KPESD1CAN SOT-23 WAN.pdf

    部分内容中"DESCRIPTION"描述了该ESD保护管的用途和特点,其特点包括具备IEC61000-4-2 (接触) ±15kV (空气),±8kV的静电放电保护能力,以及IEC61000-4-4 (EFT) 40A (5/50ns) 的电气快速瞬变保护能力。其具有350瓦...

    Oracle RAC配置ST_Geometry技术文档

    1. 向 Oracle 每个节点服务器上传 libst_shapelib.so 文件,利用 oracle 用户上传到 $ORACLE_HOME/lib 路径下,并赋权限 chown oracle:oinstall libst_shapelib.so,chmod 775 libst_shapelib.so。 2. 在每个节点的...

    达梦8的Linux平台ODBC驱动包,可直接配置odbcinstance

    附件包是单独分离的libdodbc.so和依赖so库: /etc/odbcinst.ini [DM8 ODBC DRIVER] Description=ODBC DRIVER FOR DM8 Driver=/usr/lib/libdodbc.so /etc/odbc.ini [DM8] Description = DM ODBC DSN Driver = DM8 ...

    Description of ASP file upload and ScriptUtilities

    The software has also a free version of asp file upload with progress bar, called Pure asp upload, written in plain VBS, without components (so you do not need to install anything on server)....

    libjingle_peerconnection

    在Android平台上,通常会用到libjingle_peerconnection.jar(Java库)和libjingle_peerconnection.so(Native库),两者协同工作以实现WebRTC的功能。 1. **音频和视频处理**: - **音频编解码**:libjingle_...

    hadoop2.2.0 native lib 本地IO库 Linux SuSE 11 X86_64

    Description: SUSE Linux Enterprise Server 11 (x86_64) Release: 11 Codename: n/a weblogic@F23-B4-E2-B1:~> cat /etc/SuSE-release SUSE Linux Enterprise Server 11 (x86_64) VERSION = 11 PATCHLEVEL = 1

    Micron Memory Serial NOR Flash 全系列原理图库+PCB封装库(AD集成库).zip

    Name Description ---------------------------------------------------------------------------------------------------- M25P05-AVMN6P 512K (x1) Serial NOR Flash Memory, 50 MHz, 2.3 to 3.6 V, 8-pin SO8 ...

    android webrtc libjingle_peerconnection

    5. **建立连接**: 使用`createOffer`或`createAnswer`方法来生成SDP(Session Description Protocol)offer或answer,然后通过`setLocalDescription`和`setRemoteDescription`设置本地和远程的会话描述。 6. **ICE...

    psqlodbc安装

    Description=PostgreSQL driver for Linux & Win32 Driver=/usr/lib/libpsqlodbca.so Driver64= Setup= Setup64= UsageCount=1 CPTimeout= CPReuse= ``` - 保存并退出编辑器。 2. **修改odbc.ini文件**:...

    ping 的源代码 网络应用

    Description: // This sample illustrates how an ICMP ping app can be written // using the SOCK_RAW socket type and IPPROTO_ICMP protocol. // By creating a raw socket, the underlying layer does not ...

Global site tag (gtag.js) - Google Analytics