MinGW unable to find pkg-config

Recently I need build libewf on Windows, and MinGW is chosen as the compilation tool.

Open MSYS and run autogen.sh in libewf source directory, then following error is appeared

unable to find: pkg-config


I read source code of autogen.sh and realized that it’s trying to locate pkg-config at /mingw/bin directory,  Then I checked MinGW installation directory and bin folder, found there is no such pkg-config file. So we need install pkg-config manually.


Install pkg-config

At MinGW Wiki page it introduces two methods to install pkg-config, but using a pre-compiled version is much easier. Here is pre-compiled pkg-config download address from SourceForge. After downloading is completed, extract pkg-config.exe and move it to MinGW/bin directory, retry running autogen.sh we will found this problem is solved

WPF Set StartupUri in code


StartupUri is a property of Application class, which sets the first UI to show when application starts. By default it’s set in App.xaml file, e.g.

In above code the StartupUri value is MainWindow.xaml, and using default value is OK for most of times.


Why Set StartupUri in Code?

But what if you want to show other windows according to different conditions? Assume our application can open .proj files, so the file name will be passed in as command line arguments.  Now we want to show a file chooser dialog at startup if user run our application directly (without double clicking .proj files), and open another window (call it Project Explorer) when user start application by double clicking .proj file.

In this case we need to check command line arguments, then set corresponding StartupUri in code.


How to Do it

First in App.xaml.cs, add an override method OnStartup for Application class.

This method will be called at startup of application.

Setting StartupUri in OnStartup method is just a recommended way, you can set it in constructor as well. The execution order is: Constructor -> XAML Parsing -> OnStartup, so setting StartupUri in constructor will be overridden by XAML and OnStartup, and StartupUri in XAML will be overriden by OnStartup


Next we set the StartupUri according to whether filename is passed in.

In above code we call System.Environment.GetCommandLineArgs method to get command line arguments. You can see the StartupUri is actually an Uri object, its UriKind is UriKind.Relative. (If we don’t specify the UriKind parameter, we will get an UriFormatException)