每个对象上的自定义版本回溯. [英] Custom Version back-tracking on a each object.
问题描述
您好,我不理解该帖子 http: //www.linuxjournal.com/content/add-auto-incrementing-build-number-your-build-process#comment-356616 [
Hi, im not understand this post http://www.linuxjournal.com/content/add-auto-incrementing-build-number-your-build-process#comment-356616[^].
I try to implement some object version status such as git info (last commit and author), build time, date and number.
I dont have any skill in assembler, but this does not work fine.
Can you anyone say me how this work at program level?
Why assembler say warnings like:
/tmp/cccGQytx.s: Assembler messages:
/tmp/cccGQytx.s:3: Warning: entity size for SHF_MERGE not specified
/tmp/cccGQytx.s:3: Warning: group name for SHF_GROUP not specified
version.h
version.h
<pre lang="cs">#include <string><br />
#include <time.h><br />
<br />
#define PUT_VERSION_INFO(args...) \<br />
asm(" .section .build_info, \"d\"\n"); \<br />
static const struct core::Version_t::build_info_t build_info = {__FILE__, __DATE__, __TIME__, ## args}; \<br />
asm(" .data\n")<br />
<br />
#define GET_VERSIONS() \<br />
static const struct core::Version_t::build_info_t* _build_info = (struct core::Version_t::build_info_t*) &build_info<br />
<br />
namespace core {<br />
class Version_t {<br />
private:<br />
time_t m_buildtime;<br />
int m_buildNumber;<br />
public:<br />
struct build_info_t {<br />
char* m_filename;<br />
std::string m_date;<br />
std::string m_time;<br />
std::string m_author;<br />
std::string m_change;<br />
};<br />
Version_t();<br />
std::string getBuildTime();<br />
int getBuildNumber();<br />
virtual ~Version_t();<br />
};<br />
};</pre><br />
version.cc
version.cc
<pre lang="cs">namespace core {<br />
Version_t::Version_t() { };<br />
std::string Version_t::getBuildTime() {<br />
return "xxx ";<br />
};<br />
int Version_t::getBuildNumber() {<br />
return 0;<br />
};<br />
Version_t::~Version_t() { };<br />
asm(" .section .build_info, \"d\"\n");<br />
static const struct Version_t::build_info_t build_info = {__FILE__, __DATE__, "", "", ""};<br />
asm(" .data\n");<br />
};</pre><br />
<br />
main.cc
main.cc
<pre lang="cs">#include <iostream><br />
#include "version.h"<br />
//namespace core {<br />
asm(" .section .build_info, \"d\"\n");<br />
static const struct core::Version_t::build_info_t build_info = {__FILE__, __DATE__, "", "", ""};<br />
asm(" .data\n");<br />
//};<br />
int main() {<br />
core::Version_t v;<br />
//extern const char __build_info;<br />
//namespace core {<br />
//struct core::Version_t::build_info_t* bstruct = (struct core::Version_t::build_info_t*) &build_info;<br />
//asm(" .section .build_info, \"d\"\n");<br />
struct core::Version_t::build_info_t* bstruct = (struct core::Version_t::build_info_t*) &build_info;<br />
//asm(" .data\n");<br />
//struct Version_t::build_info_t binfo;// = (struct Version_t::build_info_t*) &__build_info;<br />
//};<br />
while(bstruct->m_filename) {<br />
std::cout << bstruct->m_filename << std::endl;<br />
bstruct++;<br />
};<br />
return 0;<br />
};</pre><br />
<br />
生成文件
Makefile
<pre lang="sql">BINARY_name = libpagi<br />
OBJFILES := $(patsubst %.cc,%.o,$(wildcard *.cc))<br />
.PHONY: all<br />
all: $(BINARY_name)<br />
$(BINARY_name): $(OBJFILES)<br />
$(CXX) -g -Wall -o $(BINARY_name) $(LIBRARY_DIR) $(INCLUDE_DIR) $(LIBS) $(OBJFILES)<br />
@echo "Project ''$(BINARY_name)'' builded!"<br />
%.o: %.cc<br />
$(shell git log $(shell basename $@ .o).cc | cut -d'' '' -f 2 | tr -s [:space:] | sed -e ''{:q;N;s/\n/", "/g;t q};'' > temp)<br />
#@sed -i "s/PUT_VERSION_INFO([^;]*;/PUT_VERSION_INFO(\"`cat temp`\");/gi" $(shell basename $@ .o).cc<br />
@echo "Build new version of module: $@ -> $(shell cat temp)."<br />
@rm temp<br />
$(CXX) -Wall -c -o $@ $<<br />
clean:<br />
rm $(BINARY_name)* *.o</pre><br />
编译输出:
Compilation output:
Build new version of module: main.o -> 1f671ad6311f89860947f0b0b42aee5444b468d9, gimper.
g++ -Wall -c -o main.o main.cc
main.cc:7: warning: deprecated conversion from string constant to ‘char*’
main.cc: In function ‘int main()’:
main.cc:13: warning: unused variable ‘__build_info’
/tmp/ccVnldjr.s: Assembler messages:
/tmp/ccVnldjr.s:5: Warning: entity size for SHF_MERGE not specified
/tmp/ccVnldjr.s:5: Warning: group name for SHF_GROUP not specified
as: main.o: warning: sh_link not set for section `.build_info''
Build new version of module: version.o -> 1f671ad6311f89860947f0b0b42aee5444b468d9, gimper.
g++ -Wall -c -o version.o version.cc
version.cc:6: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccN7FXjD.s: Assembler messages:
/tmp/ccN7FXjD.s:3: Warning: entity size for SHF_MERGE not specified
/tmp/ccN7FXjD.s:3: Warning: group name for SHF_GROUP not specified
as: version.o: warning: sh_link not set for section `.build_info''
g++ -g -Wall -o libpagi main.o version.o
/usr/bin/ld: main.o: warning: sh_link not set for section `.build_info''
/usr/bin/ld: version.o: warning: sh_link not set for section `.build_info''
Project ''libpagi'' builded!
程序输出:
Program output:
main.cc
Neoprávněný přístup do paměti (SIGSEGV)
代码不完整,宏丢失.
有人可以帮我吗?
非常感谢.
Code isnt complete, macros lost.
Can anybody help me with this?
Thanx a lot.
推荐答案
(部分%.cc,%.o,
(patsubst %.cc,%.o,
(通配符* .cc))< ; br/> .PHONY:全部< br/> 全部:
(wildcard *.cc))<br /> .PHONY: all<br /> all:
(BINARY_name)< br/>
(BINARY_name)<br />
这篇关于每个对象上的自定义版本回溯.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!