Operating System - HP-UX
1752346 Members
5663 Online
108787 Solutions
New Discussion

Linking issues while compiling a simple c++ module in HP-UX

 
Biswadeep
Advisor

Re: Runtime unsats with a simple aC++ shlib on HP-UX

Thanks for all the help provided by you.

 

It was really helpful.

 

I was  able to build the webservice in C++ and generate the "calc.so" using the below steps and load it in apache server successfully and now facing some issue while calling it through the client.

 

aCC +DD64 -c -AA +z calculator.cpp----(1)

aCC +DD64 -b -o calc.so  calculator.o -lstd_v2 -lCsup -lunwind -lm------(2)

 

We are using another shared library as a load module(example-abc.so) and that library is written in C.which is getting linked with the webservice shared library generated by us through (2) i.e calc.so (in C++ as described above) at run time.

 

The same webservice("calc.so") written and generated  in C   gets linked with the  load module shared library(abc.so) is successfully deployed and tested using client.

 

can someone help me how to resolve this issue.

Dennis Handly
Acclaimed Contributor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

>We are using another load module (abc.so) which is getting linked with ... calc.so at run time.

 

You are loading abc.so fron calc.so?

What's the error you're getting?  What doesn't work?

Biswadeep
Advisor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

Hi

 

I am building a  C++  webservice using a C++ webservice toolkit called gSOAP.

 

For this, we have to build two shared libraries -

1. Shared library for our actual webservice (e.g. calculator.so) which is loaded into Apache server.  I generated  the "calculator.so" using the below steps and load it in apache server successfully.

 

aCC +DD64 -c -AA +z calculator.cpp  soapC.cpp soapcalcService.cpp stdsoap2.cpp

aCC +DD64 -b -o calculator.so  calculator.o soapC.o soapcalcService.o stdsoap2.o -lstd_v2 -lCsup -lunwind -lm

 

2. Shared library for a Apache module provided by the gSOAP toolkit called mod_gsoap.so. We need to build this shared library uisng the code (mod_gsoap.c written in pure C language) provided in the toolkit. mod_gsopa.so  is generated using the following command (where apxs is a "C binary" of apache server)

 

apxs -a -i -c  mod_gsoap.c

 

 

After building the the above two modules, we loaded the modules in Apache server.  Then we started the Apache server and server was able to start.

 

We have also created a client (calcclient.cpp) to call the calculator webservice deployed in Apache.

But when we run the client:calcclient add 2 3

we are getting the following error.

 

Error -1 fault: SOAP-ENV:Client[no subcode]

"End of file or no input: Operation interrupted or timed out"

Detail: [no detail]

 

I then tried bulding the mod_gsoap.so through aCC compiler instead of apxs using the following command:

 

aCC +DD64 -c -AA +z mod_gsoap.c

aCC +DD64 -b -o mod_gsoap.so mod_gsoap.o

 

and loaded the mod_gsoap.so into Apache but I get the same error after running the calcclient.

 

But, when we build the same calculator.so and mod_gsoap.so shared libraries using C compilation, the calcclient runs successfully.

 

 

what is the reason that the code does not work in C++?

 

 

 

 

SoumitraC
Frequent Advisor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

Name mangling, perhaps?

 

You may want to verify that the symbols being crossed referenced do not get mangled, which would cause it to appear missing.

 

 

Soumitra C
HP-UX Compilers
Biswadeep
Advisor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

Hi,

 

The following is our c++ calculator service code

 

calculator.cpp

 

extern "C"

{

#include "apache_gsoap.h"

} #include<iostream.h>

extern "C"

{

IMPLEMENT_GSOAP_SERVER()//Macro present in apache_gsoap.h

}

extern "C" int soap_serve(struct soap *soap) {

soap_init(soap);  

calcService service(soap);  

int err = service.serve();

  service.destroy();  

return err;

} int calcService::add(double a, double b, double *result)

{

*result = a + b;  

return SOAP_OK;

}

int calcService::sub(double a, double b, double *result)

{

*result = a - b;  

return SOAP_OK;

}

 

The apache_gsoap.h file is as folows:

 

#ifdef __cplusplus

extern "C"

