我正确使用 libtool 吗?
我正在运行 Linux,Ubuntu 10.04 。
这不是我第一次尝试使用自动工具。我做了很多研究并遵循了很多教程:这是我想做的、我尝试过的以及我面临的问题。
目标:
- 使用 libtool、autoconf 和 automake 编译(然后交叉编译,但这将是另一项工作)我自己的用 C 编写的库
我尝试过的内容以及我所处的位置 :
库名称为FXPLib,包名称为libfxplib-0.1
我的项目文件夹是:
Makefile.am(唯一的一个) 包括 include/fxplib.h(主头文件) 包括/FXPLib include/FXPLib/header1.h(这些是公共标头) 包含/FXPLib/header2.h 包括/FXPLib/... 源代码 src/sub1/file1.c src/sub2/file1.c src/sub3 ...
我运行了自动扫描,得到了一个configure.ac,如下编辑:
<前><代码># -*- Autoconf -*- # 使用 autoconf 处理此文件以生成配置脚本。 AC_PREREQ([2.65]) AC_INIT([libfxplib-0.1], [0.1], [<>]) AC_CONFIG_SRCDIR([src/object_system/FXP_image_s.h]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE AM_PROG_LIBTOOL LT_PREREQ([2.2]) LT_INIT # 检查程序。 AC_PROG_CC AC_PROG_MAKE_SET # 检查库。 # 检查头文件。 AC_CHECK_HEADERS([stdlib.h]) # 检查类型定义、结构和编译器特性。 AC_HEADER_STDBOOL # 检查库函数。 AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([memset]) AC_CONFIG_FILES([生成文件]) 交流输出我像这样编写了Makefile.am:
lib_LTLIBRARIES = libfxplib-0.1.la libfxplib_0_1_la_CFLAGS = -I$(srcdir)/include -I$(srcdir)/include/FXPLib `sdl-config --cflags --libs` -lSDL_image libfxplib_0_1_la_SOURCES = src/sub1/file1.c \ src/sub1/file2.c \ src/sub2/file1.h \ ... nobase_include_HEADERS = include/fxplib.h \ 包括/FXPLib/header1.h \ 包括/FXPLib/header2.h \ ... ACLOCAL_AMFLAGS = -I m4
- 然后我运行aclocal和autoheader来获取automake所需的文件
- 然后最重要的: autoconf
- 和:automake --add-missing --copy
从那里,一切都好。但后来我尝试编译:
$ ./configure
一切都好...
$ make
然后我得到:
...
src/graphics_engine/FXP_rendering.c:35:25: error: FXP_image_s.h: File not found
...
其中:
- “graphics_engine”相当于 src/sub
- “FXP_rendering.c”到 src/sub/file.c
- “FXP_image_s.h”到 src/sub2/header.h
这意味着: automake 可以编译子目录中的 .c 文件,但不能在这些文件中包含其他子目录中的私有 .h 文件。
我的问题是:如何告诉 automake 编译每个子目录中的每个文件,就好像它们都在同一个地方一样?
我希望我是可以理解的(对于你在我的话中可能发现的一些问题感到抱歉,因为我是法国人)
提前谢谢你。
I am running Linux, Ubuntu 10.04 .
It is not the first time I try to use autotools. I did a lot of researches and follow a lot of tutorials : here is what I want to do, what I tried and what issue I am facing.
Goal :
- compile (and then cross-compile, but this will be an other job) my own library coded in C using libtool, autoconf and automake
What I tried and where I am :
The library name is FXPLib, the package name is libfxplib-0.1
My project folder is :
Makefile.am (the only one) include include/fxplib.h (main header) include/FXPLib include/FXPLib/header1.h (these are public headers) include/FXPLib/header2.h include/FXPLib/... src src/sub1/file1.c src/sub2/file1.c src/sub3 ...
I ran autoscan, got a configure.ac, edited it as here :
# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.65]) AC_INIT([libfxplib-0.1], [0.1], [<>]) AC_CONFIG_SRCDIR([src/object_system/FXP_image_s.h]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE AM_PROG_LIBTOOL LT_PREREQ([2.2]) LT_INIT # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET # Checks for libraries. # Checks for header files. AC_CHECK_HEADERS([stdlib.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL # Checks for library functions. AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([memset]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT
I wrote Makefile.am like this :
lib_LTLIBRARIES = libfxplib-0.1.la libfxplib_0_1_la_CFLAGS = -I$(srcdir)/include -I$(srcdir)/include/FXPLib `sdl-config --cflags --libs` -lSDL_image libfxplib_0_1_la_SOURCES = src/sub1/file1.c \ src/sub1/file2.c \ src/sub2/file1.h \ ... nobase_include_HEADERS = include/fxplib.h \ include/FXPLib/header1.h \ include/FXPLib/header2.h \ ... ACLOCAL_AMFLAGS = -I m4
- Then I ran aclocal and autoheader to get files needed by automake
- Then the most important : autoconf
- And : automake --add-missing --copy
From there, everything is ok. But then I try to compile :
$ ./configure
Everything ok too...
$ make
and then I get :
...
src/graphics_engine/FXP_rendering.c:35:25: error: FXP_image_s.h: File not found
...
where :
- "graphics_engine" is equivalent to src/sub
- "FXP_rendering.c" to src/sub/file.c
- "FXP_image_s.h" to src/sub2/header.h
This means : automake can compile .c files in a sub directory, but can't include in these files a private .h file that is in an other sub directory.
My problem is : How to tell automake to compile every files in every subdirectories as if they were all in the same place ?
I hope I am understandable (and sorry for some problems you could find in my words, cause I am French)
Thank you by advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
configure.ac
和Makefile.am
文件看起来您一定投入了大量的精力来学习。恭喜!一个有用的提示是,您可以只运行autoreconf
而不是整个aclocal
、autoheader
、autoconf
链,automake
等。这种情况下的问题实际上不是 autotools,而是 C 编译器本身 - 您正在项目的根目录中执行编译器来编译
src/sub< 中的文件/code>,但由于 src/sub2 既不是当前目录,也不是包含路径,编译器不知道在哪里找到它。
尝试将
-I$(srcdir)/src/sub2
添加到Makefile.am
中的libfxplib_0_1_la_CFLAGS
行。这将更改包含路径,以便指示编译器在 src/sub2 中查找头文件,因此您必须为包含以下内容的每个sub
目录添加类似的指令在另一个目录中使用的头文件。Your
configure.ac
andMakefile.am
files look like you must have put a lot of effort into learning. Congratulations! One useful tip is that you can just runautoreconf
instead of the whole chain ofaclocal
,autoheader
,autoconf
,automake
, etc.The problem in this case is actually not the autotools, but the C compiler itself - you are executing the compiler in your project's root directory to compile a file in
src/sub
, but sincesrc/sub2
is neither the current directory nor in the include path, the compiler doesn't know where to find it.Try adding
-I$(srcdir)/src/sub2
to yourlibfxplib_0_1_la_CFLAGS
line inMakefile.am
. This will change the include path so as to instruct the compiler to look for header files insrc/sub2
, so you will have to add a similar instruction for everysub
directory containing header files used in another directory.