zoukankan      html  css  js  c++  java
  • cmake 编译 c++ dll 的一个例子

    CMakeLists.txt

    project(xxx)
    add_library(xxx SHARED xxx.cpp)
    add_executable(yyy yyy.cpp)
    target_link_libraries(yyy xxx)

    xxx.h

    #ifndef XXX_XXX_H
    #define XXX_XXX_H
    #endif
    
    #pragma once
    #ifdef BUILD_XXX_DLL
    #define IO_XXX_DLL __declspec(export)
    #else
    #define IO_XXX_DLL __declspec(import)
    #endif
    
    extern "C"
    {
    IO_XXX_DLL void hello(void);
    }

    xxx.cpp

    #define BUILD_XXX_DLL
    #include "xxx.h"
    #include <iostream>
    
    IO_XXX_DLL void hello(void)
    {
        std::cout<<"Hello from dll!"<<std::endl;
        std::cin.get();
    }

    yyy.cpp

    #include <windows.h>
    #include "xxx.h"
    int main()
    {
        HINSTANCE handle = LoadLibrary("C:\Users\Perelman\.CLion2016.1\system\cmake\generated\xxx-4d5c076f\4d5c076f\Debug\libxxx.dll");
        typedef void (*pointer)(void);
        pointer f;
        f = (pointer)GetProcAddress(handle, "hello");
        f();
        FreeLibrary(handle);
        return 0;
    }

    360截图20160611000228834 360截图20160611000335691

  • 相关阅读:
    js的包装对象
    js-原型
    js面向对象初识
    css3-3d
    用css制作三角形
    清浮动
    IE67下浮动元素margin-bottom值失效问题
    css圆角
    Use Memory Layout from Target Dialog Scatter File
    Qt QSting
  • 原文地址:https://www.cnblogs.com/blog-3123958139/p/5574514.html
Copyright © 2011-2022 走看看