Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#13336 closed defect (fixed)

farey_symbol.pyx fails to build on Cygwin

Reported by: jpflori Owned by: tbd
Priority: major Milestone: sage-5.3
Component: porting: Cygwin Keywords: cygwin linking
Cc: Merged in: sage-5.3.beta1
Authors: Jean-Pierre Flori Reviewers: Dmitrii Pasechnik
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jpflori)

Because of DL_IMPORT stuff in headers generated by Cython and corresponding _ _ imp _ _ prefixes added in object files, farey.o cannot be linked to farey_symbol.o (it could with farey_symbol.dll if we generated it...).

The patch here does not include farey_symbol.h but directly declare the prototype of the needed functions in farey.cpp, with the extern "C" stuff but without the dllspec(import) stuff.

Attachments (1)

trac_13336-linking.patch (1.2 KB) - added by jpflori 7 years ago.
Fix linking problem.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by dimpase

with these flags on, I still get

g++ -shared -Wl,--enable-auto-image-base -L/home/Dima/sage-5.2.rc1/local/lib build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey_symbol.o build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey.o build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/sl2z.o -L/home/Dima/sage-5.2.rc1/local/lib -L/home/Dima/sage-5.2.rc1/local/lib/python2.7/config -lcsage -lgmp -lgmpxx -lstdc++ -lntl -lpython2.7 -o build/lib.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey_symbol.dll -Wl,--enable-auto-import
build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey.o: In function `_ZNK18is_element_general9is_memberERK4SL2Z':
/home/Dima/sage-5.2.rc1/devel/sage/sage/modular/arithgroup/farey.cpp:183: undefined reference to `__imp__convert_to_SL2Z'
[... etc ...]
/home/Dima/sage-5.2.rc1/devel/sage/sage/modular/arithgroup/farey.cpp:655: undefined reference to `__imp__convert_to_cusp'
build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey.o: In function `_ZNK11FareySymbol13get_fractionsEv':
/home/Dima/sage-5.2.rc1/devel/sage/sage/modular/arithgroup/farey.cpp:664: undefined reference to `__imp__convert_to_rational'
build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey.o: In function `_ZNK11FareySymbol20get_pairing_matricesEv':
/home/Dima/sage-5.2.rc1/devel/sage/sage/modular/arithgroup/farey.cpp:705: undefined reference to `__imp__convert_to_SL2Z'
build/temp.cygwin-1.7.16-i686-2.7/sage/modular/arithgroup/farey.o: In function `is_element_GammaH':
/home/Dima/sage-5.2.rc1/devel/sage/sage/modular/arithgroup/farey.cpp:132: undefined reference to `__imp__convert_to_long'
collect2: ld returned 1 exit status

So it looks like that the linker cannot find objects which are part of the Farey module (i.e. from sl2z.o, etc)?!

Looks like some g++/dll linking weirdness to me.

comment:2 follow-up: Changed 7 years ago by jpflori

Yes... In fact we'll get the same problem later with the wrapper_* things in ext/interpreter.

What's strange is that I don't remember getting it here the last time. But I kind of so much tweaked the files back then that it must have been that as well.

I think the problem is as follows: As convert_* are declared extern in farey_symbol.h (from the public modifier in farey_symbol.pyx) g++ adds _ _ imp _ _ prefixes in farey.o. Then if you actually build a dll of farey_symbol.cpp alone and link a dll of farey.o alone to it ld is fine. But when you want to directly link farey_symbol.o and farey.o together, ld whines...

comment:3 Changed 7 years ago by jpflori

And obviously I've deleted my 5.1.rc1 install so I have to figure out what let the files compile the last time :)

comment:4 in reply to: ↑ 2 Changed 7 years ago by jpflori

Replying to jpflori:

I think the problem is as follows: As convert_* are declared extern in farey_symbol.h (from the public modifier in farey_symbol.pyx) g++ adds _ _ imp _ _ prefixes in farey.o. Then if you actually build a dll of farey_symbol.cpp alone and link a dll of farey.o alone to it ld is fine. But when you want to directly link farey_symbol.o and farey.o together, ld whines...

This seems to be the problem. If you remove the DL_IMPORT lines in farey_symbol.h (generated by Cython), you'll link correctly.

I've got some ideas from here: http://stackoverflow.com/questions/3704374/linking-error-lnk2019-in-msvc-unresolved-symbols-with-imp-prefix-but-shoul

comment:5 Changed 7 years ago by jpflori

Patch coming.

Changed 7 years ago by jpflori

Fix linking problem.

comment:6 Changed 7 years ago by jpflori

  • Authors set to Jean-Pierre Flori
  • Description modified (diff)
  • Keywords cygwin linking added
  • Status changed from new to needs_review

comment:7 Changed 7 years ago by dimpase

OK, this does the trick here. I'll give it a positive review as soon as the patchbot gives OK. The next stop looks like a ginac-related problem at #13337

Last edited 7 years ago by dimpase (previous) (diff)

comment:8 Changed 7 years ago by dimpase

  • Status changed from needs_review to positive_review

Looks good.

comment:9 Changed 7 years ago by jdemeyer

  • Reviewers set to Dmitrii Pasechnik

comment:10 Changed 7 years ago by jdemeyer

  • Merged in set to sage-5.3.beta1
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:11 Changed 3 years ago by jdemeyer

Real Cython fix in #23004.

Note: See TracTickets for help on using tickets.