1. 程式人生 > >[C/C++]_[從netbeans裡提取的通用構建C++專案的Makefile檔案]

[C/C++]_[從netbeans裡提取的通用構建C++專案的Makefile檔案]

1.有了這個配置檔案,你可以用任何ide或文字編輯器,除了不支援makefile的ide。

2.makefile的好處不用說吧,不依賴ide,如果g++或ide更新了的話makefile什麼都不需要做。但是基於專案檔案的編譯配置就難了,比如vs2010專案如果想用vs2005編譯的話。。。。

3.makefile從編譯到連結選項都可以自己控制。

4個檔案,當然有時間的話也可以自己改改減少數量,自己刪除註釋吧。微笑

主 Makefile,放在專案根目錄下.

#
#  There exist several targets which are by default empty and which can be 
#  used for execution of your targets. These targets are usually executed 
#  before and after some main targets. They are: 
#
#     .build-pre:              called before 'build' target
#     .build-post:             called after 'build' target
#     .clean-pre:              called before 'clean' target
#     .clean-post:             called after 'clean' target
#     .clobber-pre:            called before 'clobber' target
#     .clobber-post:           called after 'clobber' target
#     .all-pre:                called before 'all' target
#     .all-post:               called after 'all' target
#     .help-pre:               called before 'help' target
#     .help-post:              called after 'help' target
#
#  Targets beginning with '.' are not intended to be called on their own.
#
#  Main targets can be executed directly, and they are:
#  
#     build                    build a specific configuration
#     clean                    remove built files from a configuration
#     clobber                  remove all built files
#     all                      build all configurations
#     help                     print help mesage
#  
#  Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
#  .help-impl are implemented in nbproject/makefile-impl.mk.
#
#  Available make variables:
#
#     CND_BASEDIR                base directory for relative paths
#     CND_DISTDIR                default top distribution directory (build artifacts)
#     CND_BUILDDIR               default top build directory (object files, ...)
#     CONF                       name of current configuration
#     CND_PLATFORM_${CONF}       platform name (current configuration)
#     CND_ARTIFACT_DIR_${CONF}   directory of build artifact (current configuration)
#     CND_ARTIFACT_NAME_${CONF}  name of build artifact (current configuration)
#     CND_ARTIFACT_PATH_${CONF}  path to build artifact (current configuration)
#     CND_PACKAGE_DIR_${CONF}    directory of package (current configuration)
#     CND_PACKAGE_NAME_${CONF}   name of package (current configuration)
#     CND_PACKAGE_PATH_${CONF}   path to package (current configuration)
#
# NOCDDL


# Environment 
MKDIR=mkdir -p
CP=cp
CCADMIN=CCadmin

# build
build: .build-init .build-post

.build-init:

.build-pre:
# Add your pre 'build' code here...
	windres --input-format=rc -O coff -i resources/style.rc -o build/style.o --define __WXMSW__ --include-dir E:/software/Lib/gui/wxWidgets-2.9.2/include
	
.build-post: .build-impl
# Add your post 'build' code here...
	${CP} E:/software/Lib/gui/wxWidgets-2.9.2/win32/release/share/wxmsw292u_adv_gcc_custom.dll dist/Debug/MinGW-Windows/
	${CP} E:/software/Lib/gui/wxWidgets-2.9.2/win32/release/share/wxmsw292u_core_gcc_custom.dll dist/Debug/MinGW-Windows/
	${CP} E:/software/Lib/gui/wxWidgets-2.9.2/win32/release/share/wxbase292u_gcc_custom.dll dist/Debug/MinGW-Windows/
	${CP} E:/software/MinGW/bin/libgcc_s_dw2-1.dll dist/Debug/MinGW-Windows/
	
# clean
clean: .clean-post

.clean-pre:
# Add your pre 'clean' code here...

.clean-post: .clean-impl
# Add your post 'clean' code here...


# clobber
clobber: .clobber-post

.clobber-pre:
# Add your pre 'clobber' code here...

.clobber-post: .clobber-impl
# Add your post 'clobber' code here...


# all
all: .all-post

.all-pre:
# Add your pre 'all' code here...

.all-post: .all-impl
# Add your post 'all' code here...


# build tests
build-tests: .build-tests-post

.build-tests-pre:
# Add your pre 'build-tests' code here...

.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...


# run tests
test: .test-post

.test-pre:
# Add your pre 'test' code here...

.test-post: .test-impl
# Add your post 'test' code here...


# help
help: .help-post

.help-pre:
# Add your pre 'help' code here...

.help-post: .help-impl
# Add your post 'help' code here...



