Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault #352

Open
easydowork opened this issue Oct 10, 2017 · 1 comment
Open

Segmentation fault #352

easydowork opened this issue Oct 10, 2017 · 1 comment

Comments

@easydowork
Copy link

easydowork commented Oct 10, 2017

I make a simple demo , like this

#include <phpcpp.h>
#include
void myFunction()
{
Php::out << "hello world" << std::endl;
}
extern "C" {
PHPCPP_EXPORT void *get_module() {
static Php::Extension extension("my_extension", "1.0");
extension.add("myFunction");
return extension;
}
}

but ,when I test this extension , the CLI mode echo :

"hello world
Segmentation fault"

@alain91
Copy link

alain91 commented Dec 10, 2018

It seems you have few errors in your files.

your file:

#include <phpcpp.h>
#include          /* MISSING INCLUDE FILE */
void myFunction()
{
Php::out << "hello world" << std::endl;
}
extern "C" {
PHPCPP_EXPORT void *get_module() {
static Php::Extension extension("my_extension", "1.0");
extension.add("myFunction"); /* MISSING FUNCTION TYPE <myFunction> */
return extension; /* MISSING METHOD  module() LESS IMPORTANT WORKS WITHOUT*/
}
}

simpledemo.cpp after correction + change name of extension from my_extension to simpledemo

#include <phpcpp.h>
#include <iostream>

void myFunction()
{
	Php::out << "hello world" << std::endl;
}

extern "C" {
	PHPCPP_EXPORT void *get_module() {
		static Php::Extension extension("simpledemo", "1.0");
		extension.add<myFunction>("myFunction");
		return extension.module();
	}
}

simpledemo.php

#!/usr/bin/env php
<?php
declare(strict_types=1);

$extname = 'simpledemo';
if ( ! extension_loaded($extname) ) {
    if ( false === @dl($extname.'.so') )
        die('Unable to load extension '.$extname.PHP_EOL);
}
    
echo myFunction() . "\n";

All works fine.

Examples files provided with PHPCPP are good templates for your usage but copy or modify them carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants