gcc/g++/makefile/easymake/cmake/xmake/nmake ...
最簡單的Makefile,但是還是大程序少不了makefile工具
#CC=arm-linux-gnueabihf-
CC=
target:
?? ?$(CC)gcc -o algo_main algo_main.c cJSON.c -lm
clean:
?? ?@rm -rf algo_main
?
一、Easymake太好用了,偷懶神器,強力推薦.
1、根目錄下的easymake.mk就是makefile模板,我們自定義的makefile只需要包含這個模板即可
include ../../easymake.mk?
2、源碼包自帶的sample夠我們參考應用了。
drwx------ 4 4096 9月 26 10:56 basics drwx------ 4 4096 9月 26 09:50 so drwx------ 3 4096 9月 26 09:49 staticLib drwx------ 4 4096 9月 26 09:49 vpath1) basics常規應用,包含一個shell腳本,也就是copy一份makefile文件?
cp ../../easymake.mk Makefile運行實例
dong@ubuntu:~/cb/easymake-master/samples/basics$ ./test.sh cp ../../easymake.mk Makefilemake g++ -MP -MMD -c -o bin/math/add.o math/add.cpp g++ -MP -MMD -c -o bin/add.o add.cpp # main detected g++ -o bin/add bin/math/add.o bin/add.o./bin/add add(5,6) returns 11create add_test.cppmake test g++ -MP -MMD -c -o bin/add_test.o add_test.cpp # main detected g++ -o bin/add_test bin/math/add.o bin/add_test.o# run [bin/add_test]# add_test: add_test.cpp:7: int main(): Assertion `add(1,1)==3' failed. Makefile:216: recipe for target 'test' failed make: *** [test] Error 2?
2)so生成庫文件并且運行,用shell腳本來編譯
make bin/libmylib.sog++ add_test.cpp -I. -L./bin/ -lmylib -o bin/targetLD_LIBRARY_PATH=./bin/ ./bin/target運行實例
dong@ubuntu:~/cb/easymake-master/samples/so$ ./so_test.sh g++ -I. -fPIC -MP -MMD -c -o bin/math/add.o math/add.cpp g++ -I. -fPIC -MP -MMD -c -o bin/add_test.o add_test.cpp # main detectedg++ -shared -o bin/libmylib.so bin/math/add.o add(8,8)=16?
3)staticLib生成靜態庫,就不一一編譯運行了,同上
?
4)vpath這個實例可以同時編譯多個可運行項目,makefile只需要添加自定義的項目源碼路徑就行了
VPATH = ../src2include ../../../easymake.mk運行實例
dong@ubuntu:~/cb/easymake-master/samples/vpath/proj$ make g++ -MP -MMD -c -o bin/math/add.o math/add.cpp g++ -MP -MMD -c -o bin/main.o main.cpp # main detected g++ -MP -MMD -c -o bin/hello_world.o ../src2/hello_world.cpp g++ -MP -MMD -c -o bin/test.o ../src2/test.cpp # main detected g++ -o bin/main bin/math/add.o bin/main.o bin/hello_world.o g++ -o bin/test bin/math/add.o bin/hello_world.o bin/test.o?
3、Easymake源碼在這里下載
https://github.com/roxma/easymake?
二、還有一堆cmake xmake nmake ...
CMake 入門實戰
http://www.hahack.com/codes/cmake/
cmake_demo.zip
cmake升級
https://blog.csdn.net/learning_tortosie/article/details/80593956
?
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar -xvf cmake-3.9.2.tar.gz
cd cmake-3.9.2
./configure
make
sudo make install?
?
三、指定安裝目錄
一種是在./configure的時候指定路徑
./configure --prefix=$(pwd)/_install
一種是make install的時候指定路徑
make DESTDIR=$(pwd)/_install install
?
?sudo pip2 install numpy --target=/usr/local/lib/python2.7/site-packages
?
四、gcc/g++升級和降級
由于在matlab中要使用mex,需要將原本的gcc '5.4.0' 版本降級(替換)為MEX支持的版本: '4.9.x'。
1.加入源,方便更新。
??? sudo add-apt-repository ppa:ubuntu-toolchain-r/test
2.更新
??? sudo apt-get update
3.安裝
??? sudo apt-get install gcc-4.9
??? sudo apt-get install g++-4.9
4.更新
??? sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
??? sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
5.成功驗證:
??? gcc --version
成功標志:
g++ (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4
??? gcc --version
成功標志:
gcc (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4
原文鏈接:https://blog.csdn.net/Pancheng1/article/details/83058833
?
?
轉載于:https://www.cnblogs.com/dong1/p/5908476.html
總結
以上是生活随笔為你收集整理的gcc/g++/makefile/easymake/cmake/xmake/nmake ...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pip install 出现报ascii
- 下一篇: sysctl.conf文件详解