Including other *.o files with Cabal - haskell

I'm building a simple library that wraps some parts of Qt. I want to be able to use Qt's qmake configuration system to find the Qt libraries on the given system, etc, to build the c wrapper code. I can get this to work and produce a *.o file, no problem.
But how can I get cabal to include this *.o file in the *.a it generates? I assume I'll have to write a custom Setup.hs to make it work, but reading over the Cabal library documentation I don't see an obvious way to do it.
On #haskell someone suggested that I could use postBuild to add files to the *.a after it is generated, but even then how do I get the path to the generated *.a from inside postBuild?

Related

Bash command: export BLAS_LIBS="-L$LAPACKHOME/lib -lblas"

Can any body explain to me what does the whole sentence mean?
I know this is to set Macro BLAS_LIBS as another string.
But I'm not sure what's the "-lblas" mean and I don't know how to use it.
Similar as the following code. "-llapack"
export LAPACK_LIBS="-L$LAPACKHOME/lib -llapack"
How can the program find out the BLAS and LAPACK libraries just by "-lblas" and "-llapack" ?
Thanks for advance.
I'm not sure why you say "just by -llapack" because that's not what is happening here. Specifically, the -L option just before it specifies a directory path to add to the library resolution path. This works roughly like PATH in the shell.
For example, with the command line fragment gcc -Lfoodir -Lbardir -lfoo -lbar, you basically instruct the linker to search the directories foodir and bardir for the library files libfoo.a and libbar.a.
The -l option is described in GCC: Options for Linking and -L and friends in the following section GCC: Options for Directory Search.
This build arrangement -- configure the build to show where the required files are before compiling -- is common for libraries, where if a user has already downloaded and compiled a required library for some other project, they don't need to rebuild it; they can just point the compiler to wherever they already have the stuff needed for this project.
Building your own libraries is becoming increasingly unnecessary anyway, as prepackaged binaries of most common libraries are available for most systems these days. But of course, if you are on an unusual platform, or have specialized needs which dictate recompilation with different options than any available prebuilt binary, you will still need to understand how to do this.

ElfToolChain - How to build the libelf library w/o the rest of the package?

I need to parse the loadable parts of an ELF executable for a simple loader. Found the nice "libelf by Example" tutorial (by J. Koshy) that gives a nice overview on the structure of an ELF. It then lead me to the ELF Toolchain project, which implements, among other things, the libelf library of ELF handling functions.
The nice thing about using this library is that it encapsulates the variations in ELF formats and makes the code more portable and future proof. However, I found out that in order to be able to build the package on Ubuntu, I needed to install a great amount of prerequisites.
I tried to build only the libelf part by running pmake in the libelf directory, but got a build error complaining on missing header file - which is apparently automatically generated by the global make process and is architecture dependent.
My question is - how can I build just the libelf part of ELF Toolchain?
You can build select parts of the Elftoolchain source tree by commenting out the appropriate SUBDIR lines in the top-level Makefile.
For building libelf, you should be able to get by with the following two directories:
% grep ^SUBDIR Makefile | head -2
SUBDIR += common
SUBDIR += libelf
Note: On Ubuntu, you could also use GNU libelf, which offers a different implementation of the same API, and for which there appears to be ready-made packages.

Is it possible to package c code with Haskell using cabal?

I have a c library that I'd like to provide an FFI interface for. This is easy enough, but I can't figure out how to get the packaging right. It would be nice to just be able to
cabal install librarybindings
and have cabal automatically build it with gcc, generate the .o file, and include that with the distribution. Right now, I can the package to compile fine, but when you go to build an executable using the bindings you have to explicitly pass ghc the .o file on the command line. Yuck.
Yes, you can ship C code with Haskell. See e.g.
bytestring
zlib
download
By convention the C bits are put in a cbits/ directory.

Using GNU C++ built library in VS C++ project

I'm trying to implement an open source library that is built using the GNU compiler. (namely, this: https://github.com/mjwybrow/adaptagrams )
I've tried opening and building that source code using VSC++ 6, but it results in over a thousand errors due to the strict nature of the VS compiler I guess. And rather then go through every error and try fix it myself, I was wondering if it's possible to just include the .lib if it is built with the GNU compiler?
EDIT:
Included in the source code linked above is an autogen.sh file.
mkdir -p m4
autoreconf --install --verbose
automake -a --add-missing
./configure
make
Running that with Cygwin results in a few .a library files to be created, which are unusable in VS. Is it ok to just rename these to .lib files?
I've found some stuff online about how to use GCC and create a DLL, but my problem is that I don't know enough about the GNU compiler or makefiles, or the source code in general to be able to change it right now.
Does anybody have any clues on what exactly I'd need to change to get it right? Or even better, has anyone created a DLL using this source code already that would be able to pass it on to me, or let me know what I have to do?
Or could anyone point me towards a similar library that would be compatible with visual studio?
No; you can however build the .dll file with gcc and use the .dll from msvc (with either a hand-crafted include file or a properly formatted one from the beginning, with platform specific import/export macros on top).

how to use my own dynamic library in linux (Makefile)

I have a c++ project (g++/raw Makefile) designed for linux, I used to statically link everything which worked fine for ages. Now I want to build binaries both statically and dynamically linked. The following command is used in my Makefile to build the dynamic library (say libtest):
$(CXX) -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0.0 $(LIBTEST_OBJS)
The output is libtest.so.1.0.0 which has the so name libtest.so.1
I found at least a symbolic link libtest.so --> libtest.so.1.0.0 is required to link my client program that actually use the above generated libtest.so.1.0.0 library.
Here my question is if I want to build my software, what is the standard way of managing the above symbolic link? Clearly I don't want this extra stuff in my source directory, but it is required to build my client binary, shall I create it as a temp link for building the client then just remove it when done? or shall I create a directory to host the generate .so library and its links and leave everything there until I do "make install" to install them into other specified directories? Will be cool to now what is the standard way of doing this.
Or maybe the way how I generate libraries is incorrect? shall I just generate libtest.so (as actual library, not a link) to link my executable, then rename the library and create those links when doing ``make install''?
any input will be appreciated. :)
Certainly don't generate libtest.so as an actual link. Typically installing the shared library development files installs the .h files and creates a symbolic link libtest.so as part of some install script you have to write.
If you're not installing the development files, but only using the library in your build process of your binary, you just create the symbolik link from your makefile.
There's not that much of a standard here, some prefer to build artifacts to a separate build directory,
some don't care if it's built in the source directory. I'd build to a separate directory though, and keep the source directory clean of any .o/.so/executable files.
You might find useful information here
My suggestion is to use libtool which handles situations like this.

Resources