You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by whut_jia <wh...@163.com> on 2010/11/30 13:05:02 UTC

compile a file written by C++ into apache

Hi,
I write a module by C++ supporting the generation of SAML assertion, so in my  module I called the OpenSAML Library.The question is how I compile this source file written by c++ language into my apache server.
Please help me.Thanks a lot at first!


Regards,
Jia

Re:Re: Re: compile a file written by C++ into apache

Posted by whut_jia <wh...@163.com>.
At 2010-11-30 21:58:56,"Ben Noordhuis" <in...@bnoordhuis.nl> wrote:

>2010/11/30 whut_jia <wh...@163.com>:
>> In Apache2.2, I compile a c++ source file with g++ as below:
>> g++ -fPIC -shared -o mod_validate.so mod_validate.cpp -I/usr/include/httpd -I/usr/include/apr-1 -I/opt/opensaml/include
>> After it , I copy mod_calidate.so into apache module location ,and this module work well.
>> But now,in apache2.3,I compile this file in  the same way.it accurs the following error,
>>     /apache2.3/include/http_config.h:989:error:expected ","or "..." before ‘new’
>> (In headers file ,The 989th  line is:
>> AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old,
>>                                     struct ap_logconf *new);
>> )
>> I think there are not errors in this line ,but why can i compile it successfullly?
>
>new is a C++ keyword. Three solutions.
>
>1. Rename the parameter in http_config.h to new_conf. Bad.
>2. At the top of your source file add "#define new new_". Bad.
>3. Make your module C only. Split off the C++ code into a separate file. Good.

Hi, Noordhui,
Thank you for your reply.
Because  OpenSAML which I called is a set of open source C++ & Java libraries and large  ,so I  want to write a module with c++ ,in which I can call the library-function directly.Can you give me some help how I compile  module written by c++ into apache DSO file.I used apxs tool but it failed.This tool can't compiling c++ source file???If using g++,is my directive  correct??(g++ -fPIC -shared -o mod_validate.so mod_validate.cpp -I/usr/include/httpd -I/usr/include/apr-1 -I/opt/opensaml/include) .
Because I am just studying apache module development, I hope get more help.Thanks for your concern!
Regards,
Jia


Re: compile a file written by C++ into apache

Posted by whut_jia <wh...@163.com>.
Hi,thank you for your reply.Because I called the third-party Library,so I  want to write a module with c++ ,in which I can call the function directly.Can you give me some help how I compile  module written by c++ into apache DSO file.I used apxs tool but it failed.This tool can't compiling c++ source file???Thanks,JIa

Re: compile a file written by C++ into apache

Posted by whut_jia <wh...@163.com>.
At 2010-11-30 22:58:01,"Eric Covener" <co...@gmail.com> wrote:

>On Tue, Nov 30, 2010 at 8:58 AM, Ben Noordhuis <in...@bnoordhuis.nl> wrote:
>> 2010/11/30 whut_jia <wh...@163.com>:
>>> In Apache2.2, I compile a c++ source file with g++ as below:
>>> g++ -fPIC -shared -o mod_validate.so mod_validate.cpp -I/usr/include/httpd -I/usr/include/apr-1 -I/opt/opensaml/include
>>> After it , I copy mod_calidate.so into apache module location ,and this module work well.
>>> But now,in apache2.3,I compile this file in  the same way.it accurs the following error,
>>>     /apache2.3/include/http_config.h:989:error:expected ","or "..." before ‘new’
>>> (In headers file ,The 989th  line is:
>>> AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old,
>>>                                     struct ap_logconf *new);
>>> )
>>> I think there are not errors in this line ,but why can i compile it successfullly?
>>
>> new is a C++ keyword. Three solutions.
>>
>> 1. Rename the parameter in http_config.h to new_conf. Bad.
>> 2. At the top of your source file add "#define new new_". Bad.
>> 3. Make your module C only. Split off the C++ code into a separate file. Good.
>>
>
>
>I believe this was reported and fixed in trunk over the last month or so.
>
>-- 
>Eric Covener
>covener@gmail.com
Ohahaha,
Eric Covener,Thank you!
You are right ! I download  30-Nov-2010 apache source code. Indeed It is modified in trunk .

Re: Re: compile a file written by C++ into apache

Posted by Eric Covener <co...@gmail.com>.
On Tue, Nov 30, 2010 at 8:58 AM, Ben Noordhuis <in...@bnoordhuis.nl> wrote:
> 2010/11/30 whut_jia <wh...@163.com>:
>> In Apache2.2, I compile a c++ source file with g++ as below:
>> g++ -fPIC -shared -o mod_validate.so mod_validate.cpp -I/usr/include/httpd -I/usr/include/apr-1 -I/opt/opensaml/include
>> After it , I copy mod_calidate.so into apache module location ,and this module work well.
>> But now,in apache2.3,I compile this file in  the same way.it accurs the following error,
>>     /apache2.3/include/http_config.h:989:error:expected ","or "..." before ‘new’
>> (In headers file ,The 989th  line is:
>> AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old,
>>                                     struct ap_logconf *new);
>> )
>> I think there are not errors in this line ,but why can i compile it successfullly?
>
> new is a C++ keyword. Three solutions.
>
> 1. Rename the parameter in http_config.h to new_conf. Bad.
> 2. At the top of your source file add "#define new new_". Bad.
> 3. Make your module C only. Split off the C++ code into a separate file. Good.
>


I believe this was reported and fixed in trunk over the last month or so.

-- 
Eric Covener
covener@gmail.com

Re: Re: compile a file written by C++ into apache

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
2010/11/30 whut_jia <wh...@163.com>:
> In Apache2.2, I compile a c++ source file with g++ as below:
> g++ -fPIC -shared -o mod_validate.so mod_validate.cpp -I/usr/include/httpd -I/usr/include/apr-1 -I/opt/opensaml/include
> After it , I copy mod_calidate.so into apache module location ,and this module work well.
> But now,in apache2.3,I compile this file in  the same way.it accurs the following error,
>     /apache2.3/include/http_config.h:989:error:expected ","or "..." before ‘new’
> (In headers file ,The 989th  line is:
> AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old,
>                                     struct ap_logconf *new);
> )
> I think there are not errors in this line ,but why can i compile it successfullly?

new is a C++ keyword. Three solutions.

1. Rename the parameter in http_config.h to new_conf. Bad.
2. At the top of your source file add "#define new new_". Bad.
3. Make your module C only. Split off the C++ code into a separate file. Good.

Re:Re: compile a file written by C++ into apache

Posted by whut_jia <wh...@163.com>.
At 2010-11-30 20:57:24,"Ben Noordhuis" <in...@bnoordhuis.nl> wrote:

>2010/11/30 whut_jia <wh...@163.com>:
>> I write a module by C++ supporting the generation of SAML assertion, so in my  module I called the OpenSAML Library.The question is how I compile this source file written by c++ language into my apache server.
>
>Like you compile any mixed project: define a function in your C++ code
>with C linkage[1] and call it from your C code. Compile .c and .cc
>files to object files, then link them into a shared object.
>
>apxs2 probably won't be much help here, it doesn't seem to handle C++
>source files (at least, it never does in my projects).
>
>[1] extern "C" void entrypoint(void *data) { /* ... */ }

Thank you for your replay,
In Apache2.2, I compile a c++ source file with g++ as below:
g++ -fPIC -shared -o mod_validate.so mod_validate.cpp -I/usr/include/httpd -I/usr/include/apr-1 -I/opt/opensaml/include
After it , I copy mod_calidate.so into apache module location ,and this module work well.
But now,in apache2.3,I compile this file in  the same way.it accurs the following error,
     /apache2.3/include/http_config.h:989:error:expected ","or "..." before ‘new’
(In headers file ,The 989th  line is:
AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old,
                                     struct ap_logconf *new);
)
I think there are not errors in this line ,but why can i compile it successfullly?
Thank you,
Jia

Re: compile a file written by C++ into apache

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
2010/11/30 whut_jia <wh...@163.com>:
> I write a module by C++ supporting the generation of SAML assertion, so in my  module I called the OpenSAML Library.The question is how I compile this source file written by c++ language into my apache server.

Like you compile any mixed project: define a function in your C++ code
with C linkage[1] and call it from your C code. Compile .c and .cc
files to object files, then link them into a shared object.

apxs2 probably won't be much help here, it doesn't seem to handle C++
source files (at least, it never does in my projects).

[1] extern "C" void entrypoint(void *data) { /* ... */ }