# include project implementation makefile
include nbproject/Makefile-impl.mk

# include project make variables
include nbproject/Makefile-variables.mk


根目錄下建nbproject資料夾,放入以下檔案。

Makefile-variables.mk 這個檔案不需要管

#
# Generated - do not edit!
#
# NOCDDL
#
CND_BASEDIR=`pwd`
CND_BUILDDIR=build
CND_DISTDIR=dist
# Debug configuration
CND_PLATFORM_Debug=MinGW-Windows
# Release configuration
CND_PLATFORM_Release=MinGW-Windows

Makefile-impl.mk 這個檔案不需要管
# 
# Generated Makefile - do not edit! 
# 
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a pre- and a post- target defined where you can add customization code.
#
# This makefile implements macros and targets common to all configurations.
#
# NOCDDL


# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
# and .clean-reqprojects-conf unless SUB has the value 'no'
SUB_no=NO
SUBPROJECTS=${SUB_${SUB}}
BUILD_SUBPROJECTS_=.build-subprojects
BUILD_SUBPROJECTS_NO=
BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
CLEAN_SUBPROJECTS_=.clean-subprojects
CLEAN_SUBPROJECTS_NO=
CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}


# Project Name
PROJECTNAME=

# Active Configuration
DEFAULTCONF=Debug
CONF=${DEFAULTCONF}

# All Configurations
ALLCONFS=Debug Release 


# build
.build-impl: .build-pre .validate-impl .depcheck-impl
	@#echo "=> Running 
[email protected]
Configuration=$(CONF)" "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf # clean .clean-impl: .clean-pre .validate-impl .depcheck-impl @#echo "=> Running [email protected] Configuration=$(CONF)" "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf # clobber .clobber-impl: .clobber-pre .depcheck-impl @#echo "=> Running
[email protected]
" for CONF in ${ALLCONFS}; \ do \ "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \ done # all .all-impl: .all-pre .depcheck-impl @#echo "=> Running [email protected]" for CONF in ${ALLCONFS}; \ do \ "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \ done # build tests .build-tests-impl: .build-impl .build-tests-pre @#echo "=> Running [email protected] Configuration=$(CONF)" "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf # run tests .test-impl: .build-tests-impl .test-pre @#echo "=> Running [email protected] Configuration=$(CONF)" "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf # dependency checking support .depcheck-impl: @echo "# This code depends on make tool being used" >.dep.inc @if [ -n "${MAKE_VERSION}" ]; then \ echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \ echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \ echo "include \$${DEPFILES}" >>.dep.inc; \ echo "endif" >>.dep.inc; \ else \ echo ".KEEP_STATE:" >>.dep.inc; \ echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \ fi # configuration validation .validate-impl: @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ then \ echo ""; \ echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \ echo "See 'make help' for details."; \ echo "Current directory: " `pwd`; \ echo ""; \ fi @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \ then \ exit 1; \ fi # help .help-impl: .help-pre @echo "This makefile supports the following configurations:" @echo " ${ALLCONFS}" @echo "" @echo "and the following targets:" @echo " build (default target)" @echo " clean" @echo " clobber" @echo " all" @echo " help" @echo "" @echo "Makefile Usage:" @echo " make [CONF=<CONFIGURATION>] [SUB=no] build" @echo " make [CONF=<CONFIGURATION>] [SUB=no] clean" @echo " make [SUB=no] clobber" @echo " make [SUB=no] all" @echo " make help" @echo "" @echo "Target 'build' will build a specific configuration and, unless 'SUB=no'," @echo " also build subprojects." @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no'," @echo " also clean subprojects." @echo "Target 'clobber' will remove all built files from all configurations and," @echo " unless 'SUB=no', also from subprojects." @echo "Target 'all' will will build all configurations and, unless 'SUB=no'," @echo " also build subprojects." @echo "Target 'help' prints this message." @echo ""

Makefile-Debug.mk 往裡新增編譯檔案和編譯連結引數,如果是Release,新增一個Makefile-Release.mk檔案,把Debug替換為Release即可。
#
# Generated Makefile - do not edit!
#
# Edit the Makefile in the project folder instead (../Makefile). Each target
# has a -pre and a -post target defined where you can add customized code.
#
# This makefile implements configuration specific macros and targets.


# Environment
MKDIR=mkdir
CP=cp
GREP=grep
NM=nm
CCADMIN=CCadmin
RANLIB=ranlib
CC=gcc.exe
CCC=g++.exe
CXX=g++.exe
FC=gfortran.exe
AS=as.exe

