문제

I'm trying to write my rendering code for my application in C++ and everything else in Haskell. My C++ code links to the boost and Ogre3D libraries.

I'm trying to compile/link my Haskell program with compiled .o files in GHC to no avail, getting errors like this:

undefined reference to `Ogre::Vector3::ZERO'

The command I've come up with so far to link the code is as follows:

ghc --make Main.hs obj/Debug/BaseApplication.o obj/Debug/Application.o -lstdc++ -L"C:/Ogre/OgreSDK_MinGW_v1-8-0/bin/Debug" -L"C:/Ogre/OgreSDK_MinGW_v1-8-0/bin/Release" -I"C:/Ogre/OgreSDK_MinGW_v1-8-0/include" -I"C:/Ogre/OgreSDK_MinGW_v1-8-0/include/OGRE" -I"C:/Ogre/OgreSDK_MinGW_v1-8-0/include/OIS" -I"C:/Ogre/OgreSDK_MinGW_v1-8-0/boost" -optl-Wl -optl--enable-runtime-pseudo-reloc -optl--enable-auto-image-base -optl--enable-auto-import -optl--add-stdcall-alias -optl-mthreads

It tries to link two BaseApplication.o and Application.o, two of my files, and the Ogre3D and boost libraries as well. It also has some linker options I copied from Code::Blocks.

I know that there is a small binding to Ogre3D for Haskell (http://hackage.haskell.org/package/hogre), but I am a beginner with the library and all of the resources for learning the library are written in C++; I don't want to have the barrier of having to translate it to Haskell as well.

How do I link external C++ libraries to my Haskell code? To be clear, I am using a C wrapper over the C++ routines to ensure that the names aren't mangled by the compiler, and I am using the FFI. Am I using the wrong options to provide directories for Haskell or is there something I'm missing?

도움이 되었습니까?

해결책

In case you are using your own wrapper, here's link to such project: Low level C Ogre3D Interface.

As for "undefined reference" errors - the libker is right, you are not passing in Ogre libs, only paths to them. Try to add -lOgreMain or something like this.

다른 팁

what you want is a difficult and cumbersome task, for a couple of reasons:

  • FFI is working with C only, not C++ (you probably know and have been mentioned above)
  • Writing a C wrapper for a big C++ library is a pain for a lot of reasons
  • Windows C++ libraries often use the MS compiler, for example in Ogre the MS version is supported better then the gcc version (this is an observation, based on one case, not really substantial facts behind it)

For Ogre, I also wrote a haskell wrapper, see here: http://www.hgamer3d.org.

It already contains a lot of functionality, next version 0.1.9 will contain even CEGUI API.

You're not supposed to use GHC (which uses gcc and not g++) to link C++ code.

You should have self contained C++ library (.so) that has reference to libstdc++.so and exposes C interface. GHC invokes gcc for linking and will not generate proper symbols/code for vtables for inline functions (they're generated at link time not compile time). Haskell bindings for Bullet Physics hit pretty much the same problem, you might want to look at that.

Ogre is not really designed to be wrapped because it uses too many things that are C++-specific.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top