我被要求重新编译一个相当旧的 EMG 处理冷库,以便它可以在现代 Mac 上运行,而不是在当前运行的古老 SunOS 工作站上运行。对于那些对 makefile 不太熟悉的人来说,这是一条痛苦的道路,但在阅读了整个互联网之后,这让我难住了。
makefiles(由 imake 生成)使用每个源文件的以下参数调用 gcc,但因“未定义符号”错误而失败:
gcc -I[First Include Path] -I[Second Include Path] -I. -c [File Name].c
gcc -o [Output File Name] [Include a bunch of libraries] -lm
我认为问题的根源是所有 #include 语句都使用 <>对于系统库,.h 位于包含目录中,.h 位于与正在编译的 .c 文件相同的目录中。我知道这是错的,但事实就是这样。如果我将它们更改为“”,仅将 .h 与正在编译的 .c 位于同一目录中,那么一切都会正常。
当然,我不想对数百个文件单独执行此操作。那么,我可以做一些更改,以便 gcc 在当前目录中查找 #include <> 吗?从我阅读的搜索路径来看,默认情况下它不会?
或者我注定要继续我目前的某种黑客工作批量查找和替换计划?
I have been asked to recompile a rather old library of EMG processing cold so it works on modern Macs rather than the ancient SunOS workstation it is currently running on. It's been a painful road for someone not very experienced with makefiles, but after reading all over the internet this has me stumped.
The makefiles (generated by imake) are calling gcc with the following arguments for each source file, but are failing with 'Undefined symbols' errors:
gcc -I[First Include Path] -I[Second Include Path] -I. -c [File Name].c
gcc -o [Output File Name] [Include a bunch of libraries] -lm
What I assume is the root of the problem is ALL of the #include statements use <> for the system libraries, .h in the include directories, and the .h in the same directory as the .c file being compiled. I know its wrong, but thats the way it is. If I change them to "" for only the .h in the same directory as the .c being compiled then everything works out fine.
Of course I would rather not do this individually for hundreds of files. So, is there some change I can make so gcc will look in the current directory for #include <>? as from reading up on the search path I gather it does not by default?
Or am I doomed to continue with my current plan of some sort of hack job bulk find and replace?
发布评论
评论(1)
根据我的经验,
#include ""
也适用于系统标头。因此,如果您不关心区分本地标头和系统标头,可以尝试将所有#include <>
替换为#include ""
。In my experience
#include ""
will also work for system headers. So you can try replace all#include <>
to#include ""
, if you don't care differentiating local and system headers.