openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.83k stars 810 forks source link

Window compilation issue. LNK1181 error #685

Open spyroot opened 2 years ago

spyroot commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

I think there is some issue when compiling under the window

I'm using the MSVC console.

LINK : warning LNK4044: unrecognized option '/fopenmp'; ignored LINK : fatal error LNK1181: cannot open input file 'mujoco210.lib' error: command 'D:\dev\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\link.exe' failed with exit code 1181

To Reproduce Steps to reproduce the behavior.

Expected behavior A clear and concise description of what you expected to happen.

Open VC Console. conda activate env_name

set MUJOCO_PY_MUJOCO_PATH=C:\Users\X.mujoco\mujoco210 set PATH=C:\Users\X.mujoco\mujoco210;%PATH%

clone repo python setup.py build

LINK : warning LNK4044: unrecognized option '/fopenmp'; ignored LINK : fatal error LNK1181: cannot open input file 'mujoco210.lib' error: command 'D:\dev\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\link.exe' failed with exit code 1181

Error Messages Including more/longer error messages gives us more information to work with.

(X) c:\mujoco-py>python setup.py build running build Removing old mujoco_py cext c:\mujoco-py\mujoco_py\generated\cymj_2.1.2.14_38_windowsextensionbuilder_38.so running build_ext building 'mujoco_py.cymj' extension cl : Command line warning D9025 : overriding '/W3' with '/w' cl : Command line warning D9002 : ignoring unknown option '-fopenmp' dummyshim.c cl : Command line warning D9025 : overriding '/W3' with '/w' cl : Command line warning D9002 : ignoring unknown option '-fopenmp' cymj.c C:\Users\X\anaconda3\envs\X\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION LINK : warning LNK4044: unrecognized option '/fopenmp'; ignored LINK : fatal error LNK1181: cannot open input file 'mujoco210.lib' error: command 'D:\dev\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\link.exe' failed with exit code 1181

Desktop (please complete the following information):

Environment

VC related

VCIDEInstallDir=D:\dev\Common7\IDE\VC\ VCINSTALLDIR=D:\dev\VC\ VCToolsInstallDir=D:\dev\VC\Tools\MSVC\14.29.30133\ VCToolsRedistDir=D:\dev\VC\Redist\MSVC\14.29.30133\ VCToolsVersion=14.29.30133 VisualStudioVersion=16.0 VS160COMNTOOLS=D:\dev\Common7\Tools\ VSCMD_ARG_app_plat=Desktop VSCMD_ARG_HOST_ARCH=x86 VSCMD_ARG_TGT_ARCH=x86 VSCMD_VER=16.11.10 VSINSTALLDIR=D:\dev\

Path=C:\Users\X.mujoco\mujoco210; MUJOCO_PY_MUJOCO_PATH=C:\Users\X.mujoco\mujoco210

Conda and the rest

CommandPromptType=Native CommonProgramFiles=C:\Program Files\Common Files CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files CommonProgramW6432=C:\Program Files\Common Files COMPUTERNAME=X ComSpec=C:\WINDOWS\system32\cmd.exe CONDA_DEFAULT_ENV=X CONDA_EXE=C:\Users\X\anaconda3\Scripts\conda.exe CONDA_PREFIX=C:\Users\X\anaconda3\envs\X CONDA_PROMPT_MODIFIER=(X) CONDA_PYTHON_EXE=C:\Users\X\anaconda3\python.exe CONDA_SHLVL=1

Additional context Add any other context about the problem here.

I think somewhere the path to the lib file doesn't resolve correctly or maybe something different.

LINK : warning LNK4044: unrecognized option '/fopenmp'; ignored LINK : fatal error LNK1181: cannot open input file 'mujoco210.lib' error: command 'D:\dev\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\link.exe' failed with exit code 1181

First I think for VC it must /openmp https://docs.microsoft.com/en-us/cpp/build/reference/openmp-enable-openmp-2-0-support?view=msvc-170 But it was ignored anyway.

So the root cause LINK: fatal error LNK1181: cannot open input file 'mujoco210.lib'

spyroot commented 2 years ago

Note if I add Lib and indicate direct path (mujoco) like

set LIB=C:\Users\X.mujoco\mujoco210\Lib;%LIB%

I get a million unresolved

LINK : warning LNK4044: unrecognized option '/fopenmp'; ignored Creating library c:\mujoco-py\mujoco_py\generated_pyxbld_2.1.2.14_38_windowsextensionbuilder\temp.win32-3.8\Release\mujoco-py\mujoco_py/gl\cymj.cp38-win_amd64.lib and object c:\mujoco-py\mujoco_py\generated_pyxbld_2.1.2.14_38_windowsextensionbuilder\temp.win32-3.8\Release\mujoco-py\mujoco_py/gl\cymj.cp38-win_amd64.exp cymj.obj : error LNK2001: unresolved external symbol impmj_referenceConstraint cymj.obj : error LNK2001: unresolved external symbol impmj_integratePos cymj.obj : error LNK2001: unresolved external symbol impmj_deleteVFS cymj.obj : error LNK2001: unresolved external symbol impmj_jac cymj.obj : error LNK2001: unresolved external symbol impmj_rnePostConstraint cymj.obj : error LNK2001: unresolved external symbol impmj_setConst cymj.obj : error LNK2001: unresolved external symbol impmju_insertionSortInt cymj.obj : error LNK2001: unresolved external symbol impPyUnicode_AsEncodedString cymj.obj : error LNK2001: unresolved external symbol impmjv_initPerturb cymj.obj : error LNK2001: unresolved external symbol impmj_version cymj.obj : error LNK2001: unresolved external symbol impPyFrozenSet_Type cymj.obj : error LNK2001: unresolved external symbol impmj_activate

spyroot commented 2 years ago

folks I complied by hand by can you tell me how I can overwrite -fopenmp

In Extension Builder

        extra_compile_args=[
            '-fopenmp',  # needed for OpenMP # in case of window /openmp
            '-w',  # suppress numpy compilation warnings / no need that
        ],

class MujocoExtensionBuilder():

CYMJ_DIR_PATH = abspath(dirname(__file__))

def __init__(self, mujoco_path):
    self.mujoco_path = mujoco_path
    python_version = str(sys.version_info.major) + str(sys.version_info.minor)
    self.version = '%s_%s_%s' % (get_version(), python_version, self.build_base())
    self.extension = Extension(
        'mujoco_py.cymj',
        sources=[join(self.CYMJ_DIR_PATH, "cymj.pyx")],
        include_dirs=[
            self.CYMJ_DIR_PATH,
            join(mujoco_path, 'include'),
            np.get_include(),
        ],
        libraries=['mujoco210'],
        library_dirs=[join(mujoco_path, 'bin')],
        extra_compile_args=[
            '-fopenmp',  # needed for OpenMP
            '-w',  # suppress numpy compilation warnings
        ],
        extra_link_args=['-fopenmp'],
        language='c')
spyroot commented 2 years ago

I added a pull request it fixes window compilation issues with the visual studio https://github.com/openai/mujoco-py/pull/686