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

Thread: Compile C++ program for the Teensy 3.0 (Lat/Long to MGRS coordinate conversion)

  1. #1

    Compile C++ program for the Teensy 3.0 (Lat/Long to MGRS coordinate conversion)

    I want to convert latitude/longitude to MGRS coordinates. Using this wonderful library called "GeographicLib", I can do that quite easily on the windows platform. Here's my little program utilizing that library:

    Code:
    #include <iostream>
    #include <exception>
    #include <string>
    #include "GeographicLib\UTMUPS.hpp"
    #include "GeographicLib\MGRS.hpp"
    
    using namespace std;
    using namespace GeographicLib;
    
    int main() {
    
          double lat = 33.3, lon = 44.4; // Baghdad
          int zone;
          bool northp;
          double x, y;
          UTMUPS::Forward(lat, lon, zone, northp, x, y);
          string mgrs;
          MGRS::Forward(zone, northp, x, y, 5, mgrs);
          cout << mgrs << "\n";
    
      return 0;
    }
    It compiles, runs, and gives me the MGRS coordinates accurately. Geographic lib can be downloaded from: http://geographiclib.sourceforge.net/

    HOWEVER, I'm having serious issues getting this to compile in the arduino IDE that comes with the Teensy 3.0. I was just going through the errors as they came to me during compilation, but it's become apparent to me that I'm going to have to fix a hell of a lot of errors. And some of them are starting to become beyond my ability to fix or even understand (I'm a rather novice C++/C programmer). Anyone have any ideas?

  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Post the errors.

  3. #3
    It's possible to compile and run C++ code on a microcontroller like the Teensy3, but some C++ language features depend on fairly complex and heavyweight library support (for example, STL and exceptions). In your case, if the GeographicLib library actually uses exceptions and C++ strings (as suggested by the #includes) then you're right: you may have to fix a hell of a lot of errors (actually, you may have to provide a hell of a lot of C++ language support).

    If I was you, I'd start with the C version of the library. It's apparently just 2 files, and any problems you have compiling them are likely to be math-support related (and also problems you'd face in the C++ version, if you ever got through the STL, exception and memory-allocation issues of supporting C++).

  4. #4
    Yeaahhhhhh, I was thinking of doing that spacewrench. Thanks for the advice.

Posting Permissions

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