简体   繁体   English

如何解决查找 pkg-config 时的 gcc 错误?

[英]How do I solve the gcc error on finding pkg-config?

This question seems to have been asked a zillion times, but unfortunately, none of the answers helped me.这个问题似乎被问了无数次,但不幸的是,没有一个答案对我有帮助。

I believe I have installed gtk correctly.我相信我已经正确安装了 gtk。 My pkg-config environment seems okay.我的 pkg-config 环境似乎没问题。 I'm not so sure of gcc.我不太确定 gcc。 I removed all the mingw and cygwin folders from my path environment, as I am only going to be using msys2 packages.我从我的路径环境中删除了所有 mingw 和 cygwin 文件夹,因为我将只使用 msys2 包。 So I have my path environment this way:-所以我的路径环境是这样的:-

GTK_LIB_DIR C:\\msys64\\mingw64\\lib GTK_LIB_DIR C:\\msys64\\mingw64\\lib

PKG_CONFIG_PATH C:\\msys64\\mingw64\\lib\\pkgconfig PKG_CONFIG_PATH C:\\msys64\\mingw64\\lib\\pkgconfig

Path - C:\\msys64\\usr\\bin;C:\\msys64\\mingw64\\bin;%GTK_LIB_DIR%路径 - C:\\msys64\\usr\\bin;C:\\msys64\\mingw64\\bin;%GTK_LIB_DIR%

The problem I am having is with compilation.我遇到的问题是编译。 Running this... gcc pkg-config --cflags gtk+-3.0 -o gtkTest C:\\dev\\test_gtk3.c pkg-config --libs gtk+-3.0运行这个... gcc pkg-config --cflags gtk+-3.0 -o gtkTest C:\\dev\\test_gtk3.c pkg-config --libs gtk+-3.0

I get...我得到...

cc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: unrecognized command line option '--cflags'
gcc: error: unrecognized command line option '--libs'

I can run the following commands separately, with expected results.我可以单独运行以下命令,并获得预期的结果。 eg例如

pkg-config --cflags gtk+-3.0
pkg-config --libs gtk+-3.0
gcc -o gtkTest C:\dev\test_gtk3.c

Of course the last command returns an error, since gtk is not referenced.当然最后一个命令返回一个错误,因为 gtk 没有被引用。 I tried various combinations, some of my own.我尝试了各种组合,有些是我自己的。 Some recommended, but one error persists, on pkg-config.在 pkg-config 上推荐了一些,但一个错误仍然存​​在。 eg C:\\WINDOWS\\system32> gcc -o gtkTest C:\\dev\\test_gtk3.c "pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0"例如 C:\\WINDOWS\\system32> gcc -o gtkTest C:\\dev\\test_gtk3.c "pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0"

gcc: error: pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0: No such file or directory

The last answer I found says "If pkg-config reports that it couldn't find the package, then you didn't install the Gtk development package as offered by your Linux distribution."我找到的最后一个答案是“如果 pkg-config 报告找不到该软件包,那么您没有安装 Linux 发行版提供的 Gtk 开发软件包。”

I'm using Windows, but I think I installed gtk correctly, since I followed the instructions, and I get what seems to be the expected results (please correct me if I am mistaken).我使用的是 Windows,但我认为我正确安装了 gtk,因为我遵循了说明,并且得到了预期的结果(如果我弄错了,请纠正我)。

C:\\WINDOWS\\system32> pkg-config --cflags gtk+-3.0 C:\\WINDOWS\\system32> pkg-config --cflags gtk+-3.0

-pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/m
ingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/fribidi -I/mingw6
4/include -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include
/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/
mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw
64/include/gdk-pixbuf-2.0 -I/mingw64/include -I/mingw64/lib/libffi-3.2.1/include
 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include

C:\\WINDOWS\\system32> pkg-config --libs gtk+-3.0 C:\\WINDOWS\\system32> pkg-config --libs gtk+-3.0

