The problem I am having is a little hard to explain, but I will try to put it in a simple way (I have no more ideas on how to solve it).
Well, basically, we have a very big C++ project on linux. This project was compiled with makefiles, but in the new version we are migrating it to CMake.
The CMake version is compiling fine, but the behavior when loading a library is a little different.
Here is the scenario: I have a folder with the following files:
/appserver/appserver_cmake (the binary compiled using cmake)
/appserver/appserver_original (the binary compiled using the makefiles)
/appserver/dbsrv.so (the library the program is trying to load)
There is a class called “tTOPClient”, which is compiled inside the executable and inside the library. The idea is: if the library exists, the program should execute the functions inside the library. Otherwise, it should execute its own function.
Here is the stack when executing the appserver_original:
bAdvplConn=0 '\000') at ../fatclient/clientconn.cpp:260
#1 0xb6396fe2 in tTOPClient::m4GLConnect (this=0x2075d858, server=0x2075e3d4 "(local)", environment=0x2075e404 "ORACLE",
user=0x203c6731 "user") at ../fatclient/clientconn.cpp:255
#2 0xb63a0f1d in v40TC_m4GLConnect (who=0x2075d858, toServer=0x2075e3d4 "(local)", init_prm=0x2075e404 "@!!@ORACLE/ora10g_v1002t", usr=0x203c6731 "user")
at ../fatclient/topapi40.cpp:63
#3 0x0866e49c in tTopDriver::APTC_Connect (this=0x2075e4d0, who=0x2075d858, toServer=0x2075e3d4 "(local)", conn_str=0x2075e404 "ORACLE",
usrname=0x203c6731 "user", nSeed=-1230926992) at ./lib/top.cpp:3718
#4 0x0866d0eb in tTopDriver::Connect (this=0x2075e4d0) at ./lib/top.cpp:3314
In summary, the sequence of calls:
tTopDriver::Connect (inside the executable)
tTopDriver::APTC_Connect (inside the executable, will call a library's function)
v40TC_m4GLConnect (inside the library)
tTOPClient::m4GLConnect (inside the library)
When I run the “appserver_cmake”, the “APTC_Connect” is calling the library’s “v40TC_m4GLConnect”, but this function is called the “tTOPClient::m4GLConnect” that is inside the executable, and not the one inside itself.
Here is the stack:
bAdvplConn=0 '\000') at /home/user/adv/trunk/topconnect/4.0/client/clientconn.cpp:207
#1 0x08abe8d2 in tTOPClient::m4GLConnect (this=0x20a1d528, server=0x20a1d78c "(local)", environment=0x20a1ffcc "ORACLE",
user=0x20600c69 "user") at /home/user/adv/trunk/topconnect/4.0/client/clientconn.cpp:202
#2 0xae1a0f1d in v40TC_m4GLConnect (who=0x20a1d528, toServer=0x20a1d78c "(local)", init_prm=0x20a1ffcc "ORACLE", usr=0x20600c69 "user")
at ../fatclient/topapi40.cpp:63
#3 0x08982730 in tTopDriver::APTC_Connect (this=0x209f0780, who=0x20a1d528, toServer=0x20a1d78c "(local)", conn_str=0x20a1ffcc "ORACLE",
usrname=0x20600c69 "user", nSeed=-1335784592) at /home/user/adv/trunk/lib/top.cpp:3718
#4 0x0898137f in tTopDriver::Connect (this=0x209f0780) at /home/user/adv/trunk/lib/top.cpp:3314
In summary:
tTopDriver::Connect (inside the executable)
tTopDriver::APTC_Connect (inside the executable, will call a library's function)
v40TC_m4GLConnect (inside the library)
tTOPClient::m4GLConnect (inside the executable!!!)
Do someone know what could be causing this different behavior? The makefiles and the CMakeLists are too big to post here, but I’ve compared them and they seem to be similar. I’ve tried to make a small example, but I couldn’t reproduce the problem.
I would also suspect different flags being passed to compiler or linker. I would compile everything, then touch only one cpp file and compile the cmake build like this:
VERBOSE=1 make -j1 > log-cmake.txt
The VERBOSE=1 leads to make showing the parameters which are passed to gcc. Then compile with your old makefile
make -f Makefile.old > log-oldmakefile.txt
When you find flags which are different between the two compiler / linker invocations look at these cmake variables:
information about the meaning of the variables is in the cmake wiki