Problem with function redefinition when extending PHP with C++

WBOY
Release: 2016-08-08 09:21:30
Original
1218 people have browsed it

Question: When I used C++ to extend php, I used some mathematical library functions such as sqr, sqrt, etc. I need to #include in the source file test.cpp of the C++ extension project, but these functions were found during compilation. There is a problem of redefinition.

After many attempts, I found that when #include "php.h" at the beginning of test.cpp is removed, this problem disappears

Reason: From the query, many C++ library functions are included in php.h Inline is defined directly in php.h, causing the function definition of the same name in the C++ library function file stdio.h to be recognized as a redefinition (inline-modified functions are not allowed to be defined in other files)

Solution: There will be redefined functions The C++ header file #include is written before #include "php.h" to block the inline function. Its location in test.cpp is as follows:

#ifdef HAVE_CONFIG_H #include "config.h" #endif #include  #include  #include  #include  #include  #include  #include  #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_NearestNeighbors.h"
Copy after login

Copyright statement: This article is an original article by the blogger and has not been published by the blogger. No reproduction allowed with permission of the owner.

The above has introduced the problem of function redefinition when extending PHP with C++, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!