Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux
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
#include <string>
#include <time.h>
 
#define PUT_VERSION_INFO(args...) \
    asm("  .section .build_info, \"d\"\n"); \
    static const struct core::Version_t::build_info_t build_info = {__FILE__, __DATE__, __TIME__, ## args}; \
    asm("  .data\n")
 
#define GET_VERSIONS() \
    static const struct core::Version_t::build_info_t* _build_info = (struct core::Version_t::build_info_t*) &build_info
    
namespace core {
    class Version_t {
        private:
            time_t  m_buildtime;
            int     m_buildNumber;
        public:
            struct build_info_t {
                char*   m_filename;
                std::string m_date;
                std::string m_time;
                std::string m_author;
                std::string m_change;
            };
            Version_t();
            std::string getBuildTime();
            int getBuildNumber();
            virtual ~Version_t();
    };
};
 
version.cc
namespace core {
    Version_t::Version_t() { };
    std::string Version_t::getBuildTime() {
        return "xxx  ";
    };
    int Version_t::getBuildNumber() {
        return 0;
    };
    Version_t::~Version_t() { };
    asm("  .section .build_info, \"d\"\n");
    static const struct Version_t::build_info_t build_info = {__FILE__, __DATE__, "", "", ""};
    asm("  .data\n");
};
 
main.cc
#include <iostream>
#include "version.h"
//namespace core {
    asm("  .section .build_info, \"d\"\n");
    static const struct core::Version_t::build_info_t build_info = {__FILE__, __DATE__, "", "", ""};
    asm("  .data\n");
//};
int main() {
    core::Version_t v;
    //extern const char           __build_info;
    //namespace core {
    //struct core::Version_t::build_info_t* bstruct = (struct core::Version_t::build_info_t*) &build_info;
    //asm("  .section .build_info, \"d\"\n");
    struct core::Version_t::build_info_t* bstruct = (struct core::Version_t::build_info_t*) &build_info;
    //asm("  .data\n");
    //struct Version_t::build_info_t  binfo;// = (struct Version_t::build_info_t*) &__build_info;
    //};
    while(bstruct->m_filename) {
        std::cout << bstruct->m_filename << std::endl;
        bstruct++;
    };
    return 0;
};
 
Makefile
BINARY_name = libpagi
OBJFILES := $(patsubst %.cc,%.o,$(wildcard *.cc))
.PHONY: all
all: $(BINARY_name)
$(BINARY_name): $(OBJFILES)
    $(CXX) -g -Wall -o $(BINARY_name) $(LIBRARY_DIR) $(INCLUDE_DIR) $(LIBS) $(OBJFILES)
    @echo "Project '$(BINARY_name)' builded!"
%.o: %.cc
    $(shell git log $(shell basename $@ .o).cc | cut -d' ' -f 2 | tr -s [:space:] | sed -e '{:q;N;s/\n/", "/g;t q};' > temp)
#@sed -i "s/PUT_VERSION_INFO([^;]*;/PUT_VERSION_INFO(\"`cat temp`\");/gi" $(shell basename $@ .o).cc
    @echo "Build new version of module: $@ -> $(shell cat temp)."
    @rm temp
    $(CXX) -Wall -c -o $@ $<
clean:
    rm $(BINARY_name)* *.o
 
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.
Posted 20-Feb-11 22:10pm
tulpik290
Edited 20-Feb-11 23:55pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 450
1 OriginalGriff 403
2 CPallini 189
3 Sergey Alexandrovich Kryukov 189
4 CHill60 180
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,958
2 Maciej Los 3,269
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 21 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100