Fail to compile gtk3 both in msys2 and cmd

 gcc main.c -o executable.exe  ` pkg-config --cflags --libs gtk+-3.0  `
main.c:5:10: fatal error: gtk/gtk.h: No such file or directory
    5 | #include <gtk/gtk.h>
      |          ^~~~~~~~~~~
compilation terminated.

I have tried this mingw64.exe, but the results are the same as above.

The correct command line is:

gcc -Wall `pkg-config --cflags gtk+-3.0` -o executable.exe main.c `pkg-config --libs gtk+-3.0`

You’re placing the backticks ` in the wrong order.

You can also use $( ):

gcc -Wall $( pkg-config --cflags gtk+-3.0 ) -o executable.exe main.c $( pkg-config --libs gtk+-3.0 )
gcc: error: unrecognized command-line option '--cflags'
gcc: error: unrecognized command-line option '--libs'

I have tried your command but was given the error above.

What happens when you try pkg-config by itself?

Please specify at least one package name on the command line.

That’s the results I got when I tried your command pkg-config

Then you’re writing the command line for GCC wrong. If you’re getting:

it means you’re passing --cflags and --libs to GCC, instead of passing them to pkg-config and using pkg-config’s output with GCC.

Since you’re not using a build system, you can also copy the output of:

pkg-config --cflags gtk+-3.0

to get the compiler flags, and:

pkg-config --libs gtk+-3.0`

to get the linker flags.

I have alredy tried to add the

pkg-config --cflags gtk+-3.0

pkg-config --libs gtk+-3.0

to codeblocks. But

G:\document\C++C\gtkCode\main.c|5|fatal error: gtk/gtk.h: No such file or directory|.

Actually, I can find the gtk.h in mingw64/include/gtk-3.0. But I don’t know why it fails to do so.

Open CMD and tell us what returns the following command:

pkg-config --modversion gtk+-3.0
G:\document\C++C\gtkCode>pkg-config --modversion gtk+-3.0
3.24.30

That’s what I got from your command.

Then you are doing something wrong there. Emmanuele gave you some Hints.

What results do you expect? I don’t understand his hints. Copy pkg-config --cflags gtk+-3.0 output to to where?

Did you try the first command line that @ebassi suggested? Perhaps your gcc is sensitive to the order of its arguments.

I have tried. But where should I put the output?

I have tried. But where should I put the output?

You did not type the backticks! Without those backticks, the word pkg-config was seen as an ordinary file-name; it wasn’t seen as a command. Because of that problem, the words that followed it, --cflags and --libs, looked as though they belonged to gcc. Of course, they don’t; therefore, gcc complained.

When you type @ebassi’s command again, make sure that you type all of the backticks – there are four of them on that line. Make sure that you type them exactly where he typed them.

Nope, I added backticks. The reason why it’s no displayed properly it’s because it’s recognized as code blocks in this website format. Finally, I manged to fix this issue with backslashes \ as prefixes before baclticks `

G:\document\C++C\gtkCode>gcc -Wall `pkg-config --cflags gtk±3.0` -o executable.exe main.c `pkg-config --libs gtk±3.0`
gcc: error: unrecognized command-line option ‘–cflags’
gcc: error: unrecognized command-line option ‘–libs’

That looks like Windows’ command prompt. Backticks don’t work in cmd.exe! “$( )” also doesn’t work. In cmd.exe, they’re ordinary punctuation characters.

You must go into MSys2, navigate to /g/document/C++C/gtkCode, and enter the command there.

jack@DESKTOP-RDDFVF2 MINGW64 /g/document/C++C/gtkCode

gcc -Wall `pkg-config --cflags gtk±3.0` -o executable.exe main.c `pkg-config --libs gtk±3.0`

main.c:5:10: fatal error: gtk/gtk.h: No such file or directory
5 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.

I execute this mingw64

Why are you using ± between gtk and 3.0?

This is a format issue which was caused by this website. I really don’t know how to fix this on this website. I have tried to use backslash \ to fix. But this is not working.