Windows 上的 CodeLite 和 wxWidgets:构建成功完成,但程序崩溃

CodeLite and wxWidgets on Windows: build completes successfully but program crashes

提问人:alle_meije 提问时间:10/13/2023 最后编辑:alle_meije 更新时间:10/20/2023 访问量:147

问:

在 Windows 7 虚拟机上,我使用以下命令设置了一个 C++ 构建环境:

  1. C:\usr\local\gcc-13.2.0(来自 Winlibs);
  2. C:\usr\local\cmake-3.27.6(来自 KitWare);
  3. C:\usr\local\wxWidgets-3.2.2.1(来源,来自 wxwidgets.org);
  4. C:\usr\local\codelite-17.6.0(摘自 codelite.org), 在目录中构建了 wxWidgets(目录已经存在,似乎是正确的位置),使用上面的 和 可执行文件并从编译器目录中使用。C:\usr\local\wxWidgets-3.2.2.1\buildCMakegccmingw32-make

二进制文件位于 wxWidgets 目录下,所有共享库的名称都以 .lib\gcc_x64_dll_gcc_custom.dll

然后,要在 CodeLite 中构建 wxWidgets 的“Hello World”示例:

  1. 将“设置”-“编译器设置”更改为刚刚安装的gcc
  2. 将“设置”-“GDB 设置”更改为在同一目录中gdb
  3. 添加和到“设置”->“环境变量”WXWIN=C:\usr\local\wxWidgets-3.2.2.1WXCFG=gcc_x64_dll\mswu
  4. 打开一个新项目“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

  1. libgcc_s_seh-1.dll,
  2. libstdc++-6.dll(两者都在CFF Explorer中,但未被CFF Explorer找到);C:\usr\local\gcc-13.2.0\bin
  3. KERNEL32.dll,
  4. ucrtbase.dll(两者都位于C:\Windows\system32);
  5. wxbase32u_gcc_custom.dll,
  6. wxmsw32u_core_gcc_custom.dll,
  7. 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++-6libstdc++-6.dll.alib.a.so

编译成功完成,程序崩溃。从 IDE 和 shell。IDE(调试器)给出“退出代码”消息,外壳显示:“程序无法启动,因为计算机中缺少 libgcc_s_seh-1.dll。

有谁知道在链接我的程序和独立运行程序期间能够使用这些 DLL 需要什么?

编辑二

将两个目录(g++ 的 DLL)和(wxWidgets 的 DLL)放入路径并重新启动后:C:\usr\local\gcc-13.2.0\binC:\usr\local\wxWidgets-3.2.2.1\lib\gcc_x64_dll

  1. 从 IDE 首次运行既没有产生错误,也没有产生窗口
  2. 从外壳的第一次运行产生了一个窗口(!
  3. 之后,IDE的所有运行也都会生成一个窗口

所以这似乎终于成功了!(虽然不太确定在“1”发生了什么。

将进行更多测试,然后生成一个漂亮的项目符号列表。

C++ CMake mingw wxwidgets codelite

评论

1赞 Tsyvarev 10/13/2023
该错误是关于没有找到您的程序所需的一些 dll。例如,请参阅有关解析程序的所有dll的问题0xc0000135
0赞 alle_meije 10/14/2023
有趣的谢谢!会尝试。我曾预料到缺少DLL会导致IDE中出现“未定义的引用”消息?
1赞 Tsyvarev 10/14/2023
当链接器找不到符号(函数)的定义时,会在链接时发出错误。当加载程序找不到某些 dll 时,会在运行时发出错误代码。undefined reference0xc0000135
0赞 alle_meije 10/16/2023
好的,谢谢!现在,如果我使用CFF Explorer打开.exe文件,我会得到一个包含7个DLL的列表,我已经在帖子中添加了这些DLL。不过,我真的不确定我应该在我的项目中更改什么才能成功构建和运行它!还是需要全局设置 DLL 路径?build-Debug
1赞 Igor 10/17/2023
@alle_meije,我完全理解。事实上的标准是在 Windows 上静态构建,除非您自己创建 DLL。然后建议动态构建。

答:

0赞 alle_meije 10/19/2023 #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:

  1. Download G++, CMake and CodeLite binaries and wxWidgets sources;
  2. Build wxWidgets with GCC and CMake (with wxBUILD_SHARED ticked);
  3. Set the compiler in CodeLite to the new GCC and set and to the wxWidgets source directory and the lib//mswu directory, respectively;WXWINWXCFG
  4. 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;PathbinWXCFG
  5. 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.

评论

0赞 Igor 10/23/2023
keep in mind that wxWidgets have the Makefile to build it with gcc. CMake build make sense when it is part of the bigger project which is huge.
0赞 Igor 10/23/2023
But for testing all you do is . And then when you are ready to distribute - you try CMake.cd wxWidgets\build\msw && mingw32-make -f makefile.gcc BUILD=Debug SHARED =0
0赞 alle_meije 10/25/2023
Yes sorry, this recipe is for the very stubborn who think it's silly not to use shared libraries :)