AcademySoftwareFoundation / Imath

Imath is a C++ and python library of 2D and 3D vector, matrix, and math operations for computer graphics
https://imath.readthedocs.io
BSD 3-Clause "New" or "Revised" License
376 stars 113 forks source link

Linker error on building Imath python with Boost Python #271

Open lch32111 opened 1 year ago

lch32111 commented 1 year ago

Hello I'm trying to build python bindings of Imath with Boost.Python. My OS is Windows 10. I built the Boost 1.81 like this

call bootstrap.bat vc143

b2 install -j4 variant=release toolset=msvc ^
    --with-python ^
    --prefix=dist\boost_config_release ^
    --address-model=64 ^
    -d0

The above commands get me include/lib folders which have Boost headers and libraries. For example I get this libboost_python310-vc143-mt-x64-1_81.lib, libboost_numpy310-vc143-mt-x64-1_81.lib.

And then, I build Imath python with cmake commands.

cmake ^
    -S dependency\Imath ^
    -B dependency\Imath\build ^
    -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF ^
    -DCMAKE_INSTALL_PREFIX="dependency\Imath\build\Imath_config_release" ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DPYTHON=ON ^
    -DBoost_ROOT="%cd%\dependency\boost\dist\boost_config_release\lib\cmake\Boost-1.81.0" ^
    -DBoost_NO_BOOST_CMAKE=OFF

cmake --build dependency\Imath\build ^
    --target install ^
    --config Release

However, I get a lot of boost linker errors from PyImath_Python3_10 project. If I give you one error:

PyImathVec4fd.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) prote
cted: __cdecl boost::python::detail::dict_base::dict_base(struct boost::python::detail::bo
rrowed_reference_t *)" (__imp_??0dict_base@detail@python@boost@@IEAA@PEAUborrowed_referenc
e_t@123@@Z) [D:\VisualStudioProject\Project\dependency\Imath\build\src\python\PyIma
th\PyImath_Python3_10.vcxproj]

I don't know what this log is, but I also get this one

Hint on symbols that are defined and could potentially match:
      "__declspec(dllimport) protected: __cdecl boost::python::detail::tuple_base::tuple_b
  ase(class boost::python::api::object const &)" (__imp_??0tuple_base@detail@python@boost@
  @IEAA@AEBVobject@api@23@@Z)
      "__declspec(dllimport) protected: __cdecl boost::python::detail::tuple_base::tuple_b
  ase(void)" (__imp_??0tuple_base@detail@python@boost@@IEAA@XZ)

Can I get any helps for solving this problem? it's very hard for me to figure out what's going on.

meshula commented 1 year ago

I'm afraid I'm not able to test a py310/boost 1.81 combo right now, but I thought it might be helpful to share how I usually investigate problems like this.

I pick a symbol, as you have, and note it's mangled name (_imp??0dict_base@detail@python@boost@@IEAA@PEAUborrowed_referenc e_t@123@@Z)

I then dump the libraries I expect to find that symbol in, using dumpbin /exports somelibrary.dll

and search for the symbol. If it doesn't come up, I pick a "least mangled" bit, such as borrowed_reference_t and see if that shows up.

If it doesn't, then the next avenue of investigation is to work out why that symbol is missing.

If it does, then the next step is to spot if there is a subtle difference in the fully mangled name. Sometimes there will be a single character different, and that often indicates some kind of mismatch between build settings of the library and your program.

Sorry I haven't got anything more specific for you.

lch32111 commented 1 year ago

@meshula

Thank you for your answer!

Okay If I selected wrong versions of the libraries to build it, then it might be a problem.

Can you let me know what the current 'ensured' version combination of libraries(python, Imath, boost, compiler) for building PyImath is? I think it should be documented what version of python/boost libraries should be used to build PyImath.

I don't want to investigate the details of versioning with other libraries.

My configuration is OS : Windows 10 Compiler : MSVC from Visual Studio 2022 Python : python 3.10.2 Boost : I tried 1.81, 1.76, 1.78. But all failed.

I wish there will be a caveat for building PyImath because I spent a few of hours building and end up failing to do this :(

meshula commented 1 year ago

I have a feeling that OpenEXR is not vs2022 ready yet? It is supposed to be compatible though: the combinations that are expected to work, are listed here:

https://vfxplatform.com

The only obvious difference between your configuration and the supported configurations, is boost 1.80 is supported, but boost 1.81 is not.

Could you retest after double checking that you have the same dependency versions as specified in vfxplatform, I think in your case, vfx2023 would be appropriate, because it's the only one with vs2022.

If that doesn't work, my suggestion would be that we rename this issue to "Can't compile vfx2023 on Windows", and we should get it fixed.

As a side note, I wonder if we are able to run test automation for vs2022 yet. I think we aren't currently, which is a problem.

lch32111 commented 1 year ago

I still fail to build pyimath with boost 1.80 version.

I checked the versions of my configuration according to the vfx2023. And only the difference was numpy. My numpy version 1.22.3, and the numpy version of vfx2023 1.23.x. I don't think this numpy version will affect the linker error.

The above command I wrote for building boost does not output dlls. So I added link=shared option for b2.exe like this

b2 install -j4 variant=release toolset=msvc link=shared^
    --with-python ^
    --prefix=dist\boost_config_release ^
    --address-model=64 ^
    -d0

This command outputs dll, lib for the boost.python. And I also tried to build pyimath with these libraies and I failed. I'm still doubting that It's right for me to use this cmake option for building pyimath

-DBoost_ROOT="%cd%\dependency\boost\dist\boost_config_release\lib\cmake\Boost-1.81.0" ^
-DBoost_NO_BOOST_CMAKE=OFF

It's quite hard to build on Windows configuration.

My goal was building pyalembic, but I'm stuck on this. So, unfortunately, I decided to just use '.obj' file extension. I wish the build process for Windows would be easier later.

meshula commented 1 year ago

Thank you for your report. Yes, boost python is challenging to build, there is no question. We hope to move to a simpler system such as pybind11, but that is not started yet.

We do need to be able to build according to the vfx2023 configuration, so hopefully we can get things fixed soon.