提问人:alle_meije 提问时间:10/13/2023 最后编辑:alle_meije 更新时间:10/20/2023 访问量:147
Windows 上的 CodeLite 和 wxWidgets:构建成功完成,但程序崩溃
CodeLite and wxWidgets on Windows: build completes successfully but program crashes
问:
在 Windows 7 虚拟机上,我使用以下命令设置了一个 C++ 构建环境:
C:\usr\local\gcc-13.2.0
(来自 Winlibs);C:\usr\local\cmake-3.27.6
(来自 KitWare);C:\usr\local\wxWidgets-3.2.2.1
(来源,来自 wxwidgets.org);C:\usr\local\codelite-17.6.0
(摘自 codelite.org), 在目录中构建了 wxWidgets(目录已经存在,似乎是正确的位置),使用上面的 和 可执行文件并从编译器目录中使用。C:\usr\local\wxWidgets-3.2.2.1\build
CMake
gcc
mingw32-make
二进制文件位于 wxWidgets 目录下,所有共享库的名称都以 .lib\gcc_x64_dll
_gcc_custom.dll
然后,要在 CodeLite 中构建 wxWidgets 的“Hello World”示例:
- 将“设置”-“编译器设置”更改为刚刚安装的
gcc
- 将“设置”-“GDB 设置”更改为在同一目录中
gdb
- 添加和到“设置”->“环境变量”
WXWIN=C:\usr\local\wxWidgets-3.2.2.1
WXCFG=gcc_x64_dll\mswu
- 打开一个新项目“hello_wxwidget”,类别“GUI”,键入“wxWidgets GUI应用程序”,编译器和调试器如上,构建系统“CodeLite Makefile Generator”。这将生成标准代码来制作一个简单的 wxFrame。
程序构建成功!但是,当我运行它时,CodeLite 中的输出只是“程序退出”(没有错误消息),并且没有出现任何窗口。
当我通过调试器运行它时,它说“.Debugger exited with the following error string: "During startup program exited with code 0xc0000135
如果没有其他错误和警告,也没有可用的调用堆栈,是否有可能找出这里不起作用的内容?
编辑
按照@Tsyvarev的建议,我在程序Explorer Suite中打开了该文件,其中显示了其依赖项:.exe
libgcc_s_seh-1.dll
,libstdc++-6.dll
(两者都在CFF Explorer中,但未被CFF Explorer找到);C:\usr\local\gcc-13.2.0\bin
KERNEL32.dll
,ucrtbase.dll
(两者都位于C:\Windows\system32
);wxbase32u_gcc_custom.dll
,wxmsw32u_core_gcc_custom.dll
,wxmsw32u_xrc_gcc_custom.dll
(所有三个都在CFF Explorer中,但未被CFF Explorer找到)C:\usr\local\wxWidgets-3.2.2.1\libgcc_x64_dll
在我的“设置”>“全局设置”中,我现在已经添加到“库路径”和“链接器选项”中。为了使最后一个选项起作用,我还需要在编译器的目录中重命名,否则会与 .C:\usr\local\wxWidgets-3.2.2.1\lib\gcc_x64_dll; C:\usr\local\gcc-13.2.0\bin;
-lwxbase32u_gcc_custom; -lwxmsw32u_core_gcc_custom; -lwxmsw32u_xrc_gcc_custom; -llibgcc_s_seh-1; -llibstdc++-6
libstdc++-6.dll.a
lib
.a
.so
编译成功完成,程序崩溃。从 IDE 和 shell。IDE(调试器)给出“退出代码”消息,外壳显示:“程序无法启动,因为计算机中缺少 libgcc_s_seh-1.dll。
有谁知道在链接我的程序和独立运行程序期间能够使用这些 DLL 需要什么?
编辑二
将两个目录(g++ 的 DLL)和(wxWidgets 的 DLL)放入路径并重新启动后:C:\usr\local\gcc-13.2.0\bin
C:\usr\local\wxWidgets-3.2.2.1\lib\gcc_x64_dll
- 从 IDE 首次运行既没有产生错误,也没有产生窗口
- 从外壳的第一次运行产生了一个窗口(!
- 之后,IDE的所有运行也都会生成一个窗口
所以这似乎终于成功了!(虽然不太确定在“1”发生了什么。
将进行更多测试,然后生成一个漂亮的项目符号列表。
答:
In the end the comments by @Tsyvarev and @Igor helped me find the answer. The issue with building wxWidgets as shared libraries, which is normal in Linux but not in Windows, is that these libraries need to be in the system's (or the user's) environment variable. They could also be copied into every executable's directory, but that would defy the purpose of shared libraries!Path
So my recipe for building GUIs with wxWidgets in CodeLite in Windows is:
- Download G++, CMake and CodeLite binaries and wxWidgets sources;
- Build wxWidgets with GCC and CMake (with wxBUILD_SHARED ticked);
- Set the compiler in CodeLite to the new GCC and set and to the wxWidgets source directory and the lib//mswu directory, respectively;
WXWIN
WXCFG
- Set the System environment variable so that it includes both the directory of the GCC compiler and the full path of the directory's parent;
Path
bin
WXCFG
- Select a project type in CodeLite that is wxWidgets-aware: it will put the right compiler, linker and resources options in.
In the end, no extra linker options are necessary for building, but if you want to use shared libraries as they were intended, they need to be reachable via the environment variable (there is no equivalent)Path
$LD_LIBRARY_PATH
I copied the result of steps 1-2 to another Windows 7 virtual machine and steps 3-5 were enough to get a wxFrame working.
评论
cd wxWidgets\build\msw && mingw32-make -f makefile.gcc BUILD=Debug SHARED =0
评论
0xc0000135
undefined reference
0xc0000135
build-Debug