# Macros
CND_PLATFORM=MinGW-Windows
CND_CONF=Debug
CND_DISTDIR=dist

# Include project Makefile
include Makefile

# Object Directory
OBJECTDIR=build/${CND_CONF}/${CND_PLATFORM}

# Object Files
OBJECTFILES= \
	${OBJECTDIR}/src/my_app.o \
	${OBJECTDIR}/src/my_frame.o

# C Compiler Flags
CFLAGS=

# CC Compiler Flags
CXXFLAGS=-D_LARGEFILE_SOURCE=unknown -DwxDEBUG_LEVEL=0 -DWXUSINGDLL -D__WXMSW__ -mthreads -m32 -Wall  -MMD -MP -MF [email protected]  
CPPFLAGS=\
-IE:/software/Lib/gui/wxWidgets-2.9.2/include \
-IE:/software/Lib/gui/wxWidgets-2.9.2/win32/release/share/include \
-Iinclude

# Fortran Compiler Flags
FFLAGS=

# Assembler Flags
ASFLAGS=

# Link Libraries and Options
LDLIBSOPTIONS= \
-Wl,--subsystem,windows -mwindows \
-LE:/software/Lib/gui/wxWidgets-2.9.2/win32/release/share  \
-lwx_mswu_adv-2.9 -lwx_mswu_core-2.9 -lwx_baseu-2.9 \
build/style.o


# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
	"${MAKE}"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/test_wx.exe

