Home >Backend Development >PHP Tutorial >Problem with function redefinition when extending PHP with C++
Question: When I used C++ to extend php, I used some mathematical library functions such as sqr, sqrt, etc. I need to #include
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 <strong>#include <stdio.h> #include <string.h> #include <math.h> #include <map> #include <vector> #include <set> #include <queue></strong> #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_NearestNeighbors.h"
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.