bnosac / dlib

allowing R users to work with dlib through Rcpp
13 stars 2 forks source link

undefined symbol: _ZN4dlib6base64D1Ev #3

Open artemklevtsov opened 5 years ago

artemklevtsov commented 5 years ago

Hello,

Thanks for the package.

I tried to use this package to face detection, but it does not works as expected:

I use very simple example:

// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::depends(dlib)]]

#include <Rcpp.h>
#include <iostream>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_io.h>

using namespace Rcpp;

//' @title Detect face
//'
//' @param file Path to image file
//'
//' @export
//'
// [[Rcpp::export]]
void face_detect(std::string file) {
    dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();

    dlib::array2d<unsigned char> img;
    dlib::load_image(img, file);

    std::vector<dlib::rectangle> dets = detector(img);

    std::cout << "Number of faces detected: " << dets.size() << std::endl;
}

And Makevars:

CXX_STD = CXX11 
PKG_CPPFLAGS = -DENABLE_ASSERTS
PKG_LIBS = -lpthread -lX11

My installation output below:

> devtools::install()
✔  checking for file ‘/home/xxx/projects/R/packages/RFace/DESCRIPTION’ ...
─  preparing ‘RFace’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
   Removed empty directory ‘RFace/inst/extdata’
   Removed empty directory ‘RFace/inst’
   Removed empty directory ‘RFace/man’
─  building ‘RFace_0.1.0.tar.gz’

Running /usr/lib64/R/bin/R CMD INSTALL /tmp/Rtmp7mY9II/RFace_0.1.0.tar.gz --install-tests 
* installing to library ‘/home/xxx/R/x86_64-pc-linux-gnu-library/3.5’
* installing *source* package ‘RFace’ ...
** libs
clang++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -DENABLE_ASSERTS -I"/home/xxx/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I"/home/xxx/R/x86_64-pc-linux-gnu-library/3.5/dlib/include" -D_FORTIFY_SOURCE=2   -fpic  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -c RcppExports.cpp -o RcppExports.o
clang++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -DENABLE_ASSERTS -I"/home/xxx/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I"/home/xxx/R/x86_64-pc-linux-gnu-library/3.5/dlib/include" -D_FORTIFY_SOURCE=2   -fpic  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -c face_detection.cpp -o face_detection.o
clang++ -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o RFace.so RcppExports.o face_detection.o -lpthread -lX11 -L/usr/lib64/R/lib -lR
installing to /home/xxx/R/x86_64-pc-linux-gnu-library/3.5/RFace/libs
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package  ‘RFace’ 
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘RFace’ in dyn.load(file, DLLpath = DLLpath, ...):
 не могу загрузить разделяемый объект '/home/xxx/R/x86_64-pc-linux-gnu-library/3.5/RFace/libs/RFace.so':
  /home/xxx/R/x86_64-pc-linux-gnu-library/3.5/RFace/libs/RFace.so: undefined symbol: _ZN4dlib6base64D1Ev
Ошибка: загрузка не удалась
Выполнение остановлено
ERROR: loading failed
* removing ‘/home/xxx/R/x86_64-pc-linux-gnu-library/3.5/RFace’

Should I compile dlib and link with it? How can I do it using this package?

artemklevtsov commented 5 years ago

Tried to install dlib to my OS and use the following Makevars:

CXX_STD = CXX11 
PKG_CPPFLAGS = -I /usr/include -DDLIB_NO_GUI_SUPPORT -DENABLE_ASSERTS
PKG_LIBS = -lpthread -ldlib -ljpeg -lpng -ltiff -lgif

Now example works but I want to do it with the dlib from CRAN.

jwijffels commented 5 years ago

Have you looked at the example at https://github.com/bnosac/image/tree/master/image.dlib There it is used to get the HOG and SURF descriptors of points in the image. The dlib on CRAN is dlib 19.2 I think you need to add PKG_CPPFLAGS = -DSTRICT_R_HEADERS and also make sure you don't copy-paste code from an example of a newer version of dlib. The error seems to be indicating it hasn't find some functionality from dlib.

artemklevtsov commented 5 years ago

Thank you for the reply. I'll try your suggestion. Can you compile the above code?

artemklevtsov commented 5 years ago

Dlib 19.2 is out in oct 2016. Do you plan upgrade it in the CRAN package?

jwijffels commented 5 years ago

I'll start working back again on some image recognition software in February. It's on my list.

jeffreyhanson commented 4 years ago

Hi, I was just wondering if you were still planning on updating the version of dlib on CRAN?

jwijffels commented 4 years ago

Last time I tried to push to CRAN with an update, I had to include all authors of dlib sources in the DESCRIPTION/LICENSE.note/COPYRIGHT. That was a bit too much to inspect all the headers / cpp files manually and one by one add these. Feel free to make a pull request if you want to do this.

If you want to try out dlib. I suggest you take package at https://github.com/bnosac/image/tree/master/image.dlib, remove the https://github.com/bnosac/image/blob/master/image.dlib/.Rbuildignore file and put your code in the src folder. That package is now using dlib-19.20 (released on june 6, 2020). It also shows how to pass images directly to the dlib format from R (if you are working on images). Good luck.

jeffreyhanson commented 4 years ago

Thank you very much for the fast response @jwijffels! Yeah, that would be a pain. I'm looking to do some box-constrained non-linear optimization, so I think I'll use the nloptr R package instead of playing around with dlib sources.