Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Python and error LNK1104: cannot open file 'boost_python-vc100-mt-gd-1_55.lib'

I'm trying to follow this tutorial on embedding Python into a C++ application, and am hitting a roadblock right from the beginning. Let me take you through it...

  1. I extract the boost library to C:\codelibraries\c++\boost_1_55_0
  2. I creat a new project in VC+++ and create a 'test1.cpp' file in it with the following code:

    #include <boost/python.hpp>
    
    int main(int, char**) {
     Py_Initialize();
    
     Py_Finalize();
     return 0;
    }
    
  3. I then place the following directories in my VC++ Directories > Include Directories:
    • C:\codelibraries\c++\boost_1_55_0
    • C:\codelibraries\c++\boost_1_55_0\boost\python
    • C:\Python27\include
  4. In my VC++ Directories > Library Directories:
    • C:\codelibraries\c++\boost_1_55_0
    • C:\codelibraries\c++\boost_1_55_0\libs
    • C:\Python27\libs
  5. And in my VC++ Directories > Source Directories:
    • C:\Python27\include
    • C:\codelibraries\c++\boost_1_55_0

After adding these and running it, I am given error LNK1104: cannot open file 'boost_python-vc100-mt-gd-1_55.lib'.

Okay, turns out that I need to actually install the boost library. Fine. I do so. It creates the new folder '..\boost_1_55_0\stage\lib.' Inside it, there is the library file called libboost_python-vc100-mt-gd-1_55.lib and another one that's very similar but excludes the 'gd' portion.

Under 'Linker' > 'General' > 'Additional Library Directories', I added C:\codelibraries\c++\boost_1_55_0\stage\lib. I run it again. still it gives the same linker error LNK1104: cannot open file 'boost_python-vc100-mt-gd-1_55.lib'. I go to the 'stage\lib' folder and see that there is no boost_python-vc100-mt-gd-1_55.lib, only *lib*boost_python-vc100-mt-gd-1_55.lib.

I rename libboost_python-vc100-mt-gd-1_55.lib to boost_python-vc100-mt-gd-1_55.lib and rerun the build.

It succeeds, but gives me other linker errors:

error LNK1120: 3 unresolved externals
error LNK2001: unresolved external symbol __imp___Py_NoneStruct
error LNK2019: unresolved external symbol __imp__Py_Finalize referenced in function _main
error LNK2019: unresolved external symbol __imp__Py_Initialize referenced in function _main

And now I'm stuck and have come here. Are the few lines of code I have written incorrect? Does it have anything to do with my using a 64-bit machine? Are my includes incorrect? Please help if you can. Any information is greatly appreciated, thank you.

like image 904
akappel Avatar asked May 25 '26 17:05

akappel


2 Answers

I'm returning to this question as I do not want to leave it unanswered. It turns out the issue was attempting to use a 64-bit implementation of Python with a 32-bit version of the boost libraries. After switching to 32-bit Python, things got a lot easier. If you do not have to use 64-bit Python, I would recommend against it.

like image 124
akappel Avatar answered May 28 '26 07:05

akappel


In my case, there are only .lib files begin with libboost* rather than boost* in stage/lib. So I have to go to download the binaries from http://boost.teeks99.com/ which have all libboost*.lib, boost*.lib and boost*.dll versions and add the boost*.lib and boost*.dll to stage\lib library in order for it to work.

like image 29
bignano Avatar answered May 28 '26 07:05

bignano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!