ZLMediaKit / ZLToolKit

一个基于C++11的轻量级网络框架,基于线程池技术可以实现大并发网络IO
MIT License
1.94k stars 581 forks source link

Process (calling Debug version library) exits abnormally #207

Open dyzyrax opened 8 months ago

dyzyrax commented 8 months ago

进程Debug版本退出时异常

进程Debug版本退出时异常

TRANS_BY_GITHUB_AI_ASSISTANT

xia-chu commented 8 months ago

I can't see any useful information. What is the code git hash?

看不出什么有效信息 代码git hash是多少?

TRANS_BY_GITHUB_AI_ASSISTANT

dyzyrax commented 8 months ago

ZLToolKit-master.zip The version above

ZLToolKit-master.zip 上面这个版本

TRANS_BY_GITHUB_AI_ASSISTANT

dyzyrax commented 8 months ago

Using Visual Studio 2015, ZLToolKit was compiled as a dynamic library. When calling the dynamic library, the above exception occurred.

Note: When using a static library, there is a conflict with other code in the project, resulting in a compilation error.

采用Visual studio 2015,将ZLToolKit编译为动态库,进行调用动态库时出现上图异常。 注,采用静态库时,与项目的其他代码存在冲突,编译报错

TRANS_BY_GITHUB_AI_ASSISTANT

dyzyrax commented 8 months ago

Is this exception related to my usage? My usage: I called the static library ZLToolKit in the dynamic library sampled.dll, and then the process sampled.exe called sampled.dll.

I saw that CMakeLists.txt prohibits compiling ZLToolKit as a DLL under Windows. What is the reason for this? Are there any solutions?

这个异常是否与我的使用方法有关。我的使用方法:我在动态库sampled.dll中调用了静态库ZLToolKit,然后进程sampled.exe中调用了sampled.dll 我看到CMakeLists.txt中禁止将ZLToolKit编译为WIndows下的DLL,是什么原因呢?有无解决措施?

TRANS_BY_GITHUB_AI_ASSISTANT

xia-chu commented 8 months ago

Compiling zltoolkit into a dll, it's recommended to encapsulate it with C. This is because C++'s ABI is incompatible.

From your debug information, it seems that ZLToolkit's socket was either reclaimed by the system or closed by code in the same process. It's unclear which.

把zltoolkit编译成dll 建议还是c封装下比较好 因为c++的abi是不兼容的。 从你debug信息看 是ZLToolkit的socket被系统回收了或者被同进程代码关闭了 不得而知。

TRANS_BY_GITHUB_AI_ASSISTANT

xia-chu commented 8 months ago

Compiling zltoolkit into a dll, it's recommended to encapsulate it with C. This is because C++'s ABI is incompatible.

From your debug information, it seems that ZLToolkit's socket was either reclaimed by the system or closed by code in the same process. It's unclear which.

把zltoolkit编译成dll 建议还是c封装下比较好 因为c++的abi是不兼容的。 从你debug信息看 是ZLToolkit的socket被系统回收了或者被同进程代码关闭了 不得而知。

TRANS_BY_GITHUB_AI_ASSISTANT

dyzyrax commented 8 months ago

Understood, thank you.

@.***

