zoukankan      html  css  js  c++  java
  • vs2015开发so动态库linux

    #include <stdio.h>
    #include <dlfcn.h>
    
    typedef int(*fn_max)(int a, int b);
    
    int main()
    {
        printf("entery in main
    ");
    
        void* hdl = dlopen("liblinuxdlltest.so.1.0", RTLD_NOW);//RTLD_LAZY
        if (!hdl)
        {
            printf("load dll fail
    ");
            return;
        }
    
        fn_max max = (fn_max)dlsym(hdl, "max");
        char* perr = dlerror();
        if (perr)
        {
            printf("load symbol failed: %s
    ", perr);
            return;
        }
    
        int result = max(200, 123);
    
        printf("the max is %d
    ", result);
    
        dlclose(hdl);
    
    
        printf("exit main
    ");
    
        return 0;
    }

    dllmain.h

    #pragma once
    
    
    
    int max(int a, int b);

    dllmain.c

    #include <stdio.h>
    
    //int main()
    //{
    //    printf("hello from ConsoleApplication7!
    ");
    //
    //    printf("this is my so dll test project");
    //    return 0;
    //}
    
    /************************************************************************/
    /* 构造函数                                                             */
    /************************************************************************/
    void __attribute__((constructor)) x_init(void)
    {
        printf("----so lib is loaded
    ");
    }
    
    /************************************************************************/
    /* 析构函数                                                             */
    /************************************************************************/
    void __attribute__((destructor))  x_fini(void)
    {
        printf("----so lib is unload
    ");
    }
    
    int max(int a, int b)
    {
        printf("enter in max
      .. 
    ");
        return a > b ? a : b;
    }

    工程源码下载: http://download.csdn.net/download/jiftlixu/10236153

    导出符号控制:

    https://www.cnblogs.com/lidabo/p/5703890.html

  • 相关阅读:
    c语言数组的赋值问题
    英语------------单词被动形式的读音规律
    英语------------单词复数形式的规律
    一天半时间大致的学习了HTML和CSS.
    没有权威,只有努力
    java 对象赋值问题
    Java-Math
    StringBuffer
    java--String方法
    某个日期的下一天
  • 原文地址:https://www.cnblogs.com/jiftle/p/8401887.html
Copyright © 2011-2022 走看看