1. 首先在ubuntu下安裝gyp,命令如下:
sudo apt-get install gyp
安裝好gyp工具。
2. 然後在ubuntu下安裝make,命令如下:
apt install make
3. 然後安裝g++,命令如下:
sudo apt-get install build-essential
4. 寫乙個hello world的測試程式,包括:hello.c和main.gyp,具體如下:
hello.c檔案,內容:
#include int main()
main.gyp檔案,內容:
,
],
}
5. 在ubuntu下,cd跳到 hello.c和main.gyp的檔案路徑下,執行命令:
gyp --depth=./ main.gyp
會產生三個檔案:
hello.target.mk
main.makefile
makefile
6. 在ubuntu下,執行make命令,如下:
make
會產生out/default資料夾,在此資料夾下,會產生:
.deps 資料夾
obj.target 資料夾
hello 可執行檔案
7. 在ubuntu下,跳到out/default路徑,執行./hello,即可執行源程式。
./hello
顯示:hello gyp。
注意:
(1) 在使用gyp時,為了保證編譯出來的檔案生成到乙個新的檔案下下,可以執行如下命令:
gyp --depth=./ --generator-output=./build main.gyp
會在build檔案下,生成hello.target.mk、main.makefile、makefile三個檔案。
首先建立genprj.sh,使用命令:touch genprj.sh,再在檔案內寫入:
#!/bin/bash
gyp --depth=./ --generator-output=./build main.gyp
if [ -d build ]; then
cd build
make
fi
在ubuntu下直接執行genprj.sh會出錯,需要轉換編碼格式。
a). 安裝dos2unix包,命令如下:
apt install dos2unix
b). 進行格式轉換,命令如下:
dos2unix genprj.sh
c).格式轉換後,再次執行genprj.sh,可以了。
gyp是實現跨平台編譯的配置工具,在gyp上配置好執行gyp編譯後,會生成makefile檔案,再使用make進行編譯就可以了。
Ubuntu下gyp簡單入門例項
安裝工具 sudo apt get install gyp 1.簡單例項 hello.c include int main main.gyp 構建 gyp depth main.gyp 編譯make 執行.hello hello gyp 2.改進 例項1中整個資料夾都是比較凌亂的,所以做乙個genp...
如何在Ubuntu下使用全民wifi
最近一直想在 ubuntu 下進行開發,苦於公司給的電腦不能連線 wifi 如是拿了乙個全民 wifi 19.9元 接在電腦上,作為無線的網絡卡,接入網路。因為 linux 沒能像window 提供自動驅動,所以得自個整,折騰不息,生命不止。1.檢視usb.如下紅色部分就是新增的全民 wifi 的u...
如何在ubuntu下正確安裝NVIDIA顯示卡驅動?
從安裝顯示卡驅動開始,尤其是做深度學習的話,始終要注意版本對應的問題!一 ubuntu 16.04預設安裝了第三方開源的驅動程式nouveau,安裝nvidia顯示卡驅動首先需要禁用nouveau,不然會碰到衝突的問題,導致無法安裝nvidia顯示卡驅動。sudo gedit etc modprob...