gpt4 book ai didi

c - 如何链接 X11 程序

转载 作者:行者123 更新时间:2023-12-04 02:34:27 24 4
gpt4 key购买 nike

我已经编译了我的第一个 X11 程序,但无法链接它。我在 64 位 Xubuntu 13.10 上,我使用命令行gcc $(pkg-config x11) findXfonts.c -o findXfonts

编译没问题,但我使用的每个 X* 符号在链接器步骤中都显示为未定义。pkg-config 习语扩展为简单的 -lX11

/*
* Copyright 2014 Kevin O'Gorman <kogorman@gmail.com>.
* Distributed under the GNU General Public License.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
char **fontlist;
XFontStruct *returned_info;
char *pattern="-*-*-*-*-*-*-*-*-*-*-*-*-*-*-";
int nFonts;
char *displayName;
Display *display;
FILE *ostream = stdout;
int i, j, k;

displayName = getenv("DISPLAY"); /* expect ":0.0", but YMMV */
display = XOpenDisplay(displayName);
fontlist = XListFontsWithInfo(display, pattern, 10000, &nFonts, &returned_info);

for (i = 0; i < nFonts; i++) {
fprintf(ostream, "\n%s\n", fontlist[i]);
fprintf(ostream, " first: %u/%u, last: %u/%u\n",
returned_info[i].min_byte1, returned_info[i].min_char_or_byte2,
returned_info[i].max_byte1, returned_info[i].max_char_or_byte2);
for (j = 0; j < returned_info[i].n_properties; j++) {
fprintf(ostream, " %s: %ld\n",
XGetAtomName(display, returned_info[i].properties[j].name),
returned_info[i].properties[j].card32);
}
}

XFreeFontInfo(fontlist, returned_info, nFonts);
return EXIT_SUCCESS;
}

最佳答案

尝试:

gcc $(pkg-config x11 --cflags) findXfonts.c -o findXfonts $(pkg-config x11 --libs)

然后阅读 pgk-config 的手册页:

man pkg-config

关于c - 如何链接 X11 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21068872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com