dist/Debug/MinGW-Windows/test_wx.exe: ${OBJECTFILES}
	${MKDIR} -p dist/Debug/MinGW-Windows
	${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/test_wx -Wl,-s ${OBJECTFILES} ${LDLIBSOPTIONS} 

${OBJECTDIR}/src/my_app.o: src/my_app.cpp 
	${MKDIR} -p ${OBJECTDIR}/src
	${RM} [email protected]
	$(COMPILE.cc) -o ${OBJECTDIR}/src/my_app.o src/my_app.cpp

${OBJECTDIR}/src/my_frame.o: src/my_frame.cpp 
	${MKDIR} -p ${OBJECTDIR}/src
	${RM} [email protected]
	$(COMPILE.cc) -o ${OBJECTDIR}/src/my_frame.o src/my_frame.cpp

# Subprojects
.build-subprojects:

# Clean Targets
.clean-conf: ${CLEAN_SUBPROJECTS}
	${RM} -r build/Debug
	${RM} dist/Debug/MinGW-Windows/test_wx.exe

# Subprojects
.clean-subprojects:

# Enable dependency checking
.dep.inc: .depcheck-impl

include .dep.inc

會Makefile一點原理的會知道往哪裡新增編譯項。

參考例子的配置下載連結:

相關推薦

[C/C++]_[netbeans提取通用構建C++專案Makefile檔案]

1.有了這個配置檔案,你可以用任何ide或文字編輯器,除了不支援makefile的ide。 2.makefile的好處不用說吧,不依賴ide,如果g++或ide更新了的話makefile什麼都不需要做。但是基於專案檔案的編譯配置就難了,比如vs2010專案如果想用vs20

javaJDK提取全球資料,包含國家(名稱、二字程式碼、三字程式碼)、幣種(名稱和程式碼)、和語言種類的資料

JDK版本:jdk1.8.0_66 主要需要依賴的類 import sun.util.locale.provider.LocaleProviderAdapter; import sun.util.locale.provider.ResourceBun

C#_DataTable中檢索信息

int 說明 () [] font blog where 所有 字符 C#_從DataTable中檢索信息 存在於內存中的虛擬表DataTable,綁定在數據顯示控件後,如果想在再檢索其中某些信息,可以利用DataTable.Select方法進行檢索,避免了重復

C# DbHelperSQL 類,東軟生成器提取而來

ida 提取 csharp lpar rac 生成 action red stat DBHelerSQL,可以結合東軟生成器寫簡單三層結構,也可以自己去調用執行相關SQL語句 直接上代碼: using System; using System.Collect

『Python CoolBook』C擴展庫_其六_C語言中調用Python代碼

callable 什麽 跟著 來講 cpp iat mst 轉化 gcc 一、C語言運行pyfun的PyObject對象 思路是在C語言中提供實參,傳給python函數: 獲取py函數對象(PyObject),函數參數(C類型) 獲取GIL(PyGILState_

c++基礎】json檔案提取資料

前言 標註資料匯出檔案是json格式的,也就是python的dict格式,需要讀取標註結果,可以使用c++或者python,本文使用c++實現的。 JsonCpp簡介 JsonCpp是一種輕量級的資料交換格式,是個跨平臺的開源庫,可以從github和sourceforge上下載原始碼。 JsonCpp

C語言_在自定義函式使用結構體_Cplus14.6

#include<stdio.h> #define FUNDLEN 50 struct fund {char bank[FUNDLEN];double bankfund;char save[FUNDLEN];double savefund; }; double

C語言實現 一個字串中提取一個子字串

例如: 編寫一個函式,它從一個字串中提取一個子字串。函式原型如下: int substr(char dst[], char src[],int start, int len) {} 目標是:從src陣列起始位置向後偏移start個字元的位置開始,最多複製len個非NULL字

iOS開發_一個帶有空格和特殊符號的字串提取數字即手機號的方法

最近做呼叫手機通訊錄,有的號碼調取之後會有空格或者“-”和“+86”等特殊符號,先把“+86”替換成“”,然後在剩下的字串使用如下方法,即可提取數字及手機號; 替換“+86”方法: truePhone = [phoneStr stringByReplacingOccurre

C++檔案轉base64字串的程式碼_網上抄了些_但我做了優化_1G資料9秒優化到了1秒

程式碼執行效率優化的幾個關鍵點: 1.使用一個編碼陣列, 解決掉編碼中的一些判斷與加減運算 //編碼表 const stati

C擴展 共享內存shm到memcache外部內存

ans quest jca com dai cheng cab hang c擴展 %E5%B8%B8%E7%94%A8%E6%95%B0%E6%8D%AE%E4%B8%8EVARIANT%E4%B9%8B%E9%97%B4%E7%9A%84%E8%BD%AC%E6%8D%A

C# 操作地址 內存中讀取寫入數據(初級)

mode .com 陽光 pen bsp api bject str ddr 本示例以植物大戰僵屍為例, 實現功能為 每1秒讓陽光刷新為 9999.本示例使用的遊戲版本為 [植物大戰僵屍2010年度版], 使用的輔助查看內存地址的工具是 CE. 由於每次啟動遊戲, 遊戲

c基礎_筆記_1

python clu std printf 定義變量 blog include num port 定義變量 int i; 也可以 int i,num; 賦值,c必須先定義變量再賦值 num = 0; 循環for for(i=1; i<=0; i++) { prin

c語言_文件操作_FILE結構體小解釋

hold 輸出 def 系統 span fopen 大小 round typedef 參考文檔來自:https://www.cnblogs.com/haore147/p/3648395.html 我們通過fopen返回一個文件指針(指向FILE結構體的指針)來進行文件操作。

iostat命令介紹及C++對其返回值的提取處理

linux 運維 C++ 1、命令介紹常用的命令為 iostat -xkx參數表示返回全部參數k參數表示返回的數據單位為kbDevice: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz a

【閱讀筆記】《C程序員 校園到職場》第二章 學校到職場

-c 是什麽 閱讀 括號 blog 能力 出現 而是 pos 一、代碼規範: 1、變量命名(讓人一眼看它是什麽意思,要做什麽操作),定義並初始化 2、函數命名規範(函數的功能)在主函數之前進行聲明。 在實際項目中,一般不在函數調用者的內部來對被調函數進行聲明,而是將聲明放在

【閱讀筆記】《C程序員 校園到職場》第三章 程序的樣式(大括號)

突出 char s 結構體 需要 初始化 detail 處理 思維 https 參考: https://blog.csdn.net/zhouzhaoxiong1227/article/details/22820533 一、.初始化數組變量 在實際的軟件開

【閱讀筆記】《C程序員 校園到職場》第六章 配置文件,makefile 文件 (Part 2)

不同 tpc 閱讀 ret ftp 理解 源代碼 exe tst Contents: 1.配置文件(通常以 ini 結尾) 2.makefile文件 (Linux) PS: 這篇文章的內容,不太理解。 一、配置文件 本文以一個實際的小軟件為例,介紹了C語言中配

C++框架_之Qt的窗口部件系統的詳解-上

同時 窗體 包含 鼠標 對象模型 種類 動態分配內存 對話框 狀態 C++框架_之Qt的窗口部件系統的詳解-上 第一部分概述 第一次建立helloworld程序時,曾看到Qt Creator提供的默認基類只有QMainWindow、QWidget和QDialog三種。是的,

程序清單2.1_first.c程序_C Primer Plus》P15

C Primer Plus// first.cpp : 定義控制臺應用程序的入口點。 // /* 時間:2018年05月29日 22:49:40 代碼:程序清單2.1_first.c程序_《C Primer Plus》P15 目的:進一步了解 printf()函數,定義變量與賦值 及