<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>
"); //-->

博客專(zhuān)欄

EEPW首頁(yè) > 博客 > linux 編譯頭文件默認搜索路徑問(wèn)題

linux 編譯頭文件默認搜索路徑問(wèn)題

發(fā)布人:電子禪石 時(shí)間:2019-11-22 來(lái)源:工程師 發(fā)布文章
總結:

1,如果需要看的話(huà),可以通過(guò)

echo 'main(){}'|arm-linux-gcc ---

其實(shí)是在SPECs文件讀到的。

這個(gè)路徑和你安裝GCC編譯器的配置有關(guān)。至于如何配置,后面有空再細化。

 

2,如果編譯的時(shí)候加入了-nostdinc,則不會(huì )到默認路徑下去搜索。比如用GCC編譯器編譯一個(gè)新的linux內核。()


最開(kāi)始是頭文件找不到問(wèn)題

1.png

一開(kāi)始確實(shí)缺少這個(gè)sqlite.h,拿到這個(gè)(其他同事那有,作者當時(shí)用的)后放到/usr/include,因為網(wǎng)上各種資料表示編譯的時(shí)候默認的頭文件路徑是這個(gè)


試過(guò)其他幾個(gè)地方仍然報同樣的錯,No such file or directory

2.png

但是同樣的程序里包含的pthread.h 在/usr/include里面找到了pthread.h,我就納悶了,放在同樣地方,為啥這個(gè)就找不到
后來(lái)查閱頭文件默認路徑的資料,了解到:
交叉編譯的默認搜索頭文件路徑與普通的gcc不一樣
1,如果需要看的話(huà),可以通過(guò)
echo 'main(){}'|arm-linux-gcc -E -v -

其實(shí)是在SPECs文件讀到的。

3.png

這個(gè)路徑和你安裝GCC編譯器的配置有關(guān)。至于如何配置,后面有空再細化。
2,如果編譯的時(shí)候加入了-nostdinc,則不會(huì )到默認路徑下去搜索。比如用GCC編譯器編譯一個(gè)新的linux內核。()
其實(shí)當時(shí)如果這樣搜一下
kevin@pc:~/works/projects/omc_au$find /opt/arm-2009q1/ -name pthread.h
/opt/arm-2009q1/arm-none-linux-gnueabi/libc/usr/include/pthread.h
就知道其實(shí)還有其他的地方有這個(gè)文件。

好了,通過(guò)上面那條指令可以查到arm-linux-gcc查找頭文件的默認路徑和一些庫的位置
————————————————

原文鏈接:https://blog.csdn.net/davion_zhang/article/details/45075685



https://www.jianshu.com/p/3eb25114576e


編寫(xiě)c/c++的代碼的經(jīng)常,經(jīng)常#include 頭文件。include有兩種方式,一個(gè)是#include “頭文件”,一個(gè)是#include <頭文件>。區別在于:

  1. 前者是從當前的目錄來(lái)搜索

  2. 后者是一般會(huì )先搜索 -I 選項后的路徑(即用gcc編譯時(shí)的-I選項),之后就是標準的系統頭文件路徑。

通過(guò)cpp -v命令,可以查看標準系統頭文件的路徑。

zhaozheng@ubuntu:~$ cpp -vUsing built-in specs.COLLECT_GCC=cppTarget: x86_64-linux-gnuConfigured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnuThread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/5/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu - -mtune=generic -march=x86-64 -fstack-protector-strong -Wformat -Wformat-security
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/5/../../../../x86_64-linux-gnu/include"#include "..." search starts here:#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/5/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed /usr/include/x86_64-linux-gnu /usr/includeEnd of search list.

所以基本上是三個(gè)目錄:
usr/include
usr/lib/include
usr/local/include

注意:usr并不是user用戶(hù)的縮寫(xiě),而是unix system resource 的縮寫(xiě)。

如果我們在給要編譯的代碼加上自己的頭文件,應該怎么辦?

  1. 在path里面加上自己的目錄

  2. gcc或g++ 編譯的時(shí)候 ,加上 -I  選項, 比如這樣

g++ -c ttcp_blocking.cc -I /home/zhaozheng/code/chensuo/code/muduo-master/ -o ttcp_blocking.o

這里把這個(gè)實(shí)際的例子寫(xiě)在這里
在看陳碩的這本《linux 多線(xiàn)程服務(wù)器端編程》書(shū)的時(shí)候,有一個(gè)案例的源碼是這樣的

#include <examples/ace/ttcp/common.h>#include <muduo/base/Timestamp.h>

看來(lái)一個(gè)這個(gè) example/ace/ttcp/common.h 和 muduo/base/Timestamp.h,分別在



image.png

也就是說(shuō),他們分別在 muduo-master的文件夾里面。所有 編譯的時(shí)候,把這個(gè)鏈接上就好。




image.png

所以,把這個(gè)目錄鏈接上去就好。就不會(huì )出現找不到頭文件的情況了。

 -I /home/zhaozheng/code/chensuo/code/muduo-master/


  


*博客內容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀(guān)點(diǎn),如有侵權請聯(lián)系工作人員刪除。

pid控制相關(guān)文章:pid控制原理


可控硅相關(guān)文章:可控硅工作原理


電流傳感器相關(guān)文章:電流傳感器原理
脈沖點(diǎn)火器相關(guān)文章:脈沖點(diǎn)火器原理
三相異步電動(dòng)機相關(guān)文章:三相異步電動(dòng)機原理


關(guān)鍵詞:

相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>