1

I'm pretty new to C++ and I'm having a hard time trying to install external libraries. I want to get started with GUI programming and I have searched all over, but I cannot find a way to add wxWidgets to Code::Blocks. I've tried a few different guides and Stack Overflow responses but none of them have actually worked.

I'm using this 'Hello World!' test program to see if it works, every time I try to run it I just get this error: fatal error: wx/wxprec.h: No such file or directory. I can't seem to figure out how to tell Code::Blocks where the library is.

The most recent resource I have tried is this one, I followed it step by step, but still I got this error.

What linker/compiler settings do I need to use in Code::Blocks? What lib files do I need to add and where do I add them to? Do I need to build the .zip file? How do I do this?

Please could I get a step by step guide on exactly how to add wxWidgets (or indeed any external library) to Code::Blocks as well as some information on why certain things are required?

Here's what I tried

Following the steps in the link above, this is what I have in my build options:

enter image description here

I tried adding this in my global compiler settings...

enter image description here

I still have this error...

enter image description here

user9888447
  • 127
  • 1
  • 9

1 Answers1

2

CodeBlocks seems to have some special wxWidgets integration, but it didn't always work for me, so I prefer to set up the project manually.

CB ships an outdated compiler. While it may work, updating it is a good idea.

Get rid of the MinGW version shipped with CB, or at least remove it from the PATH.

Install MSYS2. Use it to install a new GCC and GDB, as described in the link.

Configure CB to use MSYS2's GCC and GDB, by specifying the paths to them in the CB config (they're installed to C:\msys64\mingw64\bin).

wxWidgets seem to ship prebuilt libraries for MinGW, but since we're using MSYS2, we might as well use the version provided by MSYS2.

Use MSYS2 to install wxWidgets: pacman -S mingw-w64-x86_64-wxWidgets3.2-msw.

MSYS2 seems to ship several different versions of wxWidgets: 3.0, 3.1, 3.2, and each of them in two variants: -msw and -gtk. 3.2-msw looks like a reasonable choice to me, but I haven't used this library before.

wxWidgets doesn't seem to use the standard way of telling you what compiler flags to use (which would be pkg-config, or at least a CMake file). Instead they ship their own script to determine the flags, called wx-config.

Run wx-config --cflags to get the compiler flags, and run wx-config --libs to get the linker flags. Paste them into the project settings (compiler settings and linker settings respectively). Edit the project settings, not the global compiler settings.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • As Code::Blocks is poorly maintained, what is a good IDE to use as an alternative? – user9888447 Nov 10 '22 at 20:48
  • @user9888447 VSCode, with Clangd extension instead of the stock Microsoft one. It doesn't have visual editor for wxWidgets forms though (perhaps there are plugins for that? or find a separate tool, if you need it). – HolyBlackCat Nov 10 '22 at 22:38
  • @user9888447, you can use a free version of MSVC. Or continue using CodeBlocks. This IDE is really good for working with wxWidgets. It is maintained and gets updated frequently and is patched whenever patches are submitted to the library. – Igor Nov 11 '22 at 05:48
  • I also suggest to use PB guide to use CodeBlocks - you can find a link to it on the wx forum. And I believe that's what New Pagodi is linking you to. – Igor Nov 11 '22 at 05:50
  • I would also never use VSCode for anything more than code editing as it's not an IDE, but just an editor. But than - why use it at all, when you can use full-blown IDE? – Igor Nov 11 '22 at 05:52
  • @Igor Last time I checked CB, the glaring issue was a poor code completion, which broke down on some C++ features (Clangd and MS IntelliSense are miles ahead), and some visual debugger features not working. The problem with VSC is the configuration complexity, and the lack of visual gui editor, if you want that. Otherwise you can make a full-featured IDE out of it. The problem with VS is it not being cross-platform, and not working well with MinGW. – HolyBlackCat Nov 11 '22 at 12:06
  • @HolyBlackCat, did you talk to C::B devs about your issues? I know they have their own forum. Yes - MSVC is not cross-platform but will generate very optimal native code. And why do you need it to support MinGW? It has its own compiler... – Igor Nov 11 '22 at 13:35
  • And about VSCode - MS producing windows products. They are miles from cross-platform stuff. And wxWidhets with this IDE is really hard to set up. – Igor Nov 11 '22 at 13:38
  • @Igor I get the impression that you're defending your IDE of choice, without having used VSC much. *"miles from cross-platform stuff"* Did you have any issues with it? I didn't. *"wxWidhets with this IDE is really hard to set up"* Huh? The process doesn't depend on the IDE, you'd just paste the right compiler flags, similar to what OP did. *"why ... MinGW"* To have the single compiler on all platforms. Also MSVC has its issues (not enforcing strict standard compliance in some places, errors in templates not being informative enough, etc). – HolyBlackCat Nov 11 '22 at 19:22
  • @HolyBlackCat, I'm not. I'm basing this on the number of complaints in the wx forum. But that aside - MSVC does have project/solution to start from in the wxWidgets so it is much simpler. – Igor Nov 11 '22 at 19:44
  • Hi, code::blocks developer here. Code::Blocks now has better code completion by using the clangd client plugin. You can try those features by using the latest nightly build release. – ollydbg23 Nov 29 '22 at 14:33
  • @ollydbg23 Good to hear it's a thing now. Since this was my main complaint, I'll get rid of the "poorly maintained" part. – HolyBlackCat Nov 29 '22 at 17:08
  • I'm using another way to configure the wxWidgets libraries under Windows and Code::Blocks, see this page: [asmwarrior/cb_projects_for_wxWidgets: Code::Blocks projects for building wxWidgets sample code](https://github.com/asmwarrior/cb_projects_for_wxWidgets). I have all the Code::Blocks cbp files for the wx samples, what I use is a `global compiler variable` named `wx-config`, which could point to either `wx-config-msys2.exe` if you use msys2 prebuild wx library(installed by `pacman` command), or `wx-config.exe` is you used self build wx libraries. – ollydbg23 Nov 30 '22 at 00:54