unable to load shared object - opencv

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

unable to load shared object - opencv

niandra
Hi all

i'm trying to use the opencv's function into R.

i wrote a simple script, just for try to understand how use c++ in R, it loads an image and write it with a different name (i know it ), and then write "Hello, World". The file is names prova2.cpp (is the first time i try to use c++ )

#include <stdio.h>
#include <opencv/cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/highgui.h>
#include <opencv/cv.h> 
#include <R.h>
#include <Rinternals.h>

extern "C" SEXP provaR(void) {
cv::Mat gravit;
gravit=cv::imread("imm.jpg");
cv::imwrite("imm_dop.jpg",gravit);
Rprintf("Hello, World!nn");
return R_NilValue;
}

Now in the terminal  i type R CMD SHLIB  prova2.cpp to create the file prova2.so and this happen without error.

In R i type dyn.load("prova2.so") and get this error:

Errore in dyn.load("prova2.so") :
  unable to load shared object '/Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so':
  dlopen(/Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so, 6): Symbol not found: __ZN2cv11_InputArrayC1ERKNS_3MatE
  Referenced from: /Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so
  Expected in: flat namespace
 in /Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so

I understand that the problem is because i should tell R where to find the opencv library, but i really don't know how do it.




Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

Simon Urbanek

On Nov 8, 2012, at 3:19 PM, niandra wrote:

> Hi all
>
> i'm trying to use the opencv's function into R.
>
> i wrote a simple script, just for try to understand how use c++ in R, it
> loads an image and write it with a different name (i know it ), and then
> write "Hello, World". The file is names prova2.cpp (is the first time i try
> to use c++ )
>
> #include <stdio.h>
> #include <opencv/cv.h>
> #include <opencv2/core/core.hpp>
> #include <opencv2/highgui/highgui.hpp>
> #include <opencv/highgui.h>
> #include <opencv/cv.h>
> #include <R.h>
> #include <Rinternals.h>
>
> extern "C" SEXP provaR(void) {
> cv::Mat gravit;
> gravit=cv::imread("imm.jpg");
> cv::imwrite("imm_dop.jpg",gravit);
> Rprintf("Hello, World!nn");
> return R_NilValue;
> }
>
> Now in the terminal  i type R CMD SHLIB  prova2.cpp to create the file
> prova2.so and this happen without error.
>
> In R i type dyn.load("prova2.so") and get this error:
>
> Errore in dyn.load("prova2.so") :
>  unable to load shared object
> '/Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so':
>
> dlopen(/Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so,
> 6): Symbol not found: __ZN2cv11_InputArrayC1ERKNS_3MatE
>  Referenced from:
> /Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so
>  Expected in: flat namespace
> in /Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so
>
> I understand that the problem is because i should tell R where to find the
> opencv library, but i really don't know how do it.
>

add the necessary -l flags (see your configuration or pkgconfig) to R CMD SHLIB

Cheers,
S


>
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/unable-to-load-shared-object-opencv-tp4648958.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

niandra
In reply to this post by niandra
Sorry but i'm really a beginner.

If when i use opencv with Xcode i need to set the following path
/System/Library/Frameworks
/usr/local/include
/usr/local/lib

how can i specify this in  R CMD SHLIB?
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

niandra
In reply to this post by Simon Urbanek
Edit

i try to use this comman in terminal:
R CMD SHLIB  prova2.cpp -l/usr/local/lib -l/usr/local/include -l/System/Library/Frameworks  and gave me this error

g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o prova2.so prova2.o -l/usr/local/lib -l/usr/local/include -l/System/Library/Frameworks -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: library not found for -l/usr/local/lib
collect2: ld returned 1 exit status
make: *** [prova2.so] Error 1

Then when i use dyn.load("prova2.so") i get

Errore in dyn.load("prova2.so") :
  unable to load shared object '/Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so':
  dlopen(/Users/niandra/Desktop/statistico/r/builtpack/ProvaScript/prova2.so, 6): image not found
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

Dirk Eddelbuettel

On 8 November 2012 at 12:53, niandra wrote:
| Edit
|
| i try to use this comman in terminal:
| R CMD SHLIB  prova2.cpp -l/usr/local/lib -l/usr/local/include
| -l/System/Library/Frameworks  and gave me this error

You may want to go back to some introduction to Unix and its toolchains and
revisit the differences between

    -I

    -L

    -l

They may look the same, especially with a typewriter font, but trust me that
they are not.

Dirk

--
Dirk Eddelbuettel | [hidden email] | http://dirk.eddelbuettel.com

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

niandra
Yes i know, i need to study.

i'm trying to understand all this stuff, i never use c++ or Unix.
G.M.


Il giorno 08/nov/2012, alle ore 22:58, Dirk Eddelbuettel <[hidden email]> ha scritto:

>
> On 8 November 2012 at 12:53, niandra wrote:
> | Edit
> |
> | i try to use this comman in terminal:
> | R CMD SHLIB  prova2.cpp -l/usr/local/lib -l/usr/local/include
> | -l/System/Library/Frameworks  and gave me this error
>
> You may want to go back to some introduction to Unix and its toolchains and
> revisit the differences between
>
>    -I
>
>    -L
>
>    -l
>
> They may look the same, especially with a typewriter font, but trust me that
> they are not.
>
> Dirk
>
> --
> Dirk Eddelbuettel | [hidden email] | http://dirk.eddelbuettel.com 

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

Simon Urbanek
In reply to this post by niandra

On Nov 8, 2012, at 3:34 PM, niandra wrote:

> Sorry but i'm really a beginner.
>
> If when i use opencv with Xcode i need to set the following path
> /System/Library/Frameworks
> /usr/local/include
> /usr/local/lib
>
> how can i specify this in  R CMD SHLIB?
>

Those are essentially default so no need to specify any of those. The real thing you need to specify are the actual libraries to link against, typically something like -lopencv_core ... If you use a framework it may be just something like -framework OpenCV - we don't know since you didn't tell us what your'e really using.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

niandra
Ok, sorry.

I need the library libopencv_core.2.4.0.dylib and libopencv_highgui.2.4.0.dylib.

Thanks
G.M.



Il giorno 09/nov/2012, alle ore 01:09, Simon Urbanek <[hidden email]> ha scritto:

>
> On Nov 8, 2012, at 3:34 PM, niandra wrote:
>
>> Sorry but i'm really a beginner.
>>
>> If when i use opencv with Xcode i need to set the following path
>> /System/Library/Frameworks
>> /usr/local/include
>> /usr/local/lib
>>
>> how can i specify this in  R CMD SHLIB?
>>
>
> Those are essentially default so no need to specify any of those. The real thing you need to specify are the actual libraries to link against, typically something like -lopencv_core ... If you use a framework it may be just something like -framework OpenCV - we don't know since you didn't tell us what your'e really using.
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: unable to load shared object - opencv

niandra
In reply to this post by Simon Urbanek
Thanks to all, now this problem is solved

G.M.


Il giorno 09/nov/2012, alle ore 01:09, Simon Urbanek <[hidden email]> ha scritto:

>
> On Nov 8, 2012, at 3:34 PM, niandra wrote:
>
>> Sorry but i'm really a beginner.
>>
>> If when i use opencv with Xcode i need to set the following path
>> /System/Library/Frameworks
>> /usr/local/include
>> /usr/local/lib
>>
>> how can i specify this in  R CMD SHLIB?
>>
>
> Those are essentially default so no need to specify any of those. The real thing you need to specify are the actual libraries to link against, typically something like -lopencv_core ... If you use a framework it may be just something like -framework OpenCV - we don't know since you didn't tell us what your'e really using.
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel