User forums > General (but related to Code::Blocks)

Configuring Code Blocks in Windows to create GTK applications when using Msys2

(1/3) > >>

tuchin:
Installed Msys2, compiler and GTK+:
--- Code: ---pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-gdb
pacman -S make
pacman -S mingw-w64-x86_64-cmake
pacman -S mingw-w64-x86_64-toolchain base-devel
pacman -S mingw-w64-x86_64-gtk3
pacman -S mingw-w64-x86_64-glade
--- End code ---
Installed Code Blocks, specified the compiler:
--- Code: ---C:\msys64\mingw64
--- End code ---
Set up the project like this:
--- Code: ---Search directories Compiler
C:\msys64\mingw64\include
C:\msys64\mingw64\include\atk-1.0
C:\msys64\mingw64\include\cairo
C:\msys64\mingw64\include\glib-2.0
C:\msys64\mingw64\include\gtk-3.0
C:\msys64\mingw64\include\gtk-3.0\gtk
C:\msys64\mingw64\include\gtk-3.0\gdk
C:\msys64\mingw64\include\gdk-pixbuf-2.0
C:\msys64\mingw64\include\harfbuzz
C:\msys64\mingw64\include\pango-1.0
C:\msys64\mingw64\lib\glib-2.0\include
Search directories Linker
C:\msys64\mingw64\lib
--- End code ---
In a simple program:
--- Code: ---int main(int argc, char *argv[])
{
  gtk_init (&argc, &argv);
  GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_show (win);
  gtk_main ();
  return 0;
}
--- End code ---
I get errors:
--- Code: ---||=== Build: Debug in cbTestGTK (compiler: GNU GCC Compiler) ===|
C:\msys64\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\12.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: obj\Debug\main.o||in function `main':|
D:\MyProgramming\cbTestGTK\main.cpp|5|undefined reference to `gtk_init_abi_check'|
C:\msys64\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\12.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: D:\MyProgramming\cbTestGTK\main.cpp|6|undefined reference to `gtk_window_new'|
C:\msys64\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\12.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: D:\MyProgramming\cbTestGTK\main.cpp|7|undefined reference to `gtk_widget_show'|
C:\msys64\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\12.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: D:\MyProgramming\cbTestGTK\main.cpp|8|undefined reference to `gtk_main'|
||error: ld returned 1 exit status|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
--- End code ---
Please help me set up the project correctly.

Miguel Gimenez:
You added the search directories for the linker, but did not add the gtk library itself.

Look in C:\msys64\mingw64\lib for something similar to "libgtk-3.a" and add it to Linker settings -> Link libraries (I do not use neither GTK nor MSYS2).

tuchin:
It didn't help. There are even more errors.

tumanovalex:
I would also like to get an answer to this question. I followed the same steps and got the same results. By searching through the files, I found that there are links to gtk_init_api_check in C:\msys64\mingw64\lib\libgtk-3.a and C:\msys64\mingw64\lib\libgtk-3.dll.a , but directly connecting them to the project did not help either.

stahta01:
5 years ago, I wrote an CB Project; it might still work.

https://github.com/stahta01/MSys2_CodeBlocks_Projects/tree/master/gtk

Edit: I am trying to test it; but, my Internet Bandwidth is working on a large download; so, it could be a while.
Edit2: I had to add an include path and the project worked.

Tim S.

Navigation

[0] Message Index

[#] Next page

Go to full version