Mingw compiles DLL and static links pthread

Source: Internet
Author: User

I recently used mingw to compile a DLL and encountered several minor problems. record it.

1. The problem of dllmain not being executed

After the DLL is written, the function test is OK, but the dllmain is not executed, causing the initialization and analysis in the code to fail to be executed. Check the generated DLL, it is found that due to C ++ compilation, dllmain is renamed, and the solution is added with extern "C"

2. Static link pthreadgc2

When testing with the test program, the prompt does not find pthreadgc2.dll, so in the mingw Directory Search pthread, found a pthreads-win32-README document, which details how to static link pthread, the procedure is as follows:

Define the ptw32_static_lib Macro during compilation

Link pthreadGC2-static and ws2_32 Library (do not need to link pthread)

Call pthread_win32_process_attach_np () to initialize pthread_win32_process_attach_np () before calling any pthread function. Call pthread_win32_process_detach_np () (DLL under dll_process_detach)

3. If multiple threads are used in the EXE, repeat Step 2.

 

 

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.