Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined::reference error during building from source #63

Closed
ndonyapour opened this issue Feb 6, 2022 · 11 comments
Closed

undefined::reference error during building from source #63

ndonyapour opened this issue Feb 6, 2022 · 11 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@ndonyapour
Copy link

Hello,
I’m trying to build Opemm-torch from source, and I get an undefined reference error. This error happens when I install Pytroch from PyTorch channel via Conda. I believe this error relates to the compiling of OpenMM with the old C++ ABI. I tried installing OpenMM from source with the new C++11 AB, but still, I got the same error.

Environment config:

  • OpenMM7.7.0 from condaforge
  • PyTorch 1.10.2 from pytoch
  • GNU 8.5.0

Commands for compiling Opemm-torch

export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')"
cmake  ..
ccmake -i ..
make install

Error:

[ 36%] Linking CXX executable ../../TestSerializeTorchForce
CMakeFiles/TestSerializeTorchForce.dir/TestSerializeTorchForce.cpp.o: In function `testSerialization()':
TestSerializeTorchForce.cpp:(.text+0x35a): undefined reference to `OpenMM::throwException(char const*, int, std::string const&)'
TestSerializeTorchForce.cpp:(.text+0x447): undefined reference to `OpenMM::throwException(char const*, int, std::string const&)'
TestSerializeTorchForce.cpp:(.text+0x534): undefined reference to `OpenMM::throwException(char const*, int, std::string const&)'
TestSerializeTorchForce.cpp:(.text+0x665): undefined reference to `OpenMM::throwException(char const*, int, std::string const&)'
TestSerializeTorchForce.cpp:(.text+0x77e): undefined reference to `OpenMM::throwException(char const*, int, std::string const&)'
CMakeFiles/TestSerializeTorchForce.dir/TestSerializeTorchForce.cpp.o:TestSerializeTorchForce.cpp:(.text+0x890): more undefined references to `OpenMM::throwException(char const*, int, std::string const&)' follow
CMakeFiles/TestSerializeTorchForce.dir/TestSerializeTorchForce.cpp.o: In function `void OpenMM::XmlSerializer::serialize<TorchPlugin::TorchForce>(TorchPlugin::TorchForce const*, std::string const&, std::ostream&)':
TestSerializeTorchForce.cpp:(.text._ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo[_ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo]+0x66): undefined reference to `OpenMM::SerializationNode::setName(std::string const&)'
TestSerializeTorchForce.cpp:(.text._ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo[_ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo]+0xc9): undefined reference to `OpenMM::SerializationNode::hasProperty(std::string const&) const'
TestSerializeTorchForce.cpp:(.text._ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo[_ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo]+0x100): undefined reference to `OpenMM::SerializationProxy::getTypeName() const'
TestSerializeTorchForce.cpp:(.text._ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo[_ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo]+0x150): undefined reference to `OpenMM::SerializationProxy::getTypeName() const'
TestSerializeTorchForce.cpp:(.text._ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo[_ZN6OpenMM13XmlSerializer9serializeIN11TorchPlugin10TorchForceEEEvPKT_RKSsRSo]+0x18d): undefined reference to `OpenMM::SerializationNode::setStringProperty(std::string const&, std::string const&)'
../../libOpenMMTorch.so: undefined reference to `OpenMM::Platform::createKernel(std::string const&, OpenMM::ContextImpl&) const'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::setBoolProperty(std::string const&, bool)'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::getDoubleProperty(std::string const&) const'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::setIntProperty(std::string const&, int)'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::getIntProperty(std::string const&) const'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationProxy::SerializationProxy(std::string const&)'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::getBoolProperty(std::string const&) const'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::getStringProperty(std::string const&) const'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::getName() const'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::createChildNode(std::string const&)'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::setDoubleProperty(std::string const&, double)'
../../libOpenMMTorch.so: undefined reference to `OpenMM::SerializationNode::getIntProperty(std::string const&, int) const'
collect2: error: ld returned 1 exit status
make[2]: *** [serialization/tests/CMakeFiles/TestSerializeTorchForce.dir/build.make:117: TestSerializeTorchForce] Error 1
make[1]: *** [CMakeFiles/Makefile2:315: serialization/tests/CMakeFiles/TestSerializeTorchForce.dir/all] Error 2
make: *** [Makefile:160: all] Error 2

Any idea?

Thank you.

@raimis raimis added the help wanted Extra attention is needed label Feb 7, 2022
@raimis raimis self-assigned this Feb 7, 2022
@raimis
Copy link
Contributor

raimis commented Feb 7, 2022

OpenMM, like any other package on conda-forge, are built with the new C++11 ABI. The packages from the PyTorch channel are build with the old C++ ABI, so they aren't compatible.

From the error message, I can see that you are building with the old C++ ABI, so I won't link with OpenMM from conda-forge.

@ndonyapour
Copy link
Author

Thank you, this solved my problem. It seems that I've been compiling OpenMM with the new C++11 ABI and setting the CMAKE_FLAGS+=" -D_GLIBCXX_USE_CXX11_ABI=0" flag during compiling fixed the issue.
I just wanted to see if I installed all packages from conda-forge would work because all packages are compiled with the same version of ABI. However, I got the undefined reference linking error again.

Error:

/home/user/anaconda3/envs/foregpkgs/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream()@GLIBCXX_3.4.26'
/home/user/anaconda3/pkgs/openmm-7.7.0-py39h792354b_0/lib/libOpenMM.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()@GLIBCXX_3.4.26'
collect2: error: ld returned 1 exit status
make[2]: *** [serialization/tests/CMakeFiles/TestSerializeTorchForce.dir/build.make:118: TestSerializeTorchForce] Error 1
make[1]: *** [CMakeFiles/Makefile2:315: serialization/tests/CMakeFiles/TestSerializeTorchForce.dir/all] Error 2
make: *** [Makefile:160: all] Error 2

@ndonyapour
Copy link
Author

I hit another error while importing OpenMM (installed from source using -D_GLIBCXX_USE_CXX11_ABI=0). Here is the error, and I can't figure out how to fix it.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmm/__init__.py", line 19, in <module>
    from openmm.openmm import *
  File "/home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmm/openmm.py", line 13, in <module>
    from . import _openmm
ImportError: /home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmm/_openmm.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZN6OpenMM23CustomCentroidBondForce20addTabulatedFunctionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_17TabulatedFunctionE

@ndonyapour
Copy link
Author

I hit another error while importing OpenMM (installed from source using -D_GLIBCXX_USE_CXX11_ABI=0). Here is the error, and I can't figure out how to fix it.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmm/__init__.py", line 19, in <module>
    from openmm.openmm import *
  File "/home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmm/openmm.py", line 13, in <module>
    from . import _openmm
ImportError: /home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmm/_openmm.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZN6OpenMM23CustomCentroidBondForce20addTabulatedFunctionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_17TabulatedFunctionE

I fixed this issue by adding -D_GLIBCXX_USE_CXX11_ABI=0 to extra_compile_args in the setup.py file.

@ndonyapour
Copy link
Author

I apologize for posting multiple messages here. Now, I get an error when I dopython -c "import openmmtorch". I think this one is also related to the C++11 ABI as well.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmmtorch.py", line 15, in <module>
    import _openmmtorch
ImportError: /home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/_openmmtorch.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNK11TorchPlugin10TorchForce22getGlobalParameterNameB5cxx11Ei

@ndonyapour
Copy link
Author

I apologize for posting multiple messages here. Now, I get an error when I dopython -c "import openmmtorch". I think this one is also related to the C++11 ABI as well.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/openmmtorch.py", line 15, in <module>
    import _openmmtorch
ImportError: /home/user/anaconda3/envs/fltop/lib/python3.9/site-packages/_openmmtorch.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZNK11TorchPlugin10TorchForce22getGlobalParameterNameB5cxx11Ei

I was able to fix this issue by compiling the plugin code with -D_GLIBCXX_USE_CXX11_ABI=0 and adding this flag to its setup.py file. I was wondering if this is the right way to resolve this issue?

@raimis
Copy link
Contributor

raimis commented Feb 8, 2022

Provided you build all the components with the old C++ ABI, it should work.

@ndonyapour
Copy link
Author

Thank you, this solved my problem. It seems that I've been compiling OpenMM with the new C++11 ABI and setting the CMAKE_FLAGS+=" -D_GLIBCXX_USE_CXX11_ABI=0" flag during compiling fixed the issue. I just wanted to see if I installed all packages from conda-forge would work because all packages are compiled with the same version of ABI. However, I got the undefined reference linking error again.

Error:

/home/user/anaconda3/envs/foregpkgs/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream()@GLIBCXX_3.4.26'
/home/user/anaconda3/pkgs/openmm-7.7.0-py39h792354b_0/lib/libOpenMM.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()@GLIBCXX_3.4.26'
collect2: error: ld returned 1 exit status
make[2]: *** [serialization/tests/CMakeFiles/TestSerializeTorchForce.dir/build.make:118: TestSerializeTorchForce] Error 1
make[1]: *** [CMakeFiles/Makefile2:315: serialization/tests/CMakeFiles/TestSerializeTorchForce.dir/all] Error 2
make: *** [Makefile:160: all] Error 2

Ok, thanks! Any suggestions about this one?

@raimis
Copy link
Contributor

raimis commented Feb 8, 2022

Looks your are linking OpenMM and PyTorch with the new C++ ABI; and the C++ runtime (libstdc++.so), which doesn't support the new C++ ABI.

@ndonyapour
Copy link
Author

I have updated GNU from 8.5 to 11.2 and Cudatoolkit from 11.3 to 11.6 and still getting the linker error.

@ndonyapour
Copy link
Author

I found two methods for fixing the linker errors coming from the C++11 ABI:

1- Install PyTorch from source which sets -D_GLIBCXX_USE_CXX11_ABI=1 and then get other packages from Conda-forge, finally you can build openmm-torch

2- Create a conda virtual environment from the yml file I uploaded here and follow the commands below for building and installing openmm-torch

conda env create -n optorchenv -f environment.yml
conda activate optorchenv 
git clone https://github.com/openmm/openmm-torch.git
cd openmm-torch
mkdir build && cd build
export Torch_DIR="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')"
cmake .. 
ccmake -i .. (set the paths)
make install
make PythonInstall

openmm-torch_env.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants