【发布时间】:2014-08-24 02:11:46
【问题描述】:
我正在重新发现编译 C 的可怕之处。我刚刚从http://libtins.github.io 安装了libtins,遵循通常的./configure -> make -> sudo make install 模式。
sudo make install 肯定会在/usr/local/include/tins 中放入标头,但g++ 似乎无法看到它们。
按照here 的建议,我尝试运行gcc -x c++ -v -E /dev/null 以查看包含路径。
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.3.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
我本来希望在某处看到/usr/local/include。现在默认路径路径都在 Xcode 应用程序内吗?
app.cpp
#include <tins/tins.h>
int main() {
return 1;
}
编译命令
g++ app.cpp -ltins
结果
app.cpp:3:10: fatal error: 'tins/tins.h' file not found
知道如何让g++ 看到标题吗?
【问题讨论】:
-
我已经尝试将
tins文件夹放入/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include。 g++ 立即拿起它。不过,这不应该是必要的,不是吗? -
这没有必要。
/usr/local/include和/usr/local/lib不是 OS X 上预处理器默认搜索路径的一部分。您显示的输出就是证明。您可以 (a) 修改预处理器的默认搜索路径(不推荐)或 (b) 使用-Ipath修改预处理器搜索源(并且可能为链接器关联-Llibpath)。clang曾经为你这样做(gcc 没有)为/usr/local/include。但是,我的 确实 see here 在 gcc 模式下(有趣)。