ld在cygwin下无法找到存在的库

时间:2011-07-29 19:12:30

标签: c++ python g++ perforce

我正在尝试安装p4python,这是Perforce版本控制系统的Python扩展。我正在使用cygwin来实现这一点,因为p4python需要P4 C ++ API(它实际上只是一个包装器),而这又需要g ++(更不用说,Python扩展需要一个C编译器,因此,gcc)。我在Windows 7 64位(不是选择)和Microsoft VS 2008给了我一些相当顽固的问题;我听说使用Cygwin / MinGW可能是更好的选择。我也查找了相关问题,但似乎没有一个问题特别相关。

我能想到的最好的是ld正在寻找这些libs的错误位置,并且我被告知Cygwin不能很好地处理符号链接,但我不确定从哪里开始。请参见下面的终端输出:

API Release 2010.2
running install
running build
running build_py
running build_ext
building 'P4API' extension
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c P4API.cpp -o build/temp.cygwin-1.7.9-i686-2.6/P4API.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c PythonClientAPI.cpp -o build/temp.cygwin-1.7.9-i686-2.6/PythonClientAPI.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c PythonClientUser.cpp -o build/temp.cygwin-1.7.9-i686-2.6/PythonClientUser.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
PythonClientUser.cpp: In member function ‘virtual int PythonClientUser::Resolve(ClientMerge*, Error*)’:
PythonClientUser.cpp:423: warning: deprecated conversion from string constant to ‘char*’
PythonClientUser.cpp:423: warning: deprecated conversion from string constant to ‘char*’
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c SpecMgr.cpp -o build/temp.cygwin-1.7.9-i686-2.6/SpecMgr.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
SpecMgr.cpp: In member function ‘PyObject* SpecMgr::NewSpec(StrPtr*)’:
SpecMgr.cpp:550: warning: deprecated conversion from string constant to ‘char*’
SpecMgr.cpp:550: warning: deprecated conversion from string constant to ‘char*’
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c P4Result.cpp -o build/temp.cygwin-1.7.9-i686-2.6/P4Result.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
P4Result.cpp: In destructor ‘P4Result::~P4Result()’:
P4Result.cpp:49: warning: suggest explicit braces to avoid ambiguous ‘else’
P4Result.cpp:52: warning: suggest explicit braces to avoid ambiguous ‘else’
P4Result.cpp:55: warning: suggest explicit braces to avoid ambiguous ‘else’
P4Result.cpp: In member function ‘void P4Result::Reset()’:
P4Result.cpp:71: warning: suggest explicit braces to avoid ambiguous ‘else’
P4Result.cpp:75: warning: suggest explicit braces to avoid ambiguous ‘else’
P4Result.cpp: In member function ‘void P4Result::Fmt(const char*, PyObject*, StrBuf&)’:
P4Result.cpp:189: warning: deprecated conversion from string constant to ‘char*’
P4Result.cpp:189: warning: deprecated conversion from string constant to ‘char*’
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c PythonMergeData.cpp -o build/temp.cygwin-1.7.9-i686-2.6/PythonMergeData.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c P4MapMaker.cpp -o build/temp.cygwin-1.7.9-i686-2.6/P4MapMaker.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DID_OS="CYGWINX86" -DID_REL="2009.2" -DID_PATCH="240822" -DID_API="2010.2" -DID_Y="2010" -DID_M="04" -DID_D="02" -IC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -IC:\Pyt
hon\p4api\p4api-2010.2.295040-vs2010_static\/include/p4 -I/usr/include/python2.6 -c PythonSpecData.cpp -o build/temp.cygwin-1.7.9-i686-2.6/PythonSpecData.o -DOS_CYGWIN -DOS_CYGWIN -DOS_CYGWINX86 -DOS_CYGWINX86
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
g++ -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.7.9-i686-2.6/P4API.o build/temp.cygwin-1.7.9-i686-2.6/PythonClientAPI.o build/temp.cygwin-1.7.9-i686-2.6/PythonClientUser.o build/temp.cygwin-1.7.9-i686-2.6/SpecMgr.o build/temp.cygwin-1.7.
9-i686-2.6/P4Result.o build/temp.cygwin-1.7.9-i686-2.6/PythonMergeData.o build/temp.cygwin-1.7.9-i686-2.6/P4MapMaker.o build/temp.cygwin-1.7.9-i686-2.6/PythonSpecData.o -LC:\Python\p4api\p4api-2010.2.295040-vs2010_static\ -LC:\Python\p4api\p4api-2010
.2.295040-vs2010_static\/lib -L/usr/lib/python2.6/config -lclient -lrpc -lsupp -lpython2.6 -o build/lib.cygwin-1.7.9-i686-2.6/P4API.dll
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lclient
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lrpc
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lsupp
collect2: ld returned 1 exit status
error: command 'g++' failed with exit status 1

提出一个更具体的问题,是在寻找错误的地方还是其他出错的地方,我没有看到?我没有想法。非常感谢任何帮助或指导。

2 个答案:

答案 0 :(得分:3)

这是我用来将lib文件转换为共享库以便与gcc一起使用的方法:

  1. echo EXPORTS > NAME.def
  2. nm NAME.lib | grep ' T _' | sed 's/.* T _//' >> NAME.def
  3. dlltool --input-def NAME.def --dllname NAME --output-lib libNAME.a
  4. 关于使用Cygwin的更多说明(但我在较旧的32位系统上使用gcc 3,因此YMMV):

    安装gcc-mingw软件包(用于gcc和g ++ 3的mingw的头文件和库)或者使用mingw-w64用于gcc 4.5的新软件包之一。此外,使用选项-mno-cygwin进行编译,以防止将Cygwin链接到可执行文件/库中。对于Python扩展,您可以通过将distutils.cfg文件添加到Lib \ distutils文件夹来永久配置distutils以使用mingw:

    [build]
    compiler = mingw32   #or mingw64
    
    [build_ext]
    compiler = mingw32   #or mingw64
    

    我将C:\cygwin\bin添加到Windows路径(最后将干扰降至最低)并在Windows cmd中进行编译。但是,我必须用实际的可执行文件(即gcc3.exe - > gcc.exe,g ++ 3.exe - > g ++。exe)替换Cygwin符号链接,因为Windows cmd不理解符号链接。它还没有给我一个问题,编译Python 3扩展,Cython(甚至按需编译pyximport),swig和嵌入Python。

答案 1 :(得分:0)

This可能有助于从.lib。

生成.a