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.