Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cygwin gcc链接器找不到-lpython2.7_Python_Gcc_Dll_Cygwin_Shared - Fatal编程技术网

cygwin gcc链接器找不到-lpython2.7

cygwin gcc链接器找不到-lpython2.7,python,gcc,dll,cygwin,shared,Python,Gcc,Dll,Cygwin,Shared,我已经在cygwin中使用gcc将几个.c程序编译成相应的.o文件,如下所示: gcc -fPIC -c test5*.c -I/usr/include/python2.7 -L/usr/lib/python2.7 -lpython2.7 现在,我试图将它们链接到一个python可以使用的dll库中。这就是问题开始的地方,首先,我尝试了以下命令: gcc -shared test5*.o -o test5.dll -I/usr/include/python2.7 -L/usr/lib/pyth

我已经在cygwin中使用gcc将几个.c程序编译成相应的.o文件,如下所示:

gcc -fPIC -c test5*.c -I/usr/include/python2.7 -L/usr/lib/python2.7 -lpython2.7
现在,我试图将它们链接到一个python可以使用的dll库中。这就是问题开始的地方,首先,我尝试了以下命令:

gcc -shared test5*.o -o test5.dll -I/usr/include/python2.7 -L/usr/lib/python2.7
然后,它抱怨没有找到很多python函数调用,如下所示:

test5_wrap.o:test5_wrap.c:(.text+0x42e0): undefined reference to `PyArg_ParseTuple'
test5_wrap.o:test5_wrap.c:(.text+0x450e): undefined reference to `PyArg_ParseTuple'
test5_wrap.o:test5_wrap.c:(.text+0x4924): undefined reference to `PyString_FromString'
test5_wrap.o:test5_wrap.c:(.text+0x4942): undefined reference to `PyString_FromString'
test5_wrap.o:test5_wrap.c:(.text+0x4963): undefined reference to `PyString_FromString'
test5_wrap.o:test5_wrap.c:(.text+0x4972): undefined reference to `PyString_ConcatAndDel'
gcc -shared test5*.o -o test5.dll -I/usr/include/python2.7 -L/usr/lib/python2.7 -lpython2.7
根据大家的说法,这是因为需要指定-lpython2.7,所以我将其添加到gcc命令中,如下所示:

test5_wrap.o:test5_wrap.c:(.text+0x42e0): undefined reference to `PyArg_ParseTuple'
test5_wrap.o:test5_wrap.c:(.text+0x450e): undefined reference to `PyArg_ParseTuple'
test5_wrap.o:test5_wrap.c:(.text+0x4924): undefined reference to `PyString_FromString'
test5_wrap.o:test5_wrap.c:(.text+0x4942): undefined reference to `PyString_FromString'
test5_wrap.o:test5_wrap.c:(.text+0x4963): undefined reference to `PyString_FromString'
test5_wrap.o:test5_wrap.c:(.text+0x4972): undefined reference to `PyString_ConcatAndDel'
gcc -shared test5*.o -o test5.dll -I/usr/include/python2.7 -L/usr/lib/python2.7 -lpython2.7
但现在,它抱怨找不到-lpython2.7:

/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lpython2.7
collect2: error: ld returned 1 exit status

任何帮助都将不胜感激。

您需要尝试并了解自己在做什么,而不是盲目地听从随机建议。PyArg_ParseTuple未定义,因此需要链接定义它的库。这是用
-l
完成的
-lfoo
查找一个名为libfoo.a或libfoo.so的文件(可能它还可以在windows上找到libfoo.lib或其他文件,我不知道)。你写了
-lpython2.7
,你有一个名为libpython2.7.so或libpython2.7.a的文件吗?@marglisse,是的,我同意,我在windows上,这些指令中有很多都是针对linux的。我将进一步验证,以发布明确的回复。但我只是希望人们把事情发出来,并清楚地说出来,他们到底是在什么平台上让它工作的。。。