Click here to Skip to main content
15,892,643 members

Custom Version back-tracking on a each object.

tulpik asked:

Open original thread
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
C#
#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
C#
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
C#
#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
SQL
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.
Tags: C++, Linux

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900