如何在Makefile中定义多个包含路径

发布于 2024-10-01 08:14:58 字数 481 浏览 0 评论 0原文

C++ 新手;对包含、库和编译过程有基本的了解。还做了一些简单的 makefile。

我当前的项目涉及使用 informix DB api,并且我需要在多个非标准目录中包含头文件。那要怎么写呢?在网上没有找到任何东西,可能是因为我没有使用好的搜索词

这是我尝试过的一种方法(不起作用)。只是为了显示 makefile

LIB=-L/usr/informix/lib/c++
INC=-I/usr/informix/incl/c++ /opt/informix/incl/public

default:    main

main:   test.cpp
        gcc -Wall $(LIB) $(INC) -c test.cpp
        #gcc -Wall $(LIB) $(INC) -I/opt/informix/incl/public -c test.cpp

clean:
        rm -r test.o make.out

New to C++; Basic understanding of includes, libraries and the compile process. Did a few simple makefiles yet.

My current project involves using an informix DB api and i need to include header files in more than one nonstandard dirs. How to write that ? Havent found anything on the net, probably because i did not use good search terms

This is one way what i tried (not working). Just to show the makefile

LIB=-L/usr/informix/lib/c++
INC=-I/usr/informix/incl/c++ /opt/informix/incl/public

default:    main

main:   test.cpp
        gcc -Wall $(LIB) $(INC) -c test.cpp
        #gcc -Wall $(LIB) $(INC) -I/opt/informix/incl/public -c test.cpp

clean:
        rm -r test.o make.out

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月牙弯弯 2024-10-08 08:14:58

您必须在每个目录前面加上 -I

INC=-I/usr/informix/incl/c++ -I/opt/informix/incl/public

You have to prepend every directory with -I:

INC=-I/usr/informix/incl/c++ -I/opt/informix/incl/public
一袭水袖舞倾城 2024-10-08 08:14:58

您需要对每个目录使用 -I 。但如果您使用 (GNU) make 的 foreach,您仍然可以用空格分隔目录:

INC=$(DIR1) $(DIR2) ...
INC_PARAMS=$(foreach d, $(INC), -I$d)

You need to use -I with each directory. But you can still delimit the directories with whitespace if you use (GNU) make's foreach:

INC=$(DIR1) $(DIR2) ...
INC_PARAMS=$(foreach d, $(INC), -I$d)
白云悠悠 2024-10-08 08:14:58

Make 的 替换 功能很好,帮助我编写

%.i: src/%.c $(INCLUDE)
        gcc -E $(CPPFLAGS) $(INCLUDE:%=-I %) 
lt; > $@

您可能会发现这很有用,因为它也要求 make 检查包含文件夹中的更改

Make's substitutions feature is nice and helped me to write

%.i: src/%.c $(INCLUDE)
        gcc -E $(CPPFLAGS) $(INCLUDE:%=-I %) 
lt; > $@

You might find this useful, because it asks make to check for changes in include folders too

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文