{

#endif

--

--

--- IMPLEMENT_GSOAP_SERVER()/ ---//Code snnipet in "C" -- --

--

--

#ifdef __cplusplus

}

 

The mod_gsoap.c file needed to generate the other module mod_gsoap.so is as follows:

 

#ifdef __cplusplus

extern "C"

{

#endif

-

-

--- -- -- --
#ifdef __cplusplus

}

#endif
#endif
 

 

So i guess there is no issue with name mangling as the C code is written with extern "C" code.

 

Dennis Handly
Acclaimed Contributor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

>we are getting the following error.

 Error -1 fault: SOAP-ENV:Client[no subcode]

"End of file or no input: Operation interrupted or timed out"

 

A particularly useless error.

 

>when we build the same calculator.so ... using C compilation

 

How can you do that when your source is C++?

 

>what is the reason that the code does not work in C++?

 

Have you tried setting breakpoints to trace the flow of code?  You may have to use tusc.

 

>int err = service.serve();

 

I assume serve() is dispatching to your calcService member functions?

 

extern "C" {

#include "apache_gsoap.h"

}

 

Since apache_gsoap.h has already been C++ified, you shouldn't put it in another extern "C" block.

Biswadeep
Advisor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

Hi ,

 

Thanks for the updates and all the helps till now.

 

>when we build the same calculator.so ... using C compilation

 How can you do that when your source is C++?

 

-->The source is in pure  "C"  ( not in C++)  when we are using C compiler.

 

>what is the reason that the code does not work in C++?

 

Have you tried setting breakpoints to trace the flow of code?  You may have to use tusc.

 

-->

we can not use tusc on a shared library , our service is .so so we  have tried tusc with the client code (which is actually calling the service).

The output of tusc on client code is inconsistant on different executions.

 

We have tried the same tusc for the service written in "C" as well  just to compare the output  and below is the difference we observed at the end of the output generated by tusc:

 

In C:

send(4, "P O S T   / s o a p   H T T P / ".., 608, 0) ........................................................ = 608
recv(4, "H T T P / 1 . 1   2 0 0   O K \r".., 65536, 0) ...................................................... = 610
brk(0x6000000000034000) ...................................................................................... = 0
shutdown(4, SHUT_RDWR) ....................................................................................... = 0
close(4) ..................................................................................................... = 0
write(1, "a f t e r   c a l l   t o   A d ".., 18) ........................................................... = 18
write(1, "\n", 1) ............................................................................................ = 1
brk(0x6000000000036000) ...................................................................................... = 0
ioctl(1, TCGETA, 0x87fffffffffcc410) ......................................................................... = 0
write(1, "r e s u l t   a c t u a l   =   ".., 18) ........................................................... = 18
exit(0) ...............................

 

 

In C++

 

send(4, "P O S T   / s o a p   H T T P / ".., 608, 0) ........................................................ = 608
recv(4, "H T T P / 1 . 1   2 0 0   O K \r".., 65536, 0) ...................................................... = 894
recv(4, 0x87fffffffffd8680, 65536, 0) ........................................................................ = 0
write(1, "a f t e r   c a l l   t o   A d ".., 18) ........................................................... = 18
write(1, "\n", 1) ............................................................................................ = 1
write(1, "S O A P   E R R O R : ", 11) ....................................................................... = 11
write(1, "\n", 1) ............................................................................................ = 1
write(1, "R e s u l t 2 : ", 8) .............................................................................. = 8
write(1, "0 ", 1) ............................................................................................ = 1
write(1, "\n", 1) ............................................................................................ = 1
write(2, "E r r o r   ", 6) .................................................................................. = 6
write(2, "- 1 ", 2) .......................................................................................... = 2
write(2, "  f a u l t :   ", 8) .............................................................................. = 8
write(2, "S O A P - E N V : C l i e n t ", 15) ............................................................... = 15
write(2, "[ ", 1) ............................................................................................ = 1
write(2, "n o   s u b c o d e ", 10) ......................................................................... = 10
write(2, "] ", 1) ............................................................................................ = 1
write(2, "\n", 1) ............................................................................................ = 1
write(2, "" ", 1) ............................................................................................ = 1
write(2, "E n d   o f   f i l e   o r   n ".., 59) ........................................................... = 59
write(2, "" ", 1) ............................................................................................ = 1
write(2, "\n", 1) ............................................................................................ = 1
write(2, "D e t a i l :   ", 8) .............................................................................. = 8
write(2, "[ n o   d e t a i l ] ", 11) ....................................................................... = 11
write(2, "\n", 1) ............................................................................................ = 1
shutdown(4, SHUT_RDWR) ....................................................................................... = 0
close(4) ..................................................................................................... = 0
exit(0) ...................................................................................................... WIFEXITED(0)

 

>int err = service.serve();

 

I assume serve() is dispatching to your calcService member functions?

--> Yes this is correct

 

extern "C" {

#include "apache_gsoap.h"

}

 

Since apache_gsoap.h has already been C++ified, you shouldn't put it in another extern "C" block.


-->Yes this is correct but using extern "C" multiple times should not make any difference ?

 

Please help what else we can try.

 

Thanks,

Biswadeep.

Dennis Handly
Acclaimed Contributor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

-->The source is in pure  "C"  ( not in C++)  when we are using C compiler.

 

But calculator.cpp is C++.  Or is that different than calc.so?

 

>we can not use tusc on a shared library

 

Yes, you use tusc on processes.

 

write(1, "a f t e r   c a l l   t o   A d ".., 18)

 

It seems to go wrong here.  Is this your message?  You may have to ask tusc to print longer strings in the writes.

 

write(1, "S O A P   E R R O R : ", 11)
write(1, "R e s u l t 2 : ", 8)
write(1, "0 ", 1)

-->using extern "C" multiple times should not make any difference?

 

It has caused compilation errors in the past and not a good idea to do.

Biswadeep
Advisor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

--->But calculator.cpp is C++.  Or is that different than calc.so?

 

We are trying to build our webservice in two differnet language: i.e in C and C++ respectively.

 The codes are in C and C++ respectively and the compiler is different for both the cases and the calc.so are also different in both the cases.

Both the webservices are distinct.

Our webservice is working fine with C code but in C++ we are facing issues as mentioned above.

Hope now its clear.Sorry for the confusion.

 

--->Yes, you use tusc on processes.

We tried running our code using the following command:

tusc -f -o calc.tusc  -p 19174( 19174 is the main process id,after loading our calc.so(in C++) , mod_gsoap.so(in C) into the apache server and starting it)

tail -f calc.tusc

Here is our output file

[19174] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... [sleeping]

[19174] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[19174] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[19174] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[19174] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[19174] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[19174] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[19174] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[19174] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[19174] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[19174] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

 

When We tried tusc in C code thats working fine(for comaprison purpose) using the command:

tusc -f -o calc1.tusc  -p 26841( 26841 is the main process id,after loading our calc.so(in C) ,mod_gsoap.so(in C)( into the apache server and starting it)

tail -f calc1.tusc

the output file is as follows:

 

[26841] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... [sleeping]

[26841] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[26841] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[26841] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[26841] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[26841] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[26841] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[26841] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[26841] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

[26841] select(0, NULL, NULL, NULL, 0x87ffffffffff65d0) ...................................................... = 0

[26841] waitpid(-1, WIFEXITED(0), WNOHANG|WUNTRACED) ......................................................... = 0

 

  The output file using tusc is same for process(using C) and process(using C++).

for c we are getting the correct result through client but for C++ it is not working.

 

---> using extern "C" multiple times has caused compilation errors in the past and not a good idea to do.

 

ok but we are not facing anny issues during compilation time.We have even removed the extern "C" line from our code and compiled the code again.

 

Please suggest what we should do next.

Dennis Handly
Acclaimed Contributor

Re: Runtime unsats with a simple aC++ shlib as Apache plugin

>Here is our output file

 

Your two tusc output file fragments don't cover the error timeframe.

Your previous one did and included the error message.

 

Note: The -p option has nothing to do with the PID but with listing them.  And so it should go next to the -f: -fp

 

>The output file using tusc is same for process (using C) and process (using C++).

>for C we are getting the correct result through client but for C++ it is not working.

 

This would imply it isn't the system calls but how you process the data that's going wrong.

All tusc can do is bracket the timeframes.