简体   繁体   English

c ++无法找到包含

[英]c++ fails to find includes

Just installed build-essentinals in debian 7. But i noticed the includes for c++ are in /usr/include/c++/4.7... Does anyone why? 刚刚在debian 7中安装了build-essentinals。但是我注意到c ++的包含在/ usr / include / c ++ / 4.7中...有人为什么? Includes used to be in /usr/include, as far as I remember... 包含曾经在/ usr / include中,据我记得...

Everything fails now... ie 一切都失败了......即

main.c:2:20: fatal error  iostream: No such file or directory

And even if i include it with -I, headers are called from headers and it won't find anything, like: 即使我用-I包含它,标题也会从标题中调用,它不会找到任何内容,例如:

/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory

So beacuse bits is NOT in /usr/include but in /usr/include/c++/4.7 compiler can't find it... 所以beacuse位不在/ usr / include中但在/usr/include/c++/4.7编译器找不到它...

I'm using g++ 我正在使用g ++

crafter# g++ -o craft main.cpp 
In file included from /usr/include/c++/4.7/x86_64-linux-gnu/bits/os_defines.h:40:0,
                 from /usr/include/c++/4.7/x86_64-linux-gnu/bits/c++config.h:414,
                 from /usr/include/c++/4.7/iostream:39,
                 from main.cpp:2:
/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory

compilation terminated. 编译终止。

Anyone knows how to fix this? 谁知道如何解决这个问题?

Thanks for your help! 谢谢你的帮助!

You are using gcc to compile C++ code, which results in C++ system headers not being considered in the header lookup process. 您正在使用gcc编译C ++代码,这导致在头查找过程中不考虑C ++系统头。 Use g++ command instead. 请改用g++命令。

Also, you should rename main.c to main.cpp since you are using C++ features. 此外,您应该将main.c重命名为main.cpp因为您正在使用C ++功能。

Finally, compiling a .cpp file with gcc will clear the preprocessing and compiling phase, but fail the linking, because libstdc++ will not be implicitly added. 最后,使用gcc编译.cpp文件将清除预处理和编译阶段,但是链接失败,因为不会隐式添加libstdc++

Your command line should look like g++ main.cpp -o outname . 您的命令行应该看起来像g++ main.cpp -o outname

Apparently a 32/64 bit mixup . 显然是一个32/64位的混音 Solved by installing libc6-dev-i386 for 32 bits builds, or by building for 64 bits. 解决方法是安装libc6-dev-i386进行32位构建,或者构建64位。

A stated by Stefano Sanfilipo, there was indeed a mixup with 32 and 64 bit libraries. Stefano Sanfilipo表示,确实存在32位和64位库的混合。

I solved as suggested by removing all dev packages: 我解决了删除所有开发包的建议:

apt-get remove --purge libc6-dev
apt-get remove --purge libc6-dev-i386

And then reinstalling: 然后重新安装:

apt-get install build-essential

And now it compiles perfectly. 现在它完美编译。

MSalters also saw the problem though, what shold I do in this case so that both get credit? MSalters也看到了这个问题,在这种情况下我做了什么,以便两者都得到信用?

Regards, 问候,

David 大卫

只需将include directlory放在编译器的-I参数中,例如:

$(CC) -I/usr/include/c++/4.7 ...

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

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