From: 夏楚 Date: 2024-01-28 19:42 To: ZLMediaKit/ZLToolKit Cc: dyzyrax; Author Subject: Re: [ZLMediaKit/ZLToolKit] Process (calling Debug version repository) exits abnormally (Issue #207) It is recommended to encapsulate zltoolkit into a dll with c, because the abi of c++ is incompatible. From your debug information, it seems that the socket of ZLToolkit has been recycled by the system or closed by the code in the same process. It is unknown. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

了解了,谢谢

@.***

发件人: 夏楚 发送时间: 2024-01-28 19:42 收件人: ZLMediaKit/ZLToolKit 抄送: dyzyrax; Author 主题: Re: [ZLMediaKit/ZLToolKit] 进程(调用Debug版版本库)退出时异常 (Issue #207) 把zltoolkit编译成dll 建议还是c封装下比较好 因为c++的abi是不兼容的。 从你debug信息看 是ZLToolkit的socket被系统回收了或者被同进程代码关闭了 不得而知。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

TRANS_BY_GITHUB_AI_ASSISTANT

dyzyrax commented 8 months ago

I verified that packaging it as a C dynamic library doesn't work either. The process crashes when it is destroyed. The problem is likely caused by the large number of global variables defined inside ZLToolKit.

@.***

From: @. Date: 2024-01-29 16:35 To: ZLMediaKit/ZLToolKit; ZLMediaKit/ZLToolKit Cc: @.; Author Subject: Re: Re: [ZLMediaKit/ZLToolKit] Process (calling Debug version library) exits abnormally (Issue #207) Understood, thank you.

@.***

From: Xia Chu Date: 2024-01-28 19:42 To: ZLMediaKit/ZLToolKit Cc: dyzyrax; Author Subject: Re: [ZLMediaKit/ZLToolKit] Process (calling Debug version library) exits abnormally (Issue #207) It is recommended to encapsulate zltoolkit into a dll using C, because the C++ ABI is not compatible. From your debug information, it seems that the socket of ZLToolkit was either reclaimed by the system or closed by the code in the same process. It is unclear which one it is. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

我验证了,封装为C动态库也不行,进程销毁时异常,问题原因应该是ZLToolKit内部定义的大量全局变量

@.***

发件人: @. 发送时间: 2024-01-29 16:35 收件人: ZLMediaKit/ZLToolKit; ZLMediaKit/ZLToolKit 抄送: @.; Author 主题: Re: Re: [ZLMediaKit/ZLToolKit] 进程(调用Debug版版本库)退出时异常 (Issue #207) 了解了,谢谢

@.***

发件人: 夏楚 发送时间: 2024-01-28 19:42 收件人: ZLMediaKit/ZLToolKit 抄送: dyzyrax; Author 主题: Re: [ZLMediaKit/ZLToolKit] 进程(调用Debug版版本库)退出时异常 (Issue #207) 把zltoolkit编译成dll 建议还是c封装下比较好 因为c++的abi是不兼容的。 从你debug信息看 是ZLToolkit的socket被系统回收了或者被同进程代码关闭了 不得而知。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

TRANS_BY_GITHUB_AI_ASSISTANT

dyzyrax commented 8 months ago

I tried to rename the main function in test_tcpClient.cpp and export it as a C interface. It runs normally, but there is an exception when the process is destroyed. I will share the way to reproduce the problem:

ZLToolKitDLL.zip

① Extract the attached zip file to the ZLToolKit-master directory ② Add the following content to the end of ZLToolKit-master/CMakeLists.txt, encapsulate the test_tcpClient example function as a dynamic library ZLToolKitDLL.dll interface ZLToolKitDLL_test, and call it in the test program ZLToolKitDLL_test.cpp

ZLToolKit dynamic library compilation and call

set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_library(ZLToolKitDLL SHARED ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKitDLL/ZLToolKitDLL.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKitDLL/ZLToolKitDLL.h)
if(ANDROID OR IOS OR WIN32)
    target_link_libraries(ZLToolKitDLL ${PROJECT_NAME}_static ${LINK_LIB_LIST})
else()
    target_link_libraries(ZLToolKitDLL ${PROJECT_NAME}_static ${LINK_LIB_LIST} pthread)
endif()

add_executable(ZLToolKitDLL_test ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKitDLL/ZLToolKitDLL_test.cpp )
target_link_libraries(ZLToolKitDLL_test ZLToolKitDLL)

③ Build the Visual Studio 2015 64-bit project, compile the test program ZLToolKitDLL_test, run the program, press 'esc' or 'q' to exit, and an exception will be reported during the exit process.

我尝试将test_tcpClient.cpp中的main函数改名并已C接口导出,运行正常,进程销毁时也存在异常。我分享下问题复现方式:

ZLToolKitDLL.zip ① 将附件压缩包解药至ZLToolKit-master目录 ② ZLToolKit-master/CMakeLists.txt中尾部增加以下内容,将test_tcpClient示例功能封装为动态库ZLToolKitDLL.dll的接口ZLToolKitDLL_test,并在测试程序ZLToolKitDLL_test.cpp调用

ZLToolKit动态库编译及调用

    set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
    add_library(ZLToolKitDLL SHARED ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKitDLL/ZLToolKitDLL.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKitDLL/ZLToolKitDLL.h)
    if(ANDROID OR IOS OR WIN32)
        target_link_libraries(ZLToolKitDLL ${PROJECT_NAME}_static ${LINK_LIB_LIST})
    else()
        target_link_libraries(ZLToolKitDLL ${PROJECT_NAME}_static ${LINK_LIB_LIST} pthread)
    endif()

    add_executable(ZLToolKitDLL_test ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKitDLL/ZLToolKitDLL_test.cpp )
    target_link_libraries(ZLToolKitDLL_test ZLToolKitDLL)

③ 构建Visual Studio 2015 64位工程,编译测试程序ZLToolKitDLL_test,程序运行后,按‘esc’或'q'键退出,退出过程中就会报异常

TRANS_BY_GITHUB_AI_ASSISTANT