c++ dynamic module fails to load

classic Classic list List threaded Threaded
3 messages Options
xrd
Reply | Threaded
Open this post in threaded view
|

c++ dynamic module fails to load

xrd
Hi All,

I have a C++ module developed for apache HTTP which now Im trying to port to
Nginx. For this I started reading about creating dynamic modules and
specifically c++. I already found ngx_cpp_test_module.cpp in the source and
able to compile it. I extended it a little and wrote a hello world program
which compiles fine but when I restart Nginx I get following error:

[build@8e269df38d20 nginx-1.16.1]$ sudo /usr/sbin/nginx -t
nginx: [emerg] dlopen() "/etc/nginx/modules/ngx_http_cpp_hello_module.so"
failed (/etc/nginx/modules/ngx_http_cpp_hello_module.so: undefined symbol:
ngx_http_cpp_hello_module) in /etc/nginx/nginx.conf:2

I have configured it as follows:

./configure --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
-grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-lstdc++
-lrt -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/home/build
--add-dynamic-module=/mnt/src/hello-world-cpp --with-threads

The config:

ngx_addon_name=ngx_http_cpp_hello_module

if test -n "$ngx_module_link"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_srcs="$ngx_addon_dir/ngx_http_cpp_hello_world_module.cpp"

    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES ngx_http_hello_module"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS
$ngx_addon_dir/ngx_http_cpp_hello_world_module.cpp"
fi

As per the error "undefined symbol: ngx_http_cpp_hello_module" Im trying to
understand why it is trying to find that function in the code.
Is there something that I'm missing during configuring or compilation
process?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285679,285679#msg-285679

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: c++ dynamic module fails to load

Maxim Dounin
Hello!

On Tue, Sep 24, 2019 at 05:05:59AM -0400, astre wrote:

> Hi All,
>
> I have a C++ module developed for apache HTTP which now Im trying to port to
> Nginx. For this I started reading about creating dynamic modules and
> specifically c++. I already found ngx_cpp_test_module.cpp in the source and
> able to compile it. I extended it a little and wrote a hello world program
> which compiles fine but when I restart Nginx I get following error:
>
> [build@8e269df38d20 nginx-1.16.1]$ sudo /usr/sbin/nginx -t
> nginx: [emerg] dlopen() "/etc/nginx/modules/ngx_http_cpp_hello_module.so"
> failed (/etc/nginx/modules/ngx_http_cpp_hello_module.so: undefined symbol:
> ngx_http_cpp_hello_module) in /etc/nginx/nginx.conf:2
>
> I have configured it as follows:
>
> ./configure --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
> -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4
> -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-lstdc++
> -lrt -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/home/build
> --add-dynamic-module=/mnt/src/hello-world-cpp --with-threads
>
> The config:
>
> ngx_addon_name=ngx_http_cpp_hello_module
>
> if test -n "$ngx_module_link"; then
>     ngx_module_type=HTTP
>     ngx_module_name=$ngx_addon_name
>     ngx_module_srcs="$ngx_addon_dir/ngx_http_cpp_hello_world_module.cpp"
>
>     . auto/module
> else
>     HTTP_MODULES="$HTTP_MODULES ngx_http_hello_module"
>     NGX_ADDON_SRCS="$NGX_ADDON_SRCS
> $ngx_addon_dir/ngx_http_cpp_hello_world_module.cpp"
> fi
>
> As per the error "undefined symbol: ngx_http_cpp_hello_module" Im trying to
> understand why it is trying to find that function in the code.
> Is there something that I'm missing during configuring or compilation
> process?

That's the module name you've specified during build
("ngx_module_name=$ngx_addon_name"), and hence this is the module
structure nginx tries to find during loading.  Since there is no
such structure, module loading fails.

If you are curios where the structure in question is referenced,
check auto/module and auto/make files.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
xrd
Reply | Threaded
Open this post in threaded view
|

Re: c++ dynamic module fails to load

xrd
Thanks Maxim. I have updated my source to reflect the addon name. It is
working.
Ill get back once I get deep into auto/module and auto/make :)

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,285679,285701#msg-285701

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx