简体   繁体   English

G ++添加包含和链接路径

[英]G++ Add include and linking path

My Problem 我的问题

I read somewhere that to add include paths to g++ you need to use the -I option: 我读到某处要添加包含路径到g ++,您需要使用-I选项:

g++ -I /some/directory and_then_my_files.cpp

However, I'm not sure if this is actually what I need. 但是,我不确定这是否是我真正需要的。 It's currently not working for me, and I couldn't find anything else close to what I have. 目前,它对我不起作用,而且我找不到其他任何东西。

My Setup 我的设定

I've got a directory with all my current project code, and in it a subdirectory classes , that contains various .h and .cpp files containing classes that may or may not be used when compiling my main files. 我有一个包含所有当前项目代码的目录,并且在其中有一个子目录classes ,其中包含各种.h.cpp文件,这些文件包含在编译主文件时可能会或可能不会使用的类。

Since g++ ./classes/*.cpp main.cpp takes a long time (large number of files in classes directory), I'm looking for an alternative that only compiles and links the files that are included in the main file. 由于g++ ./classes/*.cpp main.cpp需要很长时间( classes目录中有大量文件),因此我正在寻找一种仅编译和链接主文件中包含的文件的替代方法。

Main file: 主文件:

#include "classes/a.h"
#include "classes/b.h"
// ... my code

And as you can imagine, g++ complains about undefined references to classes A and B, unless I add ./classes/*.cpp to the build command. 可以想像,除非我在build命令中添加./classes/*.cpp ,否则g ++会抱怨未定义对类A和B的引用。

What I want to achieve 我想实现的目标

So -I and -L did not work, and adding the whole directory to the build command results in a ridiculously long build time - I'm talking 3-5 minutes, which really slows down my development speed. 因此, -I-L无效,并且将整个目录添加到build命令中会导致构建时间过长,这很荒谬-我说的是3-5分钟,这确实减慢了我的开发速度。

Is there any way to only build/link the included classes from my classes directory, such as only classes A and B from the example I gave above? 有什么方法可以仅从我的classes目录中构建/链接所包含的类,例如我上面给出的示例中的类A和B?

Small Recap of what I've already tried 我已经尝试过的小回顾

g++ -I ./classes main.cpp -o main

g++ -L ./classes main.cpp -o main (probably stupid but I tried it anyway) g++ -L ./classes main.cpp -o main (可能是愚蠢的,但我还是尝试过)

g++ ./classes/*.cpp main.cpp -o main (what I currently have to resort to) g++ ./classes/*.cpp main.cpp -o main (我目前必须采取的措施)


Thanks in advance :) 提前致谢 :)

临时解决方法

export CPLUS_INCLUDE_PATH=/usr/local/include

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM