Building a C library

Status
Not open for further replies.

hmpws

Member
Hello,

I am trying to get the following library to run on some data and fit a model (with bound constraint):
http://users.ics.forth.gr/~lourakis/levmar/

I got the standalone function working, which doesn't require LAPACK.

Part of the requirement is a LAPACK library, the CLAPACK is suggested which a pre-compiled version isn't available.
http://www.netlib.org/clapack/

I have a Teensy 3.6. How would I go about compiling this and make the library available for levmar? I am not particular enlightened in this area.

Thanks.
 
This library contains quite a lot of code designed for running on an ordinary PC operating system. For example:

Code:
      buf_sz=tot_sz;
      buf=(LM_REAL *)[B]malloc[/B](buf_sz*sizeof(LM_REAL));
      if(!buf){
        [B]fprintf[/B]([B]stderr[/B], RCAT("memory allocation in ", AX_EQ_B_QR) "() failed!\n");
        [B]exit[/B](1);
      }

The good news is malloc does work on Teensy. But without gigabytes of RAM and virtual memory management like you'd get on a PC, use of malloc isn't always ideal if the memory gets fragmented.

The bad news is you'd need to do quite a lot of tedious editing for the many places this library uses functions like fprintf(). Teensy does support Serial.printf(), so the path of least resistance might be to just change them all to Serial.printf. Likewise, you'll need to make decisions about how you want to handle functions like exit(). On Teensy your program never stops running. There is no operating system, so you can't really have exit(). You could try replacing all these with something like "while (1) ; //die here".

The point is this code was designed for a conventional operating system, not running on "bare metal" without an OS. There isn't any simple & automatic way to port it. You'll need to look through all the code and make decisions about what to do in all these cases where the code depends on conventional operating system features. That's not hard, but it will take a lot of tedious time to find and replace them all. The more you try to automate that process, the less you'll understand the compromises you're making and how to troubleshoot problems when/if things don't work.
 
Thanks, Paul. I decided to try another C++ library (dlib) which uses only ISO C++. I fixed a lot of the try/catch statements but now I seem to have run into iostream error init errors. Is there anyway I can get around that? Thanks.

The Arduino makes use of avr-g++ compiler, what about the Teensy, I see both C and C++ compiler options but can't seem to get it to work with the arm-none-eabi-g++?

Screenshot 2018-01-05 18.22.38.jpg
 
Last edited:
Status
Not open for further replies.
Back
Top