News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

CodeBlocks Msys2 and wxWidgets

Started by tumanovalex, March 01, 2020, 06:48:10 PM

Previous topic - Next topic

tumanovalex

CodeBlocks Msys2 and wxWidgets
Windows 10 Home 64 bit. Installed CodeBlocks from codeblocks-17.12-nosetup.zip by simply copying it to drive C. Using Msys2 I downloaded the necessary tools (pacman -S --needed mingw-w64-x86_64-toolchain), specified the necessary directory in CodeBlocks (C: \ msys64 \ mingw64 \ bin \) and the necessary tools. The console application was created normally, everything works. I decided to try to make a wxWidgets project. I decided to try to make a wxWidgets project. Installed wxWidgets (pacman -S mingw-w64-x86_64-wxWidgets). Specified in the project properties a directory for searching wxWidgets files. When I try to debug, I get messages:
C: / msys64 / mingw64 / bin /../ lib / gcc / x86_64-w64-mingw32 / 9.2.0 /../../../../ x86_64-w64-mingw32 / bin / ld.exe: cannot find -lwxmsw30ud
C: / msys64 / mingw64 / bin /../ lib / gcc / x86_64-w64-mingw32 / 9.2.0 /../../../../ x86_64-w64-mingw32 / bin / ld.exe: cannot find -lwxpngd
C: / msys64 / mingw64 / bin /../ lib / gcc / x86_64-w64-mingw32 / 9.2.0 /../../../../ x86_64-w64-mingw32 / bin / ld.exe: cannot find -lwxjpegd
C: / msys64 / mingw64 / bin /../ lib / gcc / x86_64-w64-mingw32 / 9.2.0 /../../../../ x86_64-w64-mingw32 / bin / ld.exe: cannot find -lwxtiffd
C: / msys64 / mingw64 / bin /../ lib / gcc / x86_64-w64-mingw32 / 9.2.0 /../../../../ x86_64-w64-mingw32 / bin / ld.exe: cannot find -lwxzlibd
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute (s), 42 second (s))
Please tell me how to properly configure the project. The project has attached.

stahta01

#1
Custom variable and value

WX_SUFFIX=u
WX_TOOLKIT=msw
WX_VERSION=3.0


Compiler search directories

$(TARGET_COMPILER_DIR)lib\wx\include\$(WX_TOOLKIT)-unicode-$(WX_VERSION)
$(TARGET_COMPILER_DIR)include\wx-$(WX_VERSION)


Resource Compiler search directories

$(TARGET_COMPILER_DIR)include\wx-$(WX_VERSION)


Names I use for shared wx libraries

wx_$(WX_TOOLKIT)$(WX_SUFFIX)_gl-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_stc-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_propgrid-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_xrc-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_richtext-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_html-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_adv-$(WX_VERSION).dll
wx_$(WX_TOOLKIT)$(WX_SUFFIX)_core-$(WX_VERSION).dll
wx_base$(WX_SUFFIX)_xml-$(WX_VERSION).dll
wx_base$(WX_SUFFIX)_net-$(WX_VERSION).dll
wx_base$(WX_SUFFIX)-$(WX_VERSION).dll


# Static MSys2 wx library names
Edit: For some reason I had to use full path names for the Static library to be used.
It tried to use the DLLs when I did not use fullpath.

$(TARGET_COMPILER_DIR)lib/libwx_$(WX_TOOLKIT)$(WX_SUFFIX)_core-$(WX_VERSION).a
$(TARGET_COMPILER_DIR)lib/libwx_base$(WX_SUFFIX)-$(WX_VERSION).a

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

stahta01

#2
 Attached a zipped fixed CB Project with name of cbWxWid-msys2.cbp.
It uses the MSys2 MinGW wxWidgets package.
Edit: Static build was used; since, that was what your project used.
I had to add the linker option of "-Wl,--allow-multiple-definition" to get around linker dup error.
Edit2: Removed too many things to list; because they are wrong for using MSys2 MinGW wxWidgets package.

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

ollydbg

Hi, Tim, I notice that "TARGET_COMPILER_DIR" is a good variable if we use msys2, because all the include and lib are its sub folders.
So, I use this variable now, today I found you have post this method already.  :)
Not only linking to wxWidgets library, but also other libraries can use such method.

For example, if I use OpenCV library inside msys2, I now use such include search path:

$(TARGET_COMPILER_DIR)include\opencv4


if I use cairo library, I use such include search path


$(TARGET_COMPILER_DIR)include\cairo


I hope this can help others.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

ollydbg

#4
Quote from: stahta01 on March 02, 2020, 12:25:16 AM
Attached a zipped fixed CB Project with name of cbWxWid-msys2.cbp.
It uses the MSys2 MinGW wxWidgets package.
Edit: Static build was used; since, that was what your project used.
I had to add the linker option of "-Wl,--allow-multiple-definition" to get around linker dup error.
Edit2: Removed too many things to list; because they are wrong for using MSys2 MinGW wxWidgets package.

Tim S.

I just tried your cbp file:
Here is my changes:
1, I remove the "-static" option, I don't see there is a visual option in the build setting dialog, I just removed this line from the cbp xml file.
2, I think directly link to a library with the full path should be changed to: set the library search path, and set the library names.
So:

<Add library="libwx_base$(WX_SUFFIX)-$(WX_VERSION).a" />
<Add library="libwx_base$(WX_SUFFIX)_xml-$(WX_VERSION).a" />
<Add library="libwx_base$(WX_SUFFIX)_net-$(WX_VERSION).a" />
<Add library="libwx_$(WX_TOOLKIT)$(WX_SUFFIX)_core-$(WX_VERSION).a" />
<Add library="libwx_$(WX_TOOLKIT)$(WX_SUFFIX)_adv-$(WX_VERSION).a" />
<Add library="libwx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION).a" />
<Add library="opencv_imgproc$(CV_VERSION).dll" />
<Add library="opencv_core$(CV_VERSION).dll" />
<Add library="opencv_imgcodecs$(CV_VERSION).dll" />
<Add library="opencv_calib3d$(CV_VERSION).dll" />
<Add library="opencv_videoio$(CV_VERSION).dll" />
<Add directory="$(TARGET_COMPILER_DIR)lib" />
<Add directory="$(TARGET_COMPILER_DIR)bin" />

Something like above.
3, I have put the "$(TARGET_COMPILER_DIR)bin" in the library search path, this is because when you click the "run" button to start the application, the library search path will be added to the "PATH" variable, and we can avoid setting the system's PATH.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

stahta01

If you are just doing shared it is normal to use "wx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION)" instead of "libwx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION).a".

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

ollydbg

Quote from: stahta01 on June 03, 2021, 07:02:57 AM
If you are just doing shared it is normal to use "wx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION)" instead of "libwx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION).a".

Tim S.
Hi, thanks for the help, indeed, I just test it, the cbp can be simplified as:


<Linker>
<Add option="-mthreads" />
<Add library="wx_base$(WX_SUFFIX)-$(WX_VERSION)" />
<Add library="wx_base$(WX_SUFFIX)_xml-$(WX_VERSION)" />
<Add library="wx_base$(WX_SUFFIX)_net-$(WX_VERSION)" />
<Add library="wx_$(WX_TOOLKIT)$(WX_SUFFIX)_core-$(WX_VERSION)" />
<Add library="wx_$(WX_TOOLKIT)$(WX_SUFFIX)_adv-$(WX_VERSION)" />
<Add library="wx_$(WX_TOOLKIT)$(WX_SUFFIX)_aui-$(WX_VERSION)" />
<Add library="opencv_imgproc$(CV_VERSION)" />
<Add library="opencv_core$(CV_VERSION)" />
<Add library="opencv_imgcodecs$(CV_VERSION)" />
<Add library="opencv_calib3d$(CV_VERSION)" />
<Add library="opencv_videoio$(CV_VERSION)" />
<Add directory="$(TARGET_COMPILER_DIR)lib" />
<Add directory="$(TARGET_COMPILER_DIR)bin" />
</Linker>
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

stahta01

TO ALL NEWBIES DO NOT PM ME!

Learn how to post this is a forum; if you can not then I will ask that you be banned!!

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]