我真的需要指定库位置来与 automake 链接吗?
我正在开发一个多平台 C 程序。由于每台机器上都有不同的编译器、库位置等,makefile 变得相当复杂。我认为 Autoconf/Automake 将是一个很好的解决方案,尽管我以前使用这些工具的经验很少。
我的 Makefile.am
包含行 LIBS=-lX11
,但链接失败并出现错误 "/usr/bin/ld: 找不到 -lX11".我可以通过将
"-L/usr/X11R6/lib/"
添加到 LIBS
的定义来解决这个问题,但我真的需要这样做吗?当我运行 ./configure
时,它说:
checking for X...libraries /usr/X11R6/lib, headers /usr/X11R6/include
所以看起来像 Automake应该知道在哪里可以找到它。有没有办法可以在 Makefile.am
中引用它的位置,而不必对其进行硬编码,因为 X11 libs
将位于每台计算机上的不同位置?
I am working on a multi-platform C
program. The makefile has become pretty complicated because of all the different compilers, library locations, etc. on each machine. I figured Autoconf/Automake
would be a good solution, though my previous experience using those tools was minimal.
My Makefile.am
has the line LIBS=-lX11
, but linking fails with the error "/usr/bin/ld: cannot find -lX11"
. I can work around this by adding "-L/usr/X11R6/lib/"
to the definition of LIBS
, but should I really need to do that? When I run ./configure
, it says:
checking for X... libraries /usr/X11R6/lib, headers /usr/X11R6/include
So it seems like Automake should know where to find it. Is there a way I can reference its location in Makefile.am
without having to hardcode it, since the X11 libs
will be in a different place on each machine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 Makefile.am 不应设置 LIBS。如果您需要链接库,configure.ac 应包含对库的检查,并且配置脚本将相应地设置 LIBS。另外,Makefile.am 不应指定库的路径。应配置每个系统,以便预编译器可以找到标头并且链接器可以找到库。如果系统未设置为链接器可以找到库,则正确的解决方案是用户在 LDFLAGS 中指定位置,而不是在 Makefile.am 中硬编码某些内容。 (例如,您应该将 LDFLAGS=-L/p/a/t/h 添加到configure 的调用中,而不是将-L/p/a/t/h 添加到Makefile 中。)
Your Makefile.am should not set LIBS. If you need to link with a library, configure.ac should include a check for the library and the configure script will set LIBS accordingly. Also, Makefile.am should not specify paths to libraries. Each system should be configured so that the precompiler can find the headers and the linker can find the libraries. If the system is not set up so that the linker can find a library, the correct solution is for the user to specify the location in LDFLAGS rather than hard coding something in Makefile.am. (eg, rather than adding -L/p/a/t/h to a Makefile, you should add LDFLAGS=-L/p/a/t/h to the invocation of configure.)