通过MacPorts安装GD2库的GCC编译C程序时出现问题 [英] Problem to compile a C-program by GCC with GD2 library installed via MacPorts

查看:90
本文介绍了通过MacPorts安装GD2库的GCC编译C程序时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地在Mac上通过GCC编译了C程序,并直接从源代码安装了GD2库.现在,我尝试通过MacPorts安装的GD2库来执行此操作,并显示以下错误消息:

I have successfully compiled a C-program by GCC on Mac with GD2 library installed directly from sources. Now I am trying to do that with GD2 library installed via MacPorts and have the following error message:

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

I guess, I need to provide the path to GD2 library for GCC. The gd.h is found in the following dirs

$ 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

我在 $ PATH 变量中添加了/opt/local/include ,但这没有帮助.我是否需要使用该路径将其他参数传递给GCC?你能帮我吗?

I have added /opt/local/include to my $PATH variable, but it did't help. Do I need to path an additional parameter with that path to GCC? Could you help me with this?

推荐答案

您不使用$ PATH.通过 -I 命令行选项将其添加到gcc.对于直接构建:

You don't use $PATH. Add it via the -I command-line option to gcc. For direct builds:

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

化妆:

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

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

You'll also need to reference the library while linking. Use -L/opt/local/lib -lgd or, via make:

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

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

You can, of course, set these variables in your Makefile.

这篇关于通过MacPorts安装GD2库的GCC编译C程序时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