代码之家  ›  专栏  ›  技术社区  ›  Andy

用GCC编译通过MacPorts安装GD2库的C程序时出现问题

  •  0
  • Andy  · 技术社区  · 15 年前

    plotgeometry.c:5:16: error: gd.h: No such file or directory
    plotgeometry.c: In function 'PlotGeometry':
    plotgeometry.c:28: error: 'gdImagePtr' undeclared (first use in this function)
    plotgeometry.c:28: error: (Each undeclared identifier is reported only once
    plotgeometry.c:28: error: for each function it appears in.)
    plotgeometry.c:28: error: expected ';' before 'im'
    plotgeometry.c:29: warning: ISO C90 forbids mixed declarations and code
    plotgeometry.c:748: error: 'im' undeclared (first use in this function)
    plotgeometry.c:748: warning: implicit declaration of function 'gdImageCreate'
    plotgeometry.c:752: warning: implicit declaration of function 'gdImageColorAllocate'
    plotgeometry.c:780: warning: implicit declaration of function 'gdImageSetPixel'
    plotgeometry.c:801: warning: implicit declaration of function 'gdImagePng'
    plotgeometry.c:809: warning: implicit declaration of function 'gdImageDestroy'
    

    我想,我需要为GCC提供GD2库的路径。这个 gd.h 在以下目录中找到

    $ find /opt/local/ -name 'gd.h'
    /opt/local//include/gd.h
    /opt/local//var/macports/software/gd2/2.0.35_7/opt/local/include/gd.h
    

    我补充说 /opt/local/include 给我的 $PATH 你能帮我做这个吗?

    2 回复  |  直到 15 年前
        1
  •  4
  •   Marcelo Cantos    15 年前

    您不使用$PATH。通过 -I gcc的命令行选项。对于直接构建:

    gcc -I/opt/local/include ...
    

    CPPFLAGS='-I/opt/local/include' make
    

    链接时还需要引用库。使用 -L/opt/local/lib -lgd 或者,通过make:

    CPPFLAGS='-I/opt/local/include' LDFLAGS='-L/opt/local/lib' LDLIBS='-lgd' make
    

    当然,您可以在Makefile中设置这些变量。

        2
  •  1
  •   Piotr Kalinowski    15 年前

    你需要加上 -I/opt/local/include 编译器参数(而不是仅由shell用于查找可执行文件的$PATH)。