Page 1 of 1

Compilation problem: build.cfg file is missing

Posted: Mon Jan 20, 2020 7:57 pm
by Prime
Hi all.
I had compiled wxWidgets 3.1.3 on Windows 10 by Visual Studio Community 2019 (16.4.3) from the developer command prompt using the following commands:

Code: Select all

cmake C:\home\sources\wxWidgets3.1.3 -DCMAKE_INSTALL_PREFIX="C:\wxWidgets" -DwxBUILD_DEBUG_LEVEL=0 -DwxUSE_EXCEPTIONS=ON -DwxBUILD_STRIPPED_RELEASE=ON -DwxBUILD_MSVC_MULTIPROC=ON -DwxBUILD_SHARED=OFF -DwxBUILD_MONOLITHIC=ON
cmake --build . --target install --config Release -j 4
After that, I tried to use wx-config-win utility:

Code: Select all

wx-config-win --prefix="C:\wxWidgets" --wxcfg="vc_x64_lib\mswu" --cxxflags
...But got an error:
wx-config Error: No valid configuration of wxWidgets has been found at location: C:\wxWidgets\lib\vc_x64_lib\mswu\build.cfg

Please use the --wxcfg flag (as in wx-config --wxcfg=gcc_dll\mswud) or set the environment variable WXCFG (as in WXCFG=gcc_dll\mswud) to specify which configuration exactly you want to use.
File build.cfg really does not exist anywhere on my machine. As a result, wx-config-win seams to be completely unusable, but I have no idea how to link wxWidgets to my applications without this utility (or have I to type all wx and system libs manually?). The whole situation looks very strange: build.cfg is an important part of wxWidgets installation, but it is not generated by the build system.
Any thoughts about this problem, people?

Re: Compilation problem: build.cfg file is missing

Posted: Tue Jan 21, 2020 3:42 pm
by ONEEYEMAN
Hi,
Did you try to build the sample or your own program?
I believe the "wx-config-win" should be used for MinGW compiler.
For the MSVC you just need to use exactly the same command you used to build the library.

And if you look at the latest release - there is a file for MSVC in order to create the proper solution for you own program.

Thank you.

Re: Compilation problem: build.cfg file is missing

Posted: Tue Jan 21, 2020 8:13 pm
by PB
As ONEEYEMAN already wrote, I am not sure you are supposed to mix MSVC and some "wx-config-win" utility which I believe is neither a part of wxWidgets nor is it intended for use with MSVC.

I have just tested building a recentish master with MSVC 2019 and found that using:
* CMake does NOT produce build.cfg,
* wx_vc16.sln does NOT produce build.cfg,
* nmake DOES produce build.cfg (in the build-specific lib folder, such as WXWIN\lib\vc_lib\mswu).

Additionally, I could not find any mention of "build.cfg" in the official documentation.

I advise to ask if "build.cfg" is even supposed to be always generated by wxWidgets build process in the mailing group:
https://groups.google.com/forum/#!forum/wx-users

More importantly, if you are using MSVC, all necessary libraries get linked automatically, as long as you include the MSVC-specific header file. i.e., add $(WXWIN)\include\msvc before $(WXWIN)\include in the compiler include paths and tell the linker where to find the libraries, see here
https://docs.wxwidgets.org/trunk/plat_m ... build_apps

If you for some odd reason built the library as monolithic, you need to define wxMONOLITHIC=1 in your MSVC project / preprocessor defines (otherwise the default multilib build is assumed, which has different library names).

BTW, here is my quick tutorial to setting-up wxWidgets project in MSVS IDE. The tutorial assumes the libraries reside in the wxWidgets source tree (as when built with provide a NMake makefile or MSVS solution), you may need to change your linker and resource folders to the actual folder where you built the library files.

Re: Compilation problem: build.cfg file is missing

Posted: Wed Jan 22, 2020 10:44 pm
by stahta01
ONEEYEMAN wrote: Tue Jan 21, 2020 3:42 pm Hi,
Did you try to build the sample or your own program?
I believe the "wx-config-win" should be used for MinGW compiler.
For the MSVC you just need to use exactly the same command you used to build the library.

And if you look at the latest release - there is a file for MSVC in order to create the proper solution for you own program.

Thank you.
If you build wxWidgets using nmake then wx-config-win will likely work.

Tim S.

Re: Compilation problem: build.cfg file is missing

Posted: Wed Jan 22, 2020 11:00 pm
by ONEEYEMAN
Tim,
stahta01 wrote: Wed Jan 22, 2020 10:44 pm
ONEEYEMAN wrote: Tue Jan 21, 2020 3:42 pm Hi,
Did you try to build the sample or your own program?
I believe the "wx-config-win" should be used for MinGW compiler.
For the MSVC you just need to use exactly the same command you used to build the library.

And if you look at the latest release - there is a file for MSVC in order to create the proper solution for you own program.

Thank you.
If you build wxWidgets using nmake then wx-config-win will likely work.

Tim S.
It may, but it is not officially supported.

Thank you.

Re: Compilation problem: build.cfg file is missing

Posted: Sat Jan 25, 2020 3:52 pm
by Prime
Hi again.
Thanks to your answers, I realized that wx-config-win cannot help me, so it's necessary to find another way of building wxWidgets-based applications. I have read the tutorial provided by PB, but that tutorial covers only manipulations inside IDE, which I am not used to. My favourite tool is the command line, not grafical interface. For this reason, I Tried to build a simple "Hello world" program with CMake (note that before doing the following steps, I rebuilt my wxWidgets in non-monolithic mode cause there is no principal need in single library file).

Program code (file hello.cpp):

Code: Select all

#include <wx/wx.h>
class MyApp : public wxApp
{
public:
    virtual bool OnInit()
{
wxMessageDialog(nullptr, wxString(L"Hello, world!"), wxString(L"Message"));
return true;
}
};
wxIMPLEMENT_APP(MyApp);
CMakeLists.txt contents:

Code: Select all

cmake_minimum_required(VERSION 3.15)
project(wxtest VERSION 0.0.1 LANGUAGES CXX)
add_executable(test hello.cpp)
find_package(wxWidgets REQUIRED)
target_include_directories(test PUBLIC ${wxWidgets_INCLUDE_DIRS})
target_link_libraries(test ${wxWidgets_LIBRARIES})
Build commands:

Code: Select all

cmake C:\home\projects\wxtest && cmake --build . --config Release
The output contains several messages about linker errors. Unfortunately, I cannot place them here, because the forum calls my post spam and forbids it due to "contacts" in its text. Don't remember exactly, but that linker errors was about unresolved external symbols with complicated assert-related names. Additionally there was one symbol from MSVCRT library with simple name main.
Maybe I did something wrong?

Re: Compilation problem: build.cfg file is missing

Posted: Sat Jan 25, 2020 4:56 pm
by PB
I think your CMake misses the necessary defines, I mention some of those in my tutorial linked above. You will also need other ones, as you customized the wxWidgets build (monolithic, custom BUILD_DEBUG_LEVEL which is probably the culprit for those assert-related build errors...) and need the matching defines for the project.

I do not really use CMake, but perhaps something like
add_definition / target_compile_definitions

Your project also misses the line used in the docs

Code: Select all

include(${wxWidgets_USE_FILE})
I would advise starting simple, i.e. build wxWidgets with the default settings and only once you get everything working, start experimenting.

If you are unable to embed the build errors into your post, attach the build log to it.

Re: Compilation problem: build.cfg file is missing

Posted: Mon Jan 27, 2020 10:36 am
by Prime
Hi.
I have added the suggested command to my CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.15)
project(wxtest VERSION 0.0.1 LANGUAGES CXX)
add_executable(test hello.cpp)
find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
target_include_directories(test PUBLIC ${wxWidgets_INCLUDE_DIRS})
target_link_libraries(test ${wxWidgets_LIBRARIES})
But nothing was changed in the build output. Then I compiled wxWidgets without DEBUG_LEVEL option (again in non-monolithic mode), and so successfully got rid of all assert-related errors. Unfortunately, the last linker error still remains, I attached it to this post.

Re: Compilation problem: build.cfg file is missing

Posted: Mon Jan 27, 2020 11:32 am
by PB
I know very little about CMake, but are you sure your project settings match wxWidgets one (Debug/Release, Unicode...)?

When I needed to test my simple project with CMake, I used this. I am not saying it is an example worth following, but I know it builds and does not have this line

Code: Select all

target_include_directories(test PUBLIC ${wxWidgets_INCLUDE_DIRS})

Re: Compilation problem: build.cfg file is missing

Posted: Fri Jan 31, 2020 9:59 am
by Prime
I finally managed to compile this "Hello world" with CMake. All what I needed was /subsystem:windows linker option. But wait, the resulting executable is about 3.5 mb! Simple message box with tiny text and one button requires 3.5 mb of memory? Looks like the program is 90% dead code. I tried to use options like /Gy (both for the library and the for executable) - size of the latter has not been changed. Maybe the culpret is static runtime (msvcrt.lib and so on), which is not splitted into COMDATs? Well, but I don't have any idea how to make the linker to use DLL runtime libs instead of static ones. Also I doubt if all necessary DLLs will be present on end-users' machines. Are they shipped with Windows by default, or some of them come only from SDK?

Re: Compilation problem: build.cfg file is missing

Posted: Fri Jan 31, 2020 11:46 am
by PB
Judging from your reaction: are you by any chance new to GUI libraries? While the size of the executable (which basically has nothing to do with RAM consumption of the given executable) in relation to what your program does may surprise you and may appear baffling compared to the same result achieved using Win32 API, 3.5 MBytes is virtually nothing in 2020 and I doubt you will achieve anything significantly smaller with comparable libraries such as Qt or MFC. The executable size also does not increase proportionally with source code size, i.e., if the source code for your application would increase 100 times, the executable size (RAM consumption is mostly defined by dynamic allocations for data) certainly will not.

I do not know much about linking optimization, but I doubt it is done per member methods. E.g., if the class A refers to class B, all the class B code must be linked in even if it is not ever used, and so on and so on... You can still try to minimize the size of the executable: From my (very old) experience the most useful seemed to be disabling the 3rd party libraries when building wxWidgets, particularly those for image formats (libpng, libjpeg, libtiff) which get linked in due to wxImage but these days, I would say no one cares to do that. The simple code you posted uses only wxCore and wxBase, if you start using advanced complex class, the linker will also link the other needed libraries.

You also must be doing something odd with CMake, I do not remember ever having to set the linker's subsystem manually, it always defaulted to windows and not console. Anyway, by default the CRT library is linked dynamically and you are responsible for shipping the CRT DLLs together with your application, but this has nothing to do with wxWidgets, it applies to every program.

BTW, your example code you posted here actually does not display anything: you are constructing an instance of wxMessageDialog but not showing it. Instead of your

Code: Select all

wxMessageDialog(nullptr, wxString(L"Hello, world!"), wxString(L"Message"));
you need to do either

Code: Select all

wxMessageDialog dlg(nullptr, "Hello, world!", "Message");
dlg.ShowModal();
or

Code: Select all

wxMessageBox("Hello, world!", "Message");
You also need to return false from OnInit() so the application exits once the modal dialog is closed. If you return true, application still runs but with no visible window so it is basically a zombie.

Re: Compilation problem: build.cfg file is missing

Posted: Fri Jan 31, 2020 3:20 pm
by Prime
Yes, my initial code was logically wrong. I had added a call to ShowModal method later, but forgot to update the posted example. And thank you for the tip about return value, my program really was a zombie and I didn't know how to fix its behaviour.
I am very sorry to hear that no one cares about dead code in binaries. Although 3.5 mb actually should not be a problem, but, from my point of view, this overhead is too much inefficiant. Anyway, I have to accept reality as it is. You are right, I am new to GUI programming.

Re: Compilation problem: build.cfg file is missing

Posted: Fri Jan 31, 2020 3:32 pm
by ONEEYEMAN
Hi,
We are not talking about the dead code here.
If class A is dependent on class B (say it has a member of the type B), then the fial product will link in the class B.
You may not use that member. In fact you may not even know it exist.

But the linker sees it and when you link you program will pull both classes - A and B into the final binary.

How can it not? It is a dependency.

So there is no dead code.

Thank you.