简体   繁体   中英

A linker error of Boost.Python in Visual Studio 2008

My english is very poor, so I appreciate if you try to understand my question.



I have Python3.3 , Boost 1.50.0 and visual studio 2008 installed, and all of them work fine.

Now I want to embed python 2.7.6 in C++ by using Boost Python library,so I downloaded Portable Python 2.7.6.1 ( from portablepython.com/).

And I downloaded Boost lib. 1.50.0 again, extract them into another path, compiled them by following the building tutorial.

Everything seem alright, but when I tried to compile my code, I got a linker error.

Error LNK1104 cannot open file 'python32.lib'

I have no idea why it was not 'python27.lib'

I am confused, because I never install Python3.2, and I have modified user-config.jam to make sure that all paths has been redirect to my Portable Python(2.7) folders,and the new Boost library were successfully built without error.

I have been trying to solve the problem for a few weeks, using lots of ways , but it still doesn't work


All the things I have done are :

  1. Download Boost C++ library (boost_1_50_0.7z from www.boost.org/users/history/version_1_50_0.html)

  2. Extract them into my boost root path( D:\\Proj\\ThirdPartyLib\\boost_1_50_0 )

  3. Download Portable Python 2.7.6.1 ( from portablepython.com/wiki/PortablePython2.7.6.1/ )

  4. Extract them into D:\\Py27Test

  5. Modify user-config.jam , add the following text and save it into D:\\Proj\\ThirdPartyLib\\boost_1_50_0\\

    using python : 2.7 : "D:\\Py27Test\\App" : "D:\\Py27Test\\App\\include" : "D:\\Py27Test\\App\\libs" : ;

  6. Execute Visual Studio Command Prompt (x86)

    1. cd /DD:\\Proj\\ThirdPartyLib\\boost_1_50_0
    2. bootstrap
    3. bjam --toolset=msvc-9.0 --python=2.7 --user-config=D:\\Proj\\ThirdPartyLib\\boost_1_50_0\\user-config.jam --debug-configuration

      the debug infomations are:

      notice: [python-cfg] Configuring python...

      notice: [python-cfg] user-specified version: "2.7"

      notice: [python-cfg] Checking interpreter command "python"...

      notice: [python-cfg] running command 'DIR /-C /A:S "D:\\Py27Test\\App\\python.exe" 2>&1'

      notice: [python-cfg] running command '"python" -c "from sys import *; print('version=%d.%d\\nplatform=%s\\nprefix=%s\\nexec_prefix=%s\\nexecutable=%s' % (version_info[0],version_info[1],platform,prefix,exec_prefix,executable))" 2>&1'

      notice: [python-cfg] ...requested configuration matched!

      notice: [python-cfg] Details of this Python configuration:

      notice: [python-cfg] interpreter command: "python"

      notice: [python-cfg] include path: "D:\\Py27Test\\App\\include"

      notice: [python-cfg] library path: "D:\\Py27Test\\App\\libs"

      notice: [python-cfg] DLL search path: "D:\\Py27Test\\App"

  7. Execute Visual Studio 2008

    1. Add D:\\Proj\\ThirdPartyLib\\boost_1_50_0 to compiler include paths
    2. Add D:\\Proj\\ThirdPartyLib\\boost_1_50_0\\stage\\lib to linker library paths
  8. create a testing code:

 #define BOOST_PYTHON_STATIC_LIB #include <boost/python.hpp> #include <iostream> int main(int argc, char** argv) { return 0; } 
  1. Complie the code and I would get a linker error ( Error LNK1104 cannot open file 'python32.lib' )

Did I miss something?

Or does anyone has any idea to solve this problem?

Thanks in advance

Finally, I solved this problem.

  1. Add D:\\Py27Test\\App\\include to compiler include paths
  2. Add D:\\Py27Test\\App\\libs to linker library paths

Seems like if I don't include Python.h, it will link to a default library file. So after I added those paths, it works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM