CMake An example of compiling a C + + DLL (update 1)

Source: Internet
Author: User

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  Span style= "COLOR: #800000" > " c  "  Span style= "COLOR: #000000" > {io_xxx_dll  void  hello (void  ); }

Xxx.cpp

#define"xxx.h"<iostream>   using  namespace  std;   void Hello (void) {     cout<<"Hello from dll! "<<Endl;     Cin. Get (); }

Yyy.cpp

#include <windows.h>#include<iostream>using namespacestd; intMain () {hinstance h= LoadLibrary ("c:\\users\\perelman\\. Clion2016.1\\system\\cmake\\generated\\xxx-4d5c076f\\4d5c076f\\debug\\libxxx.dll"); typedefvoid(*p) (void); P F= (p) GetProcAddress (H,"Hello");     f ();     FreeLibrary (h); return 0; }

CMake An example of compiling a C + + DLL (update 1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.