Topic
1 reply Latest Post - ‏2012-11-01T13:04:56Z by LautaroFernandez
LautaroFernandez
LautaroFernandez
2 Posts
ACCEPTED ANSWER

Pinned topic Assigning variable with value obtained from a library value does

‏2012-09-25T19:16:59Z |
Howdy,
I'm facing some trouble with a simple testcase of a program.
The idea is that a main process (binario.cpp) assigns the value of a foreign object's instance variable, defined by a library (libreria.h), in a global variable of that process.

We have been using this mechanism for a long time in our application and for our surprise, after upgrading xlc V7 to xlcV11, the default behaviour has changed.

I have made a small test program, which shows that a simple instruction such as assigning a variable in binario.cpp does not takes the expected value.
In this scenario, the l-value is the global variable COD and the r-value is the de value of the class variable CObjeto::COD.

Our AIX version is 7.1 and our compiler version is xlc V11 (IBM XL C/C++ for AIX, V11.1 (5724-X13)).

¿Do you know any limitations in xlC v11 about accessing remote values, while assigning a global variable?
I believe this is a bug in the xlc, or the xlC's installation.
Thanks and kind regards!

Library's header (libreria.h)

#include <libreria.h> 

const std::string CObjeto::COD = 
"001";


Library's body(libreria.cpp)

#include <string> using namespace std; 

class CObjeto 
{ 

public: 

static 

const std::string COD; 
};


Main/Binary Process which calls the library (binario.cpp)

#include <iostream> #include <libreria.h> using namespace std; 

const string COD = CObjeto::COD;   

int main () 
{ cout << 
"CObjeto::COD [" <<  CObjeto::COD << 
"]" << endl; cout << 
"COD [" <<  COD << 
"]" << endl; 

return 0; 
}


Compiling rules

/usr/vacpp/bin/xlC -g -c -I./  libreria.cpp -o libreria.o /usr/vacpp/bin/xlC -G -o liblibreria.so libreria.o -lc -bdynamic -brtl /usr/vacpp/bin/xlC -g -c binario.cpp -o binario.o -I./  /usr/vacpp/bin/xlC -o binario -brtl binario.o -L. -llibreria ./binario


Actual console output

$ ./binario CObjeto::COD [001] COD [] $


EXPECTED console output

$ ./binario CObjeto::COD [001] COD [001] $
Updated on 2012-11-01T13:04:56Z at 2012-11-01T13:04:56Z by LautaroFernandez
  • LautaroFernandez
    LautaroFernandez
    2 Posts
    ACCEPTED ANSWER

    Re: Assigning variable with value obtained from a library value does

    ‏2012-11-01T13:04:56Z  in response to LautaroFernandez
    After we got some support, we were able to find the solution, it was an initialization issue.

    The successful rules of compiling are:
    /usr/vacpp/bin/xlC -g -c -I./  libreria.cpp -o libreria.o
    /usr/vacpp/bin/xlC -qmkshrobj=-100 -o liblibreria.so libreria.o -lc -bdynamic -brtl
    /usr/vacpp/bin/xlC -g -c binario.cpp -o binario.o -I./ 
    /usr/vacpp/bin/xlC -o binario -brtl binario.o -L. -llibreria
    


    The key in here is all about the " -qmkshrobj=-100" rule/flag, where we are telling the compiler that the shared library liblibreria.so must be initialized before everything.

    Hope it helps.
    Updated on 2014-03-24T22:16:23Z at 2014-03-24T22:16:23Z by iron-man