-L/mingw64/lib -L/mingw64/lib/../lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32
-limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lep
oxy -lopengl32 -lgdi32 -lpangocairo-1.0 -lm -lgdi32 -lpangoft2-1.0 -lm -lpangowi
n32-1.0 -lm -lusp10 -lgdi32 -lpango-1.0 -lm -lfribidi -lthai -ldatrie -latk-1.0
-lcairo-gobject -lcairo -lz -lpixman-1 -lm -pthread -lfontconfig -liconv -lexpat
 -lfreetype -lbz2 -lharfbuzz -lm -lusp10 -lgdi32 -lrpcrt4 -lgraphite2 -lpng16 -l
z -lgdk_pixbuf-2.0 -lm -lgio-2.0 -pthread -lintl -lshlwapi -ldnsapi -liphlpapi -
lws2_32 -lgmodule-2.0 -pthread -lintl -lz -lgobject-2.0 -pthread -lintl -lffi -l
glib-2.0 -lintl -lws2_32 -lole32 -lwinmm -lshlwapi -pthread -lm -lpcre

C:\\WINDOWS\\system32> gcc -o gtkTest C:\\dev\\test_gtk3.c | C:\\WINDOWS\\system32> gcc -o gtkTest C:\\dev\\test_gtk3.c | pkg-config --cflags --libs gtk+-3.0 pkg-config --cflags --libs gtk+-3.0

-pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/m
ingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/fribidi -I/mingw6
4/include -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include
/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/
mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw
64/include/gdk-pixbuf-2.0 -I/mingw64/include -I/mingw64/lib/libffi-3.2.1/include
 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include
-L/mingw64/lib -L/mingw64/lib/../lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32
-limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lep
oxy -lopengl32 -lgdi32 -lpangocairo-1.0 -lm -lgdi32 -lpangoft2-1.0 -lm -lpangowi
n32-1.0 -lm -lusp10 -lgdi32 -lpango-1.0 -lm -lfribidi -lthai -ldatrie -latk-1.0
-lcairo-gobject -lcairo -lz -lpixman-1 -lm -pthread -lfontconfig -liconv -lexpat
 -lfreetype -lbz2 -lharfbuzz -lm -lusp10 -lgdi32 -lrpcrt4 -lgraphite2 -lpng16 -l
z -lgdk_pixbuf-2.0 -lm -lgio-2.0 -pthread -lintl -lshlwapi -ldnsapi -liphlpapi -
lws2_32 -lgmodule-2.0 -pthread -lintl -lz -lgobject-2.0 -pthread -lintl -lffi -l
glib-2.0 -lintl -lws2_32 -lole32 -lwinmm -lshlwapi -pthread -lm -lpcre
C:\dev\test_gtk3.c:1:10: fatal error: gtk/gtk.h: No such file or directory
    1 | #include <gtk/gtk.h>
      |          ^~~~~~~~~~~
compilation terminated.

Has anyone here struggled with this for hours, like I have, and finally got to understand what the problem is.有没有人像我一样为此苦苦挣扎了几个小时,终于明白了问题所在。 Please share your solution.请分享您的解决方案。 Thank you.谢谢你。

Using this Installing gtk and compiling using gcc under windows? 在windows下安装gtk并使用gcc编译? helped me get past the errors.帮助我克服了错误。 I used the following suggestion.我使用了以下建议。

"Instead of a batch file, you may find more convenient to create an user environmental variable and store the flags in there, that way you will be able to compile from within a normal command prompt." “与批处理文件不同,您可能会发现创建用户环境变量并将标志存储在其中更方便,这样您就可以在正常的命令提示符下进行编译。”

So I created two new environment variables (eg GTK_FLAGS_VARS; GTK_LIBS_VARS), and pasted the outputs in the variable values.所以我创建了两个新的环境变量(例如 GTK_FLAGS_VARS;GTK_LIBS_VARS),并将输出粘贴到变量值中。 Then in path place %GTK_FLAGS_VARS%;%GTK_LIBS_VARS% Afterward gcc -o gtkTest C:\\dev\\test_gtk3.c %GTK_FLAGS_VARS% %GTK_LIBS_VARS%然后在路径位置 %GTK_FLAGS_VARS%;%GTK_LIBS_VARS% 之后 gcc -o gtkTest C:\\dev\\test_gtk3.c %GTK_FLAGS_VARS% %GTK_LIBS_VARS%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM