Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Building a C library

  1. #1
    Junior Member
    Join Date
    May 2017
    Posts
    12

    Building a C library

    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.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,201
    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 *)malloc(buf_sz*sizeof(LM_REAL));
          if(!buf){
            fprintf(stderr, RCAT("memory allocation in ", AX_EQ_B_QR) "() failed!\n");
            exit(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.

  3. #3
    Junior Member
    Join Date
    May 2017
    Posts
    12
    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++?

    Click image for larger version. 

Name:	Screenshot 2018-01-05 18.22.38.jpg 
Views:	10 
Size:	67.3 KB 
ID:	12518
    Last edited by hmpws; 01-07-2018 at 05:36 AM. Reason: As seen by the iostream problem, the library seems to be C++!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •