Skip to content

build error in ubuntu with libpng #2392

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

Closed
maminus opened this issue Jul 4, 2020 · 2 comments · Fixed by #2398
Closed

build error in ubuntu with libpng #2392

maminus opened this issue Jul 4, 2020 · 2 comments · Fixed by #2398

Comments

@maminus
Copy link

maminus commented Jul 4, 2020

🐛 Bug

I tried to build torchvision package.
I found build error at linking image.so.

To Reproduce

Steps to reproduce the behavior:

$ git clone https://github.com/pytorch/vision.git
$ cd vision
$ python setup.py install

And error message.

g++ -pthread -shared -B /opt/conda/compiler_compat -L/opt/conda/lib -Wl,-rpath=/opt/conda/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/data/python3.6/vision/torchvision/csrc/cpu/image/image.o build/temp.linux-x86_64-3.6/data/python3.6/vision/torchvision/csrc/cpu/image/readpng_cpu.o -Llibpng-config: --libdir option is disabled in Debian/Ubuntu -L/var/lib/jenkins/.local/lib/python3.6/site-packages/torch/lib -L/opt/rocm/lib -lpng -lc10 -ltorch -ltorch_cpu -ltorch_python -lc10_hip -ltorch_hip -o build/lib.linux-x86_64-3.6/torchvision/image.so
g++: error: option: No such file or directory
g++: error: is: No such file or directory
g++: error: disabled: No such file or directory
g++: error: in: No such file or directory
g++: error: Debian/Ubuntu: No such file or directory
g++: error: unrecognized command line option ‘--libdir’; did you mean ‘--dumpdir’?
error: command 'g++' failed with exit status 1

g++ option -Llibpng-config: --libdir option is disabled in Debian/Ubuntu is wrong.

Expected behavior

-L option is correct libpng library path.

Root Cause & Environment

Now, setup.py is using libpng-config command with --libdir option, but it is disabled in Debian/Ubuntu.

$ libpng-config --libdir
libpng-config: --libdir option is disabled in Debian/Ubuntu

I tried rocm/pytorch:rocm3.5_ubuntu18.04_py3.6 docker image, but I think it reproduce in normal Ubuntu18.04.

$ python -m torch.utils.collect_env
Collecting environment information...
PyTorch version: 1.7.0a0+f083cea
Is debug build: No
CUDA used to build PyTorch: Could not collect

OS: Ubuntu 18.04.4 LTS
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
CMake version: version 3.14.0

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] numpy==1.18.1
[pip] torch==1.7.0a0+f083cea
[pip] torchvision==0.8.0a0+75f5b57
[conda] blas                      1.0                         mkl  
[conda] mkl                       2020.1                      217  
[conda] mkl-include               2020.1                      217  
[conda] mkl-service               2.3.0            py36he904b0f_0  
[conda] mkl_fft                   1.0.15           py36ha843d7b_0  
[conda] mkl_random                1.1.1            py36h0573a6f_0  
[conda] numpy                     1.18.1           py36h4f9e942_0  
[conda] numpy-base                1.18.1           py36hde5b4d6_1  
[conda] torchvision               0.8.0a0+75f5b57          pypi_0    pypi
  • torch : master branch
  • torchvision : master branch

Additional context

--L_opts option is enabled instead, but it's empty path in my environment.

So I tried to following patch, then build is succeeded.

diff --git a/setup.py b/setup.py
index 01276f1..e95137f 100644
--- a/setup.py
+++ b/setup.py
@@ -262,14 +262,21 @@ def get_extensions():
             png_version = parse_version(png_version)
             if png_version >= parse_version("1.6.0"):
                 print('Building torchvision with PNG image support')
-                png_lib = subprocess.run([libpng, '--libdir'],
+                help_result = subprocess.run([libpng, '--help'],
+                                         stdout=subprocess.PIPE)
+                lib_opt = '--libdir'
+                if '--L_opts' in help_result.stdout.decode('utf-8'):
+                    lib_opt = '--L_opts'
+                png_lib = subprocess.run([libpng, lib_opt],
                                          stdout=subprocess.PIPE)
                 png_include = subprocess.run([libpng, '--I_opts'],
                                              stdout=subprocess.PIPE)
                 png_include = png_include.stdout.strip().decode('utf-8')
                 _, png_include = png_include.split('-I')
                 print('libpng include path: {0}'.format(png_include))
-                image_library += [png_lib.stdout.strip().decode('utf-8')]
+                png_lib = png_lib.stdout.strip().decode('utf-8')
+                if png_lib:
+                    image_library += [png_lib]
                 image_include += [png_include]
                 image_link_flags.append('png')
             else:
@fmassa
Copy link
Member

fmassa commented Jul 6, 2020

Thanks for opening this issue!

cc @andfoy can you have a look?

@andfoy
Copy link
Contributor

andfoy commented Jul 6, 2020

@maminus, could you please check if #2398 fixes this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants