Home >Backend Development >PHP Tutorial >Problem with function redefinition when extending PHP with C++

Problem with function redefinition when extending PHP with C++

WBOY
WBOYOriginal
2016-08-08 09:21:301304browse

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

<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.

Statement:
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