vnayar / s2geometry-d

Port of Google's S2 Geometric Library to the D programming language.
Apache License 2.0
21 stars 1 forks source link

Linking error on Linux x86_64: error: undefined reference to 'internal' #3

Closed andrepibo closed 5 years ago

andrepibo commented 5 years ago

First of all, I'd like to thank you for porting this library to D!

The issue I am encountering is an linking error, as shown below:

/home/ubuntu/.dub/packages/s2geometry-d-0.2.0/s2geometry-d/src/s2/s2polygon.d:671: error: undefined reference to 'internal' /home/ubuntu/.dub/packages/s2geometry-d-0.2.0/s2geometry-d/src/s2/s2polygon.d:671: error: undefined reference to 'internal' /home/ubuntu/.dub/packages/s2geometry-d-0.2.0/s2geometry-d/src/s2/s2polygon.d:701: error: undefined reference to 'internal' /home/ubuntu/.dub/packages/s2geometry-d-0.2.0/s2geometry-d/src/s2/s2polygon.d:701: error: undefined reference to 'internal'

This issue, however, is happening on linux but not on mac.

The compiler/linker versions on Mac are: DMD64 D Compiler v2.083.1

/usr/bin/ld -v
@(#)PROGRAM:ld  PROJECT:ld64-351.8
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
LTO support using: LLVM version 9.1.0, (clang-902.0.39.2) (static support for 21, runtime is 21)
TAPI support using: Apple TAPI version 9.1.0 (tapi-902.0.9)

And on Linux: DMD64 D Compiler v2.083.1

ld --version
GNU gold (GNU Binutils for Ubuntu 2.26.1) 1.11

And the following is the piece of code that's using s2geometry-d:

void testS2(){
    import s2.s2polygon;
    import s2.s2latlng;
    import s2.s2loop;
    import s2.s2point;
    import s2.s2debug;

    uint multiLoop;
    foreach(id, ref l; localityById){
        if(l.geometry is null)
            continue;
        S2Loop[] loops;
        S2Point[] points;

        foreach(ref c; l.geometry.coordinates){
            S2LatLng ll = S2LatLng.fromDegrees(c.lat, c.lng);
            points ~= ll.toS2Point();

            if(points[0] == points[$-1]){
                points.popBack();
                if(points.length > 2) loops ~= new S2Loop(points, S2Debug.ALLOW);
                points.length = 0;
            }
        }

        multiLoop += (loops.length > 1 ? 1 : 0);
        if(loops.length > 0){
            S2Polygon polygon = new S2Polygon(loops, S2Debug.ALLOW);
            logInfo("Area: %s", polygon.getArea());
        }
    }
    logInfo("MultiLoop: %s", multiLoop);

}
vnayar commented 5 years ago

Thank you very much for the report, I appreciate the feedback! I build and run in Linux, so hopefully it will be easy to resolve. I'll take a look after work today and hopefully have a fix.

vnayar commented 5 years ago

I found the bug, which only seems to surface when using the library linked, but not in the unit-tests. The cause was that the S2BooleanOperation.Options struct has some of its members initialized with dynamically allocated initializers. Given that certain members should be freshly allocated for each instance, it make more sense to convert it to a static final class.

I created a new patch release version, v0.2.1 which contains the fix.

Try running dub upgrade s2geometry-d and then rebuild your project, let me know if there's any more issues.

andrepibo commented 5 years ago

Thank you @vnayar for your quick reply and fix! Version 0.2.1 links correctly on Linux.

andrepibo commented 5 years ago

Out of curiosity, have you figured out why it was working for Mac but not for Linux?

vnayar commented 5 years ago

Unfortunately I haven't. I do not have a Mac to test with. I am still not 100% sure why it wasn't working before, but a few searches through the DLang forums revealed that others have experienced similar problems. I'm still thinking about what the best solution is for a struct that should have dynamically allocated members upon creation. A factory method could work, but it seems strange to treat some structs as special cases.

But I wanted to get a fix out as soon as possible as well, and thinking about the best general practice is not a prerequisite to finding a working solution.

On Tue, Jun 4, 2019 at 10:22 AM André Pinheiro Borba < notifications@github.com> wrote:

Out of curiosity, have you figured out why it was working for Mac but not for Linux?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vnayar/s2geometry-d/issues/3?email_source=notifications&email_token=AAKGNHDQTUXIUWRT26KXOILPYYQ45A5CNFSM4HSG7U22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW3Z35A#issuecomment-498572788, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKGNHCQCSX3J6NNSFMZM5TPYYQ45ANCNFSM4HSG7U2Q .