C 嵌入 Pythom 編譯問題

C 嵌入 Pythom 編譯問題



[Copy to clipboard] [ - ]
CODE:
#include <Python.h>

int main(void){
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
                        "print 'Today is',ctime(time()\n)");
    Py_Finalize();
    return 1;

}

我是用 debian

gcc -I/opt/python/include/python2.4 -L/opt/python/lib -lpython2.4 -o test_py test_py.c

上面程式碼是我在網路上看到的


不過我opt 資料夾沒有任何東西 ,  我查了一下我python 所有文件擺放位置

不過我也沒看到 include & lib 我想知道python  include & lib 會在哪個路徑下
我測試過可以執行 python 程式 , 那應該代表我主機有安裝python
知道朋友麻煩告知一下 , 或是編譯是用其他方式?

下面是我主機 python 所有文件擺放位置

[Copy to clipboard] [ - ]
CODE:
debian:~$ dpkg -L python
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/python
/usr/share/doc/python/faq
/usr/share/doc/python/faq/extending.html
/usr/share/doc/python/faq/general.html
/usr/share/doc/python/faq/gui.html
/usr/share/doc/python/faq/installed.html
/usr/share/doc/python/faq/library.html
/usr/share/doc/python/faq/programming.html
/usr/share/doc/python/faq/windows.html
/usr/share/doc/python/FAQ.html
/usr/share/doc/python/python-policy.html
/usr/share/doc/python/python-policy.html/index.html
/usr/share/doc/python/python-policy.html/ch-python.html
/usr/share/doc/python/python-policy.html/ch-module_packages.html
/usr/share/doc/python/python-policy.html/ch-programs.html
/usr/share/doc/python/python-policy.html/ch-embed.html
/usr/share/doc/python/python-policy.html/ch-other.html
/usr/share/doc/python/python-policy.html/ap-build_dependencies.html
/usr/share/doc/python/python-policy.html/ap-upgrade.html
/usr/share/doc/python/README.Debian
/usr/share/doc/python/copyright
/usr/share/doc/python/python-policy.sgml.gz
/usr/share/doc/python/python-policy.txt.gz
/usr/share/doc/python/changelog.Debian.gz
/usr/share/doc/python2.3
/usr/share/man
/usr/share/man/man1
/usr/share/apps
/usr/share/apps/konsole
/usr/share/apps/konsole/python.desktop
/usr/share/doc-base
/usr/share/doc-base/python-policy
/usr/bin
/usr/lib
/usr/lib/valgrind
/usr/lib/valgrind/python.supp
/usr/share/doc/python2.3/python-policy.html
/usr/share/doc/python2.3/python-policy.sgml.gz
/usr/share/doc/python2.3/python-policy.txt.gz
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/pydoc.1.gz
/usr/share/man/man1/pygettext.1.gz
/usr/share/man/man1/pdb.1.gz
/usr/bin/python
/usr/bin/pydoc
/usr/bin/pygettext
/usr/bin/pdb

謝謝

[Copy to clipboard] [ - ]
CODE:
#include <Python.h>

int main(void){
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
                        "print 'Today is',ctime(time()\n)");
    Py_Finalize();
    return 1;

}

gcc -I/opt/python/include/python2.4 -L/opt/python/lib -lpython2.4 -o test_py test_py.c

上面程式碼是我在網路上看到的


不過我opt 資料夾沒有任何東西 ,  我查了一下我python 所有檔案擺放位置

不過我也沒看到 include & lib 我想知道python  include & lib 會在哪個路徑下
我測試過可以執行 python 程式 , 那應該代表我主機有安裝python
知道朋友麻煩告知一下 , 或是編譯是用其他方式?

下面是我主機 python 所有檔案擺放位置

[Copy to clipboard] [ - ]
CODE:
debian:~$ dpkg -L python
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/python
/usr/share/doc/python/faq
/usr/share/doc/python/faq/extending.html
/usr/share/doc/python/faq/general.html
/usr/share/doc/python/faq/gui.html
/usr/share/doc/python/faq/installed.html
/usr/share/doc/python/faq/library.html
/usr/share/doc/python/faq/programming.html
/usr/share/doc/python/faq/windows.html
/usr/share/doc/python/FAQ.html
/usr/share/doc/python/python-policy.html
/usr/share/doc/python/python-policy.html/index.html
/usr/share/doc/python/python-policy.html/ch-python.html
/usr/share/doc/python/python-policy.html/ch-module_packages.html
/usr/share/doc/python/python-policy.html/ch-programs.html
/usr/share/doc/python/python-policy.html/ch-embed.html
/usr/share/doc/python/python-policy.html/ch-other.html
/usr/share/doc/python/python-policy.html/ap-build_dependencies.html
/usr/share/doc/python/python-policy.html/ap-upgrade.html
/usr/share/doc/python/README.Debian
/usr/share/doc/python/copyright
/usr/share/doc/python/python-policy.sgml.gz
/usr/share/doc/python/python-policy.txt.gz
/usr/share/doc/python/changelog.Debian.gz
/usr/share/doc/python2.3
/usr/share/man
/usr/share/man/man1
/usr/share/apps
/usr/share/apps/konsole
/usr/share/apps/konsole/python.desktop
/usr/share/doc-base
/usr/share/doc-base/python-policy
/usr/bin
/usr/lib
/usr/lib/valgrind
/usr/lib/valgrind/python.supp
/usr/share/doc/python2.3/python-policy.html
/usr/share/doc/python2.3/python-policy.sgml.gz
/usr/share/doc/python2.3/python-policy.txt.gz
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/pydoc.1.gz
/usr/share/man/man1/pygettext.1.gz
/usr/share/man/man1/pdb.1.gz
/usr/bin/python
/usr/bin/pydoc
/usr/bin/pygettext
/usr/bin/pdb

謝謝
是因为你找不到include和lib文件夹么?到/usr/include和/usr/lib里面看看有没有python目录。。


我用的是RED HAT 我的编译指令:

[Copy to clipboard] [ - ]
CODE:
[root@localhost yaoms]#  gcc -o pythontest pythontest.c  -I/usr/include/python2.3/ -L/usr/lib/python2.3/ -lpython2.3
[root@localhost yaoms]# ./pythontest
Today is Wed Aug  1 17:32:03 2007

在你的机器上找libpythonxxx的文件