C++ :: Embedding Version Strings At Build Time
Dec 11, 2013
I have a set of projects. Each one builds either a static library or an executable. What I'd like to do, is at build time I want to embed a version string representing the version of the executable as well as the version of each library. These version strings will come from an external source (in my case it's based on a "git describe" call, but that's beside the point). Embedding such strings can be highly valuable for traceability. (Versions of 3rd-party libraries are not necessary.)
I'm using qmake as my build system, but this should work more or less similarly with any build tool. What I'd ideally like to do is define this process in such a self-contained way that a an absolutely minimal amount of additional code is required in order to leverage it. Preferably, nothing more than an include(version.pri) in each project's .pro file in order to collect the versions. (Retrieving them later, such as to respond to a --version command-line flag, can be done via traditional C++ methods.)
What I've done so far is to define a singleton VersionTracker class, and then tweak the build system so that "MODULE" and "VERSION" are preprocessor symbols defined at build time. I've also tweaked the build system so that a file in each project, version.cpp, is rebuilt (and regenerated if necessary) on every build regardless of changes. This source file can capture the information in the preprocessor symbols into each static library and the executable.
Now, here's the problem. How can I get the information from those version.cpp files into the VersionTracker class? I thought I could use a global object's constructor to do it, but it turns out the symbols are stripped out when the static libraries are linked so I only get the executable's version. I also found a page on stackoverflow detailing a very clever way to call a registration function at class definition time, but again the class definition appears to be stripped out if it's defined in the version.cpp file of a static library and not referenced elsewhere.
Everything I've read basically says you either need to use linker flags to prevent symbol stripping entirely, which is probably an adoption-killer for this hack, or you need to use an explicit registration function called from the executable. I'd prefer to avoid this since it is just another thing a programmer could forget to update when a library dependency is added or removed.
My last idea, which I haven't tried yet, would be to put each version.cpp into a separate static library from the one it is describing. This version-only library could be linked without symbol stripping. I don't love this concept but it might work.
I haven't yet figured out how shared libraries can be worked into this framework at all. I'll worry about that after I get static libraries working.
View 5 Replies
ADVERTISEMENT
Feb 4, 2013
The function should search the array of strings to find how many times the word 'the' was used. but its only returning a 0.
int FindThe (int The, char Paragraph[], char Pattern[]) {
for (int i(0); i < 500; i++) {
if (Paragraph[i] == Pattern[0] {
[Code] ....
View 5 Replies
View Related
Dec 27, 2012
I'm trying to calculate a series of times from start to end, and find out the duration between them, sum them up and see if they're above a certain value or not, for each particular instance.
My goal is to provide a prepared text file with time tags such as this:
Mon 19-Nov-2012 09:12 Mon 19-Nov-2012 09:34
Wed 21-Nov-2012 13:14Wed 21-Nov-2012 17:11
Fri 07-Dec-2012 15:21Fri 07-Dec-2012 15:26
=============================================
Mon 26-Nov-2012 12:50Tue 27-Nov-2012 15:29
Wed 12-Dec-2012 13:07Wed 12-Dec-2012 14:58
Fri 14-Dec-2012 14:22Fri 14-Dec-2012 14:29
And the program is able to calculate the total time relevant to each instance (instances separated by a line of '=').
Some form of number should somehow identify each instance or something similar and a text file is generated with total time printed for each instance. E.g.
Instance 1: 00h22m + 03h57m + 00h05m = 04h24m
Instance 2: 04h15m + 07h44m + 01h51m + 00h07m = 14h04m
Now I'm currently working on making the logic to calculate time within the ranges I'd like based on several parameters.
Are there any references I can use when it comes to working with strings in order to seek and extract these values in order to work with them? The documentation available on this website, despite being very informative, does not show practical applications of said class and I'm at a loss on how to implement the functionality.
View 17 Replies
View Related
Oct 28, 2013
Just wondering about how to write extremely simple version of 'find' in C: It just lists the path names of the files in the specified directories and all subdirectories.For example,
Code:
$find_version .
./foo
./bar
./baz
./baz/other
[Code]....
View 6 Replies
View Related
Jul 18, 2013
Is there any code I can use to determine my compiler version and which Standard It uses? I know the following code determine that my compiler followed ANSI But how about a version of that? ****My OS is now Ubuntu
Code:
#include <stdio.h>
int main(void){
printf("File :%s
", __FILE__ );
printf("ANSI :%d
", __STDC__ ); //return 1 if it follow ANSI but version?
return 0;
}
View 3 Replies
View Related
Feb 24, 2015
I am/we developing in C and we have a number of different programs. We also have problem to keep track of different versions of a specific exe file.
Is there any way to add version number when build a file so the version is added in the properties.
I doing this in a MFC c++ project in a .rc file. Is there a way (or a similar way) of doing this in C? Here its stored in the details section with product version 6.0.8:
View 6 Replies
View Related
Apr 15, 2014
Just wondering if there was a standard way people add a version number to their c++ code? I can just define a variable or #define and write the version number to that, but wanted to know if there is a standard method people use?
View 1 Replies
View Related
Jan 18, 2013
im trying to make a tool that can change the version of the file (.exe)
UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPVOID) lpBytes, dwSize);
i know how to update the rcdata of the resource
my problem is i dont know what to insert to it using (LPVOID) lpBytes is it a .txt ? .rc ? is it a binary ? etc.
View 1 Replies
View Related
Sep 16, 2013
When you are creating a project or program, how do you number your versions?
Like when you release it, it becomes v1.0, am i right?
then every release or build after that might become v1.1 or v1.0001 or v1.0.1.2
Is there a certain global system for how you Number your versions or is it just up to the developer?
View 1 Replies
View Related
Mar 6, 2013
I have been trying to compile a static version of the boost libraries, however when I try to launch the program it says fatal error LNK1104: cannot open file 'libboost_serialization-vc100-mt-s-1_53.lib'
I have checked in the boost/stage/lib folder and that file is not there. I compiled boost with b2 link=static yet the file still isn't there.
View 3 Replies
View Related
Feb 26, 2014
I am using borland turbo c++ version 4.5 and for printing a coloured output i used textcolor() but it is showing error that call the undefined function 'textcolor' in main, so what can i do now to print a coloured output???
View 1 Replies
View Related
May 19, 2013
I have a problem to implement a recursive version of an algorithm that I made, I get different values. Here is the code so Iterative (OK) and Recursive code form that is not OK.
The data sets do not give equal:
The algorithm is given two source and target positions on a board, find the number of paths between them...
Input Example: 5
2 3
4 4
Output Example: 5
Iterative Algorithm ( OK )
Code:
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
using namespace std;
int n , dp [1000][1000], x, y, xx, yy;
[Code] ....
View 2 Replies
View Related
Nov 19, 2014
Is there a way I can extract Machine / Hardware ID and OS Version using VC++?
View 3 Replies
View Related
Jan 15, 2013
Later i used trial version of vc2010 and created a static library using the below link. Its worked. [URL] .....
But now I'm using VC2003.Details as follows,
Microsoft Development enviroinment 2003 Version 7.1.3088
CopyRight @ 1987-2002 Microsoft Corporation. All Rights Reserved.
Microsoft .Net Framework 1.1 Version 1.1.4322
CopyRight @ 1998-2002 Microsoft Corporation. All Rights Reserved.
I used the same procedure & created the Static lib. But couldn't use this lib file in my main project.B'cos the project's property window doesn't have the :
Common Properties -> Framework & References
Couldn't find. Here with i attached missed property in VC2003. How can i set this property? Is any other way to use static lib in main project (application)?
View 4 Replies
View Related
Oct 9, 2014
I have a version.txt file and it looks like
Script=01
build date=yy.mm.dd
Mainversion=1.00.00.00:01
need a batch script or C# code increment the version if i trigger a build and expected output as
Script=02
build date=yy.mm.dd (Current date)
Mainversion=1.00.00.00:02
View 1 Replies
View Related
Nov 29, 2012
I tried to do this with _spawnl(), but first of all I'm not sure how to properly ask for the path to iexplore.exe, as I'm sure it will change every time MS gets a whim to move it. I know there's a GetWindowsDirectory() call, but that's not where IE resides (its in "C:Program FilesInternet Exploreriexplore.exe" in XP, Lord know where on win 7 or 8).
Also, even temporarily hard coding the path to make it launch with spawnl(), I can't seem to get my html document to display. I know the path to that is right (since I put it there ).
char * pFile = "someFile.htm";
char * pCmd = "C:Program FilesInternet Exploreriexplore.exe";
int res = _spawnl(_P_NOWAIT, pCmd,pCmd, pFile, NULL); // also tried without specifying pCmd 2x
if (res == -1) MessageBox("Can't Open File.");
So my second question would be, how to you PROPERLY pass the file to view as an argument.
View 7 Replies
View Related
Mar 10, 2015
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
[Code] ....
View 2 Replies
View Related
Feb 7, 2014
I'm trying to write a custom allocator that I can use with the STL. Here's what I have so far :
Code:
#include <cstddef>
#include <iostream>
#include <memory>
#include <vector>
template<class T>
struct customallocator {
[Code].....
I'm doing and currently, my push_back doesn't seem to do anything.
View 12 Replies
View Related
Sep 11, 2014
How to build the static library on my own using visual C++ 2008.
I used the following code to create the header file and cpp of the library.but I am unable to compile due to the following error.
// MathFuncsLib.h
namespace MathFuncs {
class MyMathFuncs {
public:
// Returns a + b
static double Add(double a, double b);
[Code] .....
Error I get while it is compiled :
Error3error C2653: 'MyMathFuncs' : is not a class or namespace name
View 4 Replies
View Related
Sep 28, 2013
class test {
private:
string name="";
public:
event void changedname();
void setname(string value)
[code]....
i get error about 'a' and 'b' not be a class. but using a template can i validate these code?
my problem is that i don't know how to use objects outside of functions / these is polymorphism, but not accepted by C++
View 12 Replies
View Related
Apr 6, 2014
I need to build an array in a function and return that array. Well, two arrays actually, which means I can't return it in the return statement.
Long term, this function/method is supposed to return two populated buffers for further processing. The buffers/arrays are loaded from a file. So, the size of the array is completely unknown until after the file is read. So, you can't have a fixed size array until the function is almost ready to return.
I'm hardcoding the arrays here for testing purposes, but eventually they will be loaded in from a file. That's the whole purpose of this.
Anyway, I need to pass the arrays that are created in this function/method to the caller. But I can't figure out how to do it. The code "almost" works, except that it's overwriting my array when it returns.
Here's the method:
bool GameModelClass::LoadBuffersFromPUNCFile(std::wstring PUNCFileName, VERTEX* &VertexListPointer, unsigned int* &IndexListPointer) {
VERTEX GroundVertexList[4] = {
[Code]....
VertexListPointer returns the correct data structure (actually its an array of structures). The problem is that the first time I use the other variables it over rights the array. The pointer still points to the same spot, but VertexBufferDescription is next to the VertexListPointer and so completely overwrites it.
What I "think" I want is to allocate the array in a totally different area of memory. VertexListPointer should be a pointer, not a contiguous block of memory. It should point to the contiguous block of memory elsewhere.
This is where my weak understanding of pointers comes back to bite me in the posterior end.
In the end, I just want to pass back two arrays/buffers to be used by the calling code.
View 14 Replies
View Related
Dec 29, 2013
I am not sure how to build the tree with values:
Code:
struct Node *root = 1 root->left = 2
root->right = 3
root->left->left = 4;
root->left->right = 5;
Everything should be right except the main(). How to demonstrate this program correctly?
Code:
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include <stack> // std::stack
[Code] .....
View 8 Replies
View Related
Jul 10, 2013
10,11,20,1512,22,24,19,22
i want to write a c++ program to build min heap which gets above values from user. remember this program should not alloduplicate values to enter. it should discard duplicate values.
View 11 Replies
View Related
Jul 18, 2013
i have four email adresses (for various reasons) and i could probably find a client for all three on source forge, but i thought it would be good practice to use my own. i want to use boost, sdl, and c++, but i cant find a tutorial.
View 2 Replies
View Related
Sep 27, 2013
I have lot of C++ API exposed in our project and I want to build an application that queries the database and shows some stuff to the user in the UI.
So, essentially, my main code is in the c++ language. What choices do I have over the UI?. I am interested in showing this UI in the form of a html page lilstening to a port.
View 1 Replies
View Related
Jul 1, 2014
Build a class named "salesCompany". Save it's name with a string and an array with records which will be filled with values from sales in different cities of the company.
Build the constructor which must get as a parameter the name of the company and a text file which will fill the array. There is an example of the text file format. Every line saves the sold quantity of a product, identified by a code, in a certain city.
CodeCityQuantity
1a63bCity11200
45ab8City2550
#include <iostream>
#include <string.h>
using namespace std;
class salesCompany {
[code].....
what should I add more and how can make it available for the user to enter as an input a text file.
View 1 Replies
View Related