raulzito234

A nerd blog about cs

Month: April, 2013

Problem loading a dynamic library

After linking all the libraries and set pathnames I ran the compiled version of the code and I started getting the following error:

dyld: Library not loaded: /opt/local/lib/libtiff.5.dylib
Referenced from: /opt/local/lib/libopencv_highgui.2.4.dylib
Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0
Trace/BPT trap: 5

The error is that the library that is being referenced libtiff (or the tiff library) is old and needs to be updated. There are some few tricks that helped me solve the problem, first I use the following code:

http://trac.macports.org/ticket/15554

But instead of png I awas looking for the tiff library, thus I used the following code:

>> sudo port installed | grep tiff

 

For loading the libraries I have set the path of the dynamic libraries using the variable:

DYLD_LIBRARY_PATH

The DYLD_LIBRARY_PATH path in my case was set to be

:/Applications/matlab/MATLAB_Compiler_Runtime/v81/runtime/maci64/:/Applications/matlab/MATLAB_Compiler_Runtime/v81/sys/os/maci64/:/Applications/matlab/MATLAB_Compiler_Runtime/v81/sys/os/maci64/:/Applications/matlab/MATLAB_Compiler_Runtime/v81/bin/maci64/:/Users/giu/Documents/GRobot/Code/video/lib/

where

/Applications/matlab/MATLAB_Compiler_Runtime 

is the <mcr_installed> path.

But when I set the DYLD_LIBRARY_PATH I get the following error:

dyld: Symbol not found: __ZTIN2cv16ParallelLoopBodyE
Referenced from: /opt/local/lib/libopencv_superres.2.4.dylib
Expected in: /Applications/matlab/MATLAB_Compiler_Runtime/v81/bin/maci64//libopencv_core.2.4.dylib
in /opt/local/lib/libopencv_superres.2.4.dylib

 

I imagine that there is some function that is called inside the library libopencv and it is not found.

It might be that the library that I install or link does not have the function that it’s required or has another name.

Solution:

The solution for the problem can be found here:

https://raulzito234.wordpress.com/2013/05/02/dynamic-libraries-and-make-install/

Take a look at:  

http://stackoverflow.com/questions/13252852/dyld-symbol-not-found-jpeg-resync-to-restart

http://comments.gmane.org/gmane.os.apple.macports.user/22154

Edit:
In the installation process, it’s advised to do the following:

On the target computer, append the following to your DYLD_LIBRARY_PATH environment variable:

/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/runtime/maci64:/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/sys/os/maci64:/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/bin/maci64:/System/Library/Frameworks/JavaVM.framework/JavaVM:/System/Library/Frameworks/JavaVM.framework/Libraries

Next, set the XAPPLRESDIR environment variable to the following value:

/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/X11/app-defaults

Advertisements

Dynamic Libraries vs Static Libraries.

When coding and trying to port MATLAB code to a C++ application I ran into some problems loading some dynamic libraries. See last post for more information

I never understood what was the difference between dynamic libraries and static libraries and the need for it. So I decided to learn it.

What is the difference between a dynamic library and a static library:

Dynamic libraries are not loaded to the executable code of a binary application. They are loaded in the fly. Dynamic libraries are not loaded into the heap.

Static libraries is compiled with the application and is kept together with the application. Wasting precious heap memory. [1]

I’ve seen many times articles referencing the heap and stack and I never understood the difference between the two, so I decided to google it.

What is the difference between stack and heap?

The stack is where memory is allocated for automatic variables.

Heap is a more stable storage than the stack. Memory allocated in the heap is there until the application is closed.

PS: For a more in depth explanation please visit the following websites:

[1]https://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/OverviewOfDynamicLibraries.html#//apple_ref/doc/uid/TP40001873-SW1

[2] http://www-ee.eng.hawaii.edu/~tep/EE160/Book/chap14/subsection2.1.1.8.html

Using compiled matlab compiled code in c++ program

After compiling the code I found the following error when I ran:

>> make


The problem listed was the following:

Undefined symbols for architecture x86_64:
“_mlfSegmentImage”, referenced from:
_main in KinectVideoHandler-KFLNAR.o
“_mxCreateString_proxy”, referenced from:
_main in KinectVideoHandler-KFLNAR.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [KinectVideoHandler] Error 1


Apparently (according to description here the problem is the following:

1) The object is present but the linker doesn’t look for
it in the right place.

2) The object is not present, because the matlab system
is set up to work with a 32-bit compiler.

3) The object is not present because the compiler doesn’t
support architecture

Makefile tutorial

I did not understand until today how exactly a MAkefile of c++ code worked until today. I’m glad I finally nailed it. If you want to understand it a little bit better how to do it, here is a nice tutorial of how to write a Makefile:

http://www.cs.bu.edu/teaching/cpp/writing-makefiles/

How to transform MATLAB code into C++ code.

When you compile matlab code using mcc (by default or when using the -m option), you get an executable. So from your C++ file, you can call the matlab executable with the C/C++ command exec.

If you use the -l option (using mcc), you get a shared library, and header. For instance if you type (in matlab):

mcc -l test.m -W cpplib:test.h


This should produce a shared library test.lib or test.so, and a header test.h

In test.h you should have line similar to that:

bool MW_CALL_CONV mlxTest(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);

You can call your matlab function using that.

In addition you have to add both shared libraries and headers in you msvc project.

Architecture of GRobot

This is a premature view of how the architecture of Rosie v1.0

Architecture

libfreenect Drivers for Mac OS X

Here a quick — and when I say quick, I mean quick — guide to get you up and running with libfreenect drivers on a Mac OS X.

First up, I made the switch from MacPorts to HomeBrew a while ago and if you decide to take this road, this guide is super easy. If you aren’t using HomeBrew yet, it might be a good time to check it out. It’s a great alternative to MacPorts. You can download it at https://github.com/mxcl/homebrew

I’ll bust this tut (ew?) up into two categories, the HomeBrew installation method and MacPorts. First up, HomeBrew.

Installing libfreenect using HomeBrew

All commands you see in this guide will need to be done using a Terminal Application. You can find the Terminal in Applications -> Utilities -> Terminal

If you haven’t already, download HomeBrew here, installation instructions here.

If you currently have HomeBrew installed, run brew update in order to make sure everything is up to date.

>> brew update

NOTE – You may have to use the ‘sudo’ command if you haven’t ran this script yet.

For the time being, you’ll need to manually retrive a few formulas in order to successfully install libfreenect. Invoke the following commands:

To install libfreenect, simply type the following:

>> brew install libfreenect

Once it’s finished, you should be able to simply type in glview — make sure your Kinect is plugged in, that goes for both the USB and into power outlet — and run the following:

>> glview


Installing libfreenect using MacPorts

Using MacPorts to install libfreenect will require a few additional steps, mainly compiling the build using cmake. Here’s what you need to do to get things started.

Install git, cmake and these libraries:

>> sudo port install git-core
>> sudo port install cmake
>> sudo port install libtool
>> sudo port install libusb-devel



I created a working directory for all my Kinect junk aptly name ‘Kinect’ in my Home directory. You don’t need to do this next step but if you plan on following the guide closely, it may come in handy in terms of keeping track of where things go.

>> mkdir ~/Kinect
>> cd ~/Kinect

Download libfreenect using git:

>> git clone
>> git://github.com/OpenKinect/libfreenect.git

Navigate into the root of the libfreenect directory and create a build directory in order to place the end results of the build:

>> cd ~/Kinect/libfreenect/
>> mkdir build
>> cd build
>> ccmake .

You should now be able to run make and make install

>> sudo make
>> sudo make install

That’s it. change your working directory to /libfreenect/build/bin and run the glview program by invoking the following command:

>> sudo ./glview

For more instructions realting to the installtion of libfreenect on Mac OS X — or Linux and Windows for that matter, check out OpenKinect.org’s Getting Started section.

Originally posted by Jared St. Jean here: http://developkinect.com/resource/mac-os-x/install-libfreenect-drivers-mac-os-x