codeblocks cbp 转 makefile 您所在的位置:网站首页 makefile编译c文件压缩 codeblocks cbp 转 makefile

codeblocks cbp 转 makefile

2024-06-08 00:39| 来源: 网络整理| 查看: 265

codeblocks是一个跨平台的C/C++的IDE,页面简单好用,在写C/C++工程的时候其才采用自有的工程文件(.cbp)来组织相关源码,但是有时候需要在Linux环境下运行,需要把编译工程转成makefile,codeblocks有一个自动将cbp工程文件转换为makefile的工具---cbp2make,下面我介绍如何使用cbp2make

1,下载工具:

https://sourceforge.net/projects/cbp2make/

2,解压工具,并把

cbp2makefile\cbp2make-stl-rev147-all\bin\cbp2make.linux 放到Linux环境下,更改权限和可执行属性(chomd +x),比如更改为

cbp2make,放到执行目录或环境变量目录下 /usr/local/bin

3,执行转换命令

     cbp2make -in test.cbp -out makefile (单独)

工程make file:

generate makefile for CodeBlocks core: $ cbp2mak -C cb/src CodeBlocks.cbp generate makefile for CodeBlocks contrib: $ cbp2mak -C cb/src ContribPlugins.workspace

build: $ make -C cb/src -f CodeBlocks.cbp.mak $ make -C cb/src -f ContribPlugins.workspace.mak

 

如果需要更改编译,需要编译的,方法如下:

首先下载cbp2make,下载的包后缀名是.tar.gz。Linux里双击该下载文件,解压缩。解压缩之后里面的有cbp2make.cbp,在codeblock中打开它,然后编译build。

Linux环境下的马克file

1,生成默认配置:C:\Users\gchen\.cbp2make\cbp2make.cfg

需要手动生成C:\Users\gchen\.cbp2make目录,win32 无法生成,需要Linux 命令生成(目前不知道怎么配置该路径)

cbp2make  --config  (默认目录)

cbp2make --local --config      (cbp2make.cfg 在当前目录)

2,配置cbp toolchain 的“testcompiler” config

          ***************                                                *************************                                  

配置增加testcompiler,

cbp2make --local --config toolchain --add -unix -chain testcompiler

cbp2make --local --config tool --add -unix -chain testcompiler -tool tool (参数太多,建议复制一个默认的进行配置)

                                                                                                                                                                                                                                                                                                                               

2,自动生成makefile

cbp2make -in test.cbp -unix  -cfg cbp2make.cfg -out testMakefile(单个cbp)

cbp2make.exe -in test.workspace -unix -cfg cbp2make.cfg -out test/Makefile(多个cbp工程)

3,自动获取cbp或Makefile(.mak)的宏,并进行自动匹配

CFLAGS_CUSTOM=$(./getdefine test.cbp.mak "-D" " ") 或者

CFLAGS_CUSTOM=$(./getdefine ./define.cbp "-D" "\"")

#FLAGS_WARNING="-Wextra -Wformat=2 -Wstrict-aliasing=2 -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith -Wcast-qual -Winline -Wundef -Wunreachable-code -Wredundant-decls -Waggregate-return"

LAGS_WARNING=""

CFLAGS_BASE=" -EL -msoft-float -Os -g -fno-omit-frame-pointer -rdynamic -funwind-tables -fstack-protector-all -ffunction-sections -fdata-sections -Wall ${FLAGS_WARNING} ${CFLAGS_CUSTOM}  -MMD -MP -MF \$\@.d -MT \$\@.d"

sed -i "s|^CFLAGS_RELEASE = .*|CFLAGS_RELEASE = ${CFLAGS_BASE}|" `find . -name "*.mak"`

getdefine源码如下:

#include "string.h" #include "stdlib.h" #include "stdio.h" #define MAX_LINE_CHAR_NUM 1024 int main(int argc,char**argv) { FILE *p_fhead = NULL; char *p_fileName = NULL; char *p_headStr = NULL; char *p_endStr = NULL; char strBuf[MAX_LINE_CHAR_NUM] = {0}; unsigned int strLen = 0; char *p_str = NULL; char *p_head = NULL; char *p_end = NULL; char strFind[MAX_LINE_CHAR_NUM] = {0}; if(argc < 4) { return -1; } p_fileName = argv[1]; p_headStr = argv[2]; p_endStr = argv[3]; //printf("define file:%s\n",p_fileName); //printf("head:%s\n",p_headStr); //printf("endStr:%s\n",p_endStr); p_fhead = fopen(p_fileName,"r+"); if(p_fhead == NULL) { return -1; } memset(strBuf,0,MAX_LINE_CHAR_NUM); while(fgets(strBuf,MAX_LINE_CHAR_NUM,p_fhead) != NULL) { //printf("str:%s\n",strBuf); strLen = strlen(strBuf); #if 0 if(strBuf[strLen -1] == '\n') { } #endif p_str = strBuf; p_head = NULL; p_end = NULL; while(*p_str != '\0') { if(0 == strncmp(p_str,p_headStr,strlen(p_headStr))) { /****it is defind head****/ //printf("it is define head:%s\n",p_str); p_head = p_str; p_end = NULL; p_str += strlen(p_headStr); continue; } if((0 == strncmp(p_str,p_endStr,strlen(p_endStr))) // if((0 == strncmp(p_str," ",strlen(" "))) && (p_head != NULL)) { //printf("it is define end:%s\n",p_str); p_end = p_str; memset(strFind,0,MAX_LINE_CHAR_NUM); strLen = p_end - p_head; strncpy(strFind,p_head,strLen); printf("%s ",strFind); p_head = NULL; p_end = NULL; p_str += strlen(p_endStr); continue; } p_str ++; } memset(strBuf,0,MAX_LINE_CHAR_NUM); } fclose(p_fhead); return 0; }

 

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有