Jump to content
  • 0
Sign in to follow this  
Ninhursag

Python plugin

Question

Hi!!

i'm trying to add python 3.9 source to my plugins. test.c

 

#include <Python.h>

 

int main()

{

    PyObject* pInt;

 

    Py_Initialize();

 

    PyRun_SimpleString("print('Hello World from Embedded Python!!!')");

   

    Py_Finalize();

 

    printf("\nPress any key to exit...\n");

    if(!_getch()) _getch();

    return 0;

}

 

But when i compile i have an error including python

 

        CC      test.c
test.c:3:10: fatal error: Python.h: No such file or directory
    3 | #include <Python.h>
      |          ^~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:106: ../../plugins/test.so] Error 1

 

i research a little about it on stackoverflow and im seeying to pass the flags into plugins makefile like this

 

Makefile: Makefile.in
    @$(MAKE) -C ../.. src/plugins/Makefile

.SECONDEXPANSION:

../../plugins/%@DLLEXT@: %.c $(ALL_H) $$(shell ls %/* 2>/dev/null)
    @echo "    CC    $<"
    @$(CC) $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @PLUGINSTATIC@ @DEFS@ @CFLAGS@ -I/usr/include/python3.9  -Wno-unused-result -Wsign-compare -g -ffile-prefix-map=/build/python3.9-FZ7wim/python3.9-3.9.5=. -flto=auto -ffat-lto-objects -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall @CPPFLAGS@ @LDFLAGS@ -L/usr/lib/python3.9/config-3.9-x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu  -lcrypt -lpthread -ldl  -lutil -lm -lm @SOFLAGS@ @LIBS@ @MYSQL_LIBS@ -o $@ $<

../../plugins/HPMHooking_login@DLLEXT@: HPMHOOKINGTYPE = LOGIN
../../plugins/HPMHooking_char@DLLEXT@: HPMHOOKINGTYPE = CHAR
../../plugins/HPMHooking_map@DLLEXT@: HPMHOOKINGTYPE = MAP

../../plugins/HPMHooking_%@DLLEXT@: HPMHooking.c $(ALL_H) $$(shell ls HPMHooking/*_%* HPMHooking/*_common* 2>/dev/null)
    @echo "    CC    $< ($(HPMHOOKINGTYPE))"
    @$(CC) -DHPMHOOKING_$(HPMHOOKINGTYPE) $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @PLUGINSTATIC@ @DEFS@ @CFLAGS@ -I/usr/include/python3.9  -Wno-unused-result -Wsign-compare -g -ffile-prefix-map=/build/python3.9-FZ7wim/python3.9-3.9.5=. -flto=auto -ffat-lto-objects -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security  -DNDEBUG -g -fwrapv -O3 -Wall @CPPFLAGS@ @LDFLAGS@  -L/usr/lib/python3.9/config-3.9-x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu  -lcrypt -lpthread -ldl  -lutil -lm -lm @SOFLAGS@ -o $@ $<

 

 

And when i compile with flags i got this error, like the python 3.9 is included now, but the linker doesnt work.

Could anyone help me how to solve this and add python to my plugins?

Thank you so much

 

usr/bin/ld: /tmp/test.so.Yc5jF3.ltrans0.ltrans.o: in function `main':
/home/ubuntu/hercules/src/plugins/test.c:9: undefined reference to `Py_Initialize'
/usr/bin/ld: /home/ubuntu/hercules/src/plugins/test.c:11: undefined reference to `PyRun_SimpleStringFlags'
/usr/bin/ld: /home/ubuntu/hercules/src/plugins/test.c:13: undefined reference to `Py_Finalize'
/usr/bin/ld: /home/ubuntu/hercules/src/plugins/test.c:16: undefined reference to `_getch'
/usr/bin/ld: /home/ubuntu/hercules/src/plugins/test.c:16: undefined reference to `_getch'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:106: ../../plugins/test.so] Error 1
make[1]: Leaving directory '/home/ubuntu/hercules/src/plugins'
make: *** [Makefile:132: plugins] Error 2

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 1

undefined referenced like

Quote

undefined reference to `Py_Initialize'

 

show what you not linking with python library. need something like

Quote

-llibpython

 

but probably with full path to libpython.so with version number in name

you can see what library to use in other programs what linked to python.

Share this post


Link to post
Share on other sites
  • 0

you can share pythin plugin?

probably will be good to add it as sample plugin into hercules

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.