VisualGDB Makefiles

以下内容是VisualGDB官网对VisualGDB编译时获取相关编译信息的说明:

When you create a new project using VisualGDB, it will generate a Makefile for you. More specifically, it will generate 2 files: Makefile and flags.mak

Overview

  • When you add new files to the project, VisualGDB will update the Makefile automatically
  • If you want to change the GCC/LD flags, edit the flags.mak file
  • If you want to add more configurations or targets, modify the Makefile.
  • If you don't want VisualGDB to touch the Makefile, remove the following line:
    #VisualGDB: AutoSourceFiles

Detailed description

The Makefile contains basic targets (such as all and clean) and generally has the following structure:

#VisualGDB: AutoSourceFiles
SOURCEFILES := file1.cpp file2.cpp
TARGETNAME := MyExeName
include flags.mak

ifeq ($(CONFIG),DEBUG)
    ...
endif

...

$(BINARYDIR)/%.o : %.cpp $(BINARYDIR)
    $(CXX) $(CFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)

$(BINARYDIR)/%.o : %.c $(BINARYDIR)
    $(CC) $(CXXFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)

The SOURCEFILES line lists all source files used in the project. VisualGDB will automatically update this line when you add new files to the project. The "%.cpp" and "%.c" lines define generic rules to build .o files from the C/C++ source files.

The flags.mak defines GCC flags (such as optimization level) that are used by Makefile. Its typical structure looks the following way:

CC := /usr/bin/gcc
CXX := /usr/bin/g++
LD := /usr/bin/g++

...

CFLAGS := -ggdb -ffunction-sections
DEBUG_CFLAGS := -O0
RELEASE_CFLAGS := -O3

The following table summarizes all variables defined in flags.mak:

VariableMeaningExample
CCLocation of the GCC compilerc:/gcc/gcc.exe
CXXLocation of the C++ compilerc:/gcc/g++.exe
LDLocation of the linker (typically GCC/G++ is used for linking)c:/gcc/g++.exe
COMMON_MACROSPreprocessor definitions to be defined in all configurations._WIN32 _CONSOLE
DEBUG_MACROSPreprocessor definitions to be defined in DEBUG configuration only_DEBUG DEBUG
RELEASE_MACROSPreprocessor definitions to be defined in RELEASE configuration only_NDEBUG _RELEASE
MCUFLAGSAdditional flags specifying microcontroller type-mmcu=msp430f2013
INCLUDE_DIRSAdditional include directories relative to the project location../lib1 ../lib2
LIBRARY_DIRSAdditional library directories../lib1/bin ../lib2/bin
LIBRARY_NAMESAdditional libraries to link with (no "lib" prefix)1 2
CFLAGSAdditional GCC flags for all configurations-ggdb -ffunction-sections
DEBUG_CFLAGSAdditional GCC flags for DEBUG configuration-O0
RELEASE_CFLAGSAdditional GCC flags for RELEASE configuration-O3
CXXFLAGSAdditional C++ flags for all configurations-fno-exceptions
DEBUG_CXXFLAGSAdditional C++ flags for DEBUG configuration 
RELEASE_CXXFLAGSAdditional C++ flags for RELEASE configuration 
MACOS_FRAMEWORKSAdditional framework names (MacOS only)iokit
LDFLAGSAdditional flags to the linker (with -Wl, prefix when GCC is used for linking) 
DEBUG_LDFLAGSAdditional linker flags for DEBUG configuration 
RELEASE_LDFLAGSAdditional linker flags for RELEASE configuration 
START_GROUPEither an empty string, or "-Wl,--start-group" 
END_GROUPEither an empty string, or "-Wl,--end-group" 


The START_GROUP/END_GROUP flags surround the library/object file list and allow specifying them in an arbitrary order (otherwise the object file list has to be sorted manually). You can set those variables to empty strings if your linker (e.g. MacOS linker) does not require those flags.

对上面的内容可以理解为为:Debug模式下,完整的make执行需要Makefile和debug.mak两个文件;Release模式下则需要Makefile和release.mak两个文件

如果需要导出VisualGDB的Makefile文件,只需要合并相应的两个文件即可。将.mak文件的内容放到Makefile文件内容的前面,所得到的Makefile文件即可进行编译。

转载于:https://www.cnblogs.com/young525/p/6305649.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值