मैं एक सी ++ प्रोग्राम में कुछ हास्केल फ़ंक्शंस को कॉल करना चाहता हूं।इंटरफेसिंग हास्केल और सी ++
ऐसा करने के लिए, मैंने these निर्देशों को लागू किया है और उन्हें मेरे कोड और सिस्टम में अनुकूलित किया है।
- main.cpp
- साझा हैडर और सीपीपी फ़ाइलों
- makefile
- सीपीपी/
- कुछ सीपीपी और हेडर फाइल:
क्या मैं पल के लिए निम्नलिखित है
- कुछ सीपीपी और हेडर फाइल:
- Haskell/
- hello.hs
मेकअप फ़ाइल है निम्नलिखित:
CPP_SOURCES = main.cpp textures.cpp cpp/game.cpp \
cpp/piece.cpp cpp/factories.cpp cpp/utils.cpp
HASKELL_SOURCES = haskell/hello.hs
all: main; ./main
main: $(CPP_SOURCES) HaskellPart.o; g++ \
-lsfml-graphics \
-lsfml-window \
-lsfml-system \
-I/usr/lib/ghc/include \
-liconv \
-I/usr/lib/ghc/ghc-8.0.1/include \
-L/usr/lib/ghc/ghc-8.0.1 \
-L/usr/lib/ghc/rts \
-lHSrts \
-L/usr/lib/ghc/base-4.9.0.0 \
-lHSbase-4.9.0.0 \
-L/usr/lib/ghc/ghc-prim-0.5.0.0 \
-lHSghc-prim-0.5.0.0 \
-L/usr/lib/ghc/integer-gmp-1.0.0.1 \
-lHSinteger-gmp-1.0.0.1 \
-lHSghc-prim-0.5.0.0 \
-fno-stack-protector \
-Wall \
-o main $(CPP_SOURCES) haskell/hello.o
HaskellPart.o: $(HASKELL_SOURCES); ghc -fforce-recomp -fPIC $(HASKELL_SOURCES)
clean: ; rm -rf main && rm -rf haskell/*.o && \
rm -rf haskell/*.hi && rm -rf haskell/*_stub.h
मैंने क्या किया है:
- जोड़ने
-I/usr/lib/ghc/include
अनुमति देने के लिए g ++ को खोजने के लिएHsFFI.h
- प्रतीक त्रुटियों से बचने के लिए libciries पथ
-fPIC
को ghc तर्कों में अद्यतन करें।
हालांकि, मैं निम्नलिखित उत्पादन के साथ अंत:
$ make
ghc -fforce-recomp -fPIC haskell/hello.hs
[1 of 1] Compiling Hello (haskell/hello.hs, haskell/hello.o)
g++ \
-lsfml-graphics \
-lsfml-window \
-lsfml-system \
-I/usr/lib/ghc/include \
-liconv \
-L/usr/lib/ghc/rts \
-lHSrts \
-L/usr/lib/ghc/base-4.9.0.0 \
-lHSbase-4.9.0.0 \
-L/usr/lib/ghc/ghc-prim-0.5.0.0 \
-lHSghc-prim-0.5.0.0 \
-L/usr/lib/ghc/integer-gmp-1.0.0.1 \
-lHSinteger-gmp-1.0.0.1 \
-lHSghc-prim-0.5.0.0 \
-fno-stack-protector \
-Wall \
-o main main.cpp textures.cpp cpp/game.cpp cpp/piece.cpp cpp/factories.cpp cpp/utils.cpp haskell/hello.o
/tmp/ccHPRuDY.o: In function `main':
main.cpp:(.text+0x358): undefined reference to `hs_init'
main.cpp:(.text+0x375): undefined reference to `hs_exit'
haskell/hello.o: In function `sRs_info':
/tmp/ghc9fcb_0/ghc_7.o:(.text+0x2e): undefined reference to `newCAF'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0x3e): undefined reference to `stg_bh_upd_frame_info'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0x54): undefined reference to `ghczmprim_GHCziCString_unpackCStringzh_closure'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0x5d): undefined reference to `stg_ap_n_fast'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0x96): undefined reference to `newCAF'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0xa6): undefined reference to `stg_bh_upd_frame_info'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0xbc): undefined reference to `base_SystemziIO_putStrLn_closure'
/tmp/ghc9fcb_0/ghc_7.o:(.text+0xc5): undefined reference to `stg_ap_p_fast'
haskell/hello.o: In function `helloFromHaskell':
(.text+0xd8): undefined reference to `rts_lock'
haskell/hello.o: In function `helloFromHaskell':
(.text+0xee): undefined reference to `base_GHCziTopHandler_runIO_closure'
haskell/hello.o: In function `helloFromHaskell':
(.text+0xf9): undefined reference to `rts_apply'
haskell/hello.o: In function `helloFromHaskell':
(.text+0x10f): undefined reference to `rts_evalIO'
haskell/hello.o: In function `helloFromHaskell':
(.text+0x122): undefined reference to `rts_checkSchedStatus'
haskell/hello.o: In function `helloFromHaskell':
(.text+0x12e): undefined reference to `rts_unlock'
haskell/hello.o: In function `stginit_export_Hello_zdfstableZZC0ZZCmainZZCHelloZZChelloFromHaskell':
ghc_3.c:(.text+0x144): undefined reference to `foreignExportStablePtr'
haskell/hello.o: In function `sRs_closure':
/tmp/ghc9fcb_0/ghc_7.o:(.data+0x40): undefined reference to `stg_IND_STATIC_info'
haskell/hello.o: In function `rHM_closure':
/tmp/ghc9fcb_0/ghc_7.o:(.data+0x60): undefined reference to `ghczmprim_GHCziTypes_TrNameS_static_info'
haskell/hello.o: In function `rI0_closure':
/tmp/ghc9fcb_0/ghc_7.o:(.data+0x70): undefined reference to `ghczmprim_GHCziTypes_TrNameS_static_info'
/tmp/ghc9fcb_0/ghc_7.o:(.data+0x80): undefined reference to `ghczmprim_GHCziTypes_Module_static_info'
haskell/hello.o: In function `SRD_srt':
/tmp/ghc9fcb_0/ghc_7.o:(.data.rel.ro+0x0): undefined reference to `ghczmprim_GHCziCString_unpackCStringzh_closure'
/tmp/ghc9fcb_0/ghc_7.o:(.data.rel.ro+0x8): undefined reference to `base_SystemziIO_putStrLn_closure'
collect2: error: ld returned 1 exit status
makefile:17: recipe for target 'main' failed
make: *** [main] Error 1
मैं गलत क्या कर रहा हूँ के किसी भी विचार?
धन्यवाद!
संपादित करें:
n.m जवाब के अनुसार, मैं जी ++ तर्कों का क्रम बदल।यहाँ नए makefile है:
CPP_SOURCES = main.cpp textures.cpp cpp/game.cpp cpp/piece.cpp cpp/factories.cpp cpp/utils.cpp
HASKELL_SOURCES = haskell/hello.hs
CFLAGS = -Wall -g -fno-stack-protector
all: main; ./main
main: $(CPP_SOURCES) HaskellPart.o; g++ \
$(CFLAGS) -o main $(CPP_SOURCES) haskell/hello.o \
-lsfml-graphics \
-lsfml-window \
-lsfml-system \
-I/usr/lib/ghc/include \
-liconv \
-I/usr/lib/ghc/ghc-8.0.1/include \
-L/usr/lib/ghc/ghc-8.0.1 \
-L/usr/lib/ghc/base-4.9.0.0 \
-lHSbase-4.9.0.0 \
-L/usr/lib/ghc/ghc-prim-0.5.0.0 \
-lHSghc-prim-0.5.0.0 \
-L/usr/lib/ghc/integer-gmp-1.0.0.1 \
-lHSinteger-gmp-1.0.0.1 \
-lHSghc-prim-0.5.0.0 \
-L/usr/lib/ghc/rts \
-lHSrts \
HaskellPart.o: $(HASKELL_SOURCES); ghc -fforce-recomp -fPIC $(HASKELL_SOURCES)
clean: ; rm -rf main && rm -rf haskell/*.o && rm -rf haskell/*.hi && rm -rf haskell/*_stub.h
लेकिन यह एक और त्रुटि मिली:
/usr/bin/ld: /usr/lib/ghc/rts/libHSrts.a(Itimer.o): undefined reference to symbol '[email protected]@GLIBC_2.3.3'
this धागा के अनुसार, मैं -lrt
जोड़ा है, लेकिन मिल गया:
/usr/bin/ld: /usr/lib/ghc/rts/libHSrts.a(Linker.o): undefined reference to symbol '[email protected]@GLIBC_2.2.5'
तो के अनुसार this धागा मैंने -ldl
जोड़ा BOUNTY
दोस्तों मैं एक इनाम प्रतिष्ठा की मेरी कम राशि का एक बड़ा हिस्सा खर्च क्योंकि मैं इस काम करने के लिए प्रबंधन नहीं कर सकते हैं और वास्तव में इस की जरूरत है जोड़ रहा: और अब यह a big mess...
संपादित है।
यह एक स्कूल से संबंधित परियोजना के लिए है, लेकिन मुझे यह सटीक करना है कि यह धोखाधड़ी नहीं कर रहा है क्योंकि विषय केवल कहता है: "सी ++ में एक बड़ा कार्यक्रम लिखें और उसी कार्यक्रम को हैकेल में लिखें"।
दोनों कार्यक्रमों के लिए एक सामान्य ग्राफिकल इंटरफ़ेस बनाना मेरा निर्णय है और coursework के दायरे से बाहर है।
इसके अलावा, मुझे लगता है कि इंटरनेट पर इस विषय पर दस्तावेज़ीकरण की कमी है, मेरे शिक्षक ने मुझे बताया कि वह कभी ऐसा करने में कामयाब नहीं रहा है, इसलिए हास्केल विदेशी निर्यात के साथ जी ++ के कॉन्फ़िगरेशन पर एक निर्मित उत्तर प्राप्त करना सहायक होगा।
आपकी मदद के लिए धन्यवाद।
आप पिछले -lHSghc-रस्मी-x.y.z पैरामीटर निकाल दिया है। सूची में ऊपरी -lHSghc-prim-x.y.z ऊपरी होने के बावजूद, इसे पुनर्स्थापित करने पर विचार करें। –
हो गया। मैंने अपनी पोस्ट को नए आउटपुट के साथ संपादित किया, लेकिन यह समान दिखता है। धन्यवाद –
बस ध्यान दिया कि आपके संकलन कमांड में सभी ऑब्जेक्ट्स/स्रोत फ़ाइलों से पहले सभी पुस्तकालय हैं।** यह गलत है और काम नहीं करेगा **। [यह प्रश्न और उत्तर] देखें (http://stackoverflow.com/questions/45135/why-does-the-order-in-which- पुस्तकालय-are- linked- कभी-कभी- कारण-errors-in-gcc)। मुझे यह भी लगता है कि आपको लिंक लाइन में पुस्तकालयों की श्रृंखला के नीचे HSrts को स्थानांतरित करने की आवश्यकता है। यह शायद सूची में अंतिम पुस्तकालय होना चाहिए। –