Estou tentando construir um repositório no meu Ubuntu 16.04 a partir de uma fonte e tudo corre bem até que ele atinja os arquivos vinculados ao OpenCV.
Eu recebo o seguinte erro:
/usr/bin/ld: cannot find -lIlmImf
/usr/bin/ld: cannot find -llibjasper
/usr/bin/ld: cannot find -llibtiff
/usr/bin/ld: cannot find -llibpng
/usr/bin/ld: cannot find -llibjpeg
/usr/bin/ld: cannot find -lzlib
collect2: error: ld returned 1 exit status
Makefile:305: recipe for target 'lib/libmxnet.so' failed
make: *** [lib/libmxnet.so] Error 1
Então, tentei verificar o que o vinculador está realmente fazendo. Eu digitei
ld - llibjpeg --verbose
e obtivemos
attempt to open //usr/local/lib/x86_64-linux-gnu/liblibjpeg.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/liblibjpeg.a failed
attempt to open //lib/x86_64-linux-gnu/liblibjpeg.so failed
attempt to open //lib/x86_64-linux-gnu/liblibjpeg.a failed
attempt to open //usr/lib/x86_64-linux-gnu/liblibjpeg.so failed
attempt to open //usr/lib/x86_64-linux-gnu/liblibjpeg.a failed
attempt to open //usr/local/lib64/liblibjpeg.so failed
attempt to open //usr/local/lib64/liblibjpeg.a failed
attempt to open //lib64/liblibjpeg.so failed
attempt to open //lib64/liblibjpeg.a failed
attempt to open //usr/lib64/liblibjpeg.so failed
attempt to open //usr/lib64/liblibjpeg.a failed
attempt to open //usr/local/lib/liblibjpeg.so failed
attempt to open //usr/local/lib/liblibjpeg.a failed
attempt to open //lib/liblibjpeg.so failed
attempt to open //lib/liblibjpeg.a failed
attempt to open //usr/lib/liblibjpeg.so failed
attempt to open //usr/lib/liblibjpeg.a failed
attempt to open //usr/x86_64-linux-gnu/lib64/liblibjpeg.so failed
attempt to open //usr/x86_64-linux-gnu/lib64/liblibjpeg.a failed
attempt to open //usr/x86_64-linux-gnu/lib/liblibjpeg.so failed
attempt to open //usr/x86_64-linux-gnu/lib/liblibjpeg.a failed
ld: cannot find -llibjpeg
Como vemos, o vinculador não está procurando o arquivo correto! Por outro lado, se eu digitar
ld - ljpeg --verbose
Eu vejo isto:
attempt to open //usr/local/lib/x86_64-linux-gnu/libjpeg.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libjpeg.a failed
attempt to open //lib/x86_64-linux-gnu/libjpeg.so failed
attempt to open //lib/x86_64-linux-gnu/libjpeg.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libjpeg.so succeeded
-ljpeg (//usr/lib/x86_64-linux-gnu/libjpeg.so)
libc.so.6 needed by //usr/lib/x86_64-linux-gnu/libjpeg.so
found libc.so.6 at //lib/x86_64-linux-gnu/libc.so.6
ld-linux-x86-64.so.2 needed by //lib/x86_64-linux-gnu/libc.so.6
found ld-linux-x86-64.so.2 at //lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address
Então a biblioteca libjpeg está lá, o linker está simplesmente procurando por um arquivo errado.
No makefile eu tenho
ifeq ($(USE_OPENCV), 1)
CFLAGS += -DMXNET_USE_OPENCV=1 $(shell pkg-config --cflags opencv)
LDFLAGS += $(filter-out -lopencv_ts, $(shell pkg-config --libs opencv))
BIN += bin/im2rec
E os caminhos indicados pelos scripts de shell pkg-config --cflags opencv
e pkg-config --libs opencv
estão corretos.
Eu ficaria grato por qualquer ajuda com a correção.
EDIT: Eu corro make uninstall
na pasta de código-fonte do OpenCV. Depois disso, a compilação passou com sucesso. Muito estranho, parece que o OpenCV bagunçou os links simbólicos. Eu joguei com os arquivos opencv.pc anteriormente e os caminhos estavam errados ou faltando.