Creating ruby gem out of swig generated cxx wrapper - c++

I have now spent days on this. WHAT am I doing wrong?!
I have a swig generated wrapper for a c++ library I'm interested in using (COIN-OR). So I wrote a c++ struct that has all the methods I need from coin, and I have written a Swig interface file awcbc.i. I then wrapped it with swig, and this generated a awcbc_wrapper.cxx file.
I have an extconf.rb file, which creates a makefile from this. I included the necessary libraries like this:
with_cflags("-x c++") do
abort 'missing cbc' unless find_library("Cbc", nil, "lib")
abort 'missing CbcModel.hpp' unless find_header("CbcModel.hpp", "include/coin")
abort 'missing awcbc.hpp' unless find_header("awcbc.hpp", "include")
end
"lib" is full of dylibs, one of which is Cbc. Similarly, CbcModel.hpp is one of the many headers in include/coin. The point of these is to include those directories, and thus all my dependencies into the search path. awcbc.hpp contains my struct.
When I run
$ ruby extconf.rb; make;
it creates a makefile and compiles it. I can then run irb, require awcbc, and it's all there and working.
However, when I try to put some of this into a rakefile (I've tried Jeweller, following the format set by a very similar library heroku-rglpk, or tried to use rake-compiler, as described in ruby-guides, I get
ERROR: Error installing ./pkg/awcbc-0.0.0.gem:
ERROR: Failed to build gem native extension.
/Users/*...*/.rbenv/versions/2.1.2/bin/ruby extconf.rb
checking for main() in -lCbc... no
missing cbc
*** extconf.rb failed ***
But it didn't fail when I called ruby extconf.rb manually!
This is one out of several nightmares in getting this fairly simple extension built.
What I'm shooting for, is a gem that I can put on ruby-gems which is basically the exact same thing as heroku-rglpk. I want it to check for Coin-Or, install if not there, wrap it, and gemify it. It's so frustrating that I can make the wrapper, and use it, but then I can't gemify it (and incidentally, this means I have NO IDEA how to include it in my rails app).
Bah. Can anyone help?

Related

Loading OCaml modules not in the current directory

I'm writing a large OCaml project. I wrote a file foo.ml, which works perfectly. In a subdirectory of foo.ml's directory, there is a file bar.ml.
bar.ml references code in foo.ml, so its opening line is:
open Foo
This gives me an error at compile time:
Unbound module Foo.
What can I do to fix this without changing the location of foo.ml?
The easy path is to use one of OCaml build system like ocamlbuild or oasis. Another option would be jbuilder but jbuilder is quite opiniated about file organization and does not allow for the kind of subdirectory structure that you are asking for.
The more explicit path comes with a warning: OCaml build process is complicated with many moving parts that can be hard to deal with.
After this customary warning, when looking for modules, OCaml compiler first looks for module in the current compilation environment, then looks for compiled interface ".cmi" files in the directories specified by the "-I" option flags (plus the current directory and the standard library directory).
Thus in order to compile your bar.ml file, you will need to add the parent directory in the list of included directories with the -I .. option.
After all this, you will discover that during the linking phase, all object files (i.e. .cmo or .cmx) need to be listed in a topological order compatible with the dependency graph of your project.
Consequently, let me repeat my advice: use a proper build system.

How to write an LLVM pass?

I am writing an LLVM pass, just following http://llvm.org/docs/WritingAnLLVMPass.html#basic-code-required.
I have finished the Makefile, the source code, however, when I came to do the make:
Now that it’s all together, compile the file with a simple “gmake” command in the local directory and you should get a new file “Debug+Asserts/lib/Hello.so” under the top level directory of the LLVM source tree (not in the local directory).
It reported
../../../Makefile.common:61: ../../../Makefile.config: No such file or directory
../../../Makefile.common:69: /Makefile.rules: No such file or directory
make: *** No rule to make target '/Makefile.rules'. Stop.
I didn't change the any configuration files in the root directory. There is no Makefile.config in my root directory, but there is a file called Makefile.config.in. Makefile.common appears in the root directory.
I hate to be the one to tell you, but I think you'll need to get your basics straight before diving into compiler development:
http://llvm.org/docs/WritingAnLLVMPass.html has a lot of documentation that you should definitely read, including information on the Manager:
The PassManager class takes a list of passes, ensures their prerequisites are set up correctly, and then schedules passes to run efficiently. All of the LLVM tools that run passes use the PassManager for execution of these passes.
A makefile is a mechanism of defining how a piece of software is built by compiler, linker, installation scripts etc. How that will look like depends completely on how you plan to implement your software. In your case, you should definitely orientate yourself on existing passes. In fact, http://llvm.org/docs/WritingAnLLVMPass.html#setting-up-the-build-environment has a rather detailed explanation on how to set up the makefile, including a template, which is really simple
# Makefile for hello pass
# Path to top level of LLVM hierarchy
LEVEL = ../../..
# Name of the library to build
LIBRARYNAME = Hello
# Make the shared library become a loadable module so the tools can
# dlopen/dlsym on the resulting library.
LOADABLE_MODULE = 1
# Include the makefile implementation stuff
include $(LEVEL)/Makefile.common
If you don't understand that, you'll have to read a bit of existing Makefiles or make documentation.
All in all, I think writing LLVM passes might not be the thing I'd get started with if not being used to these kind of standard tools, but I recommend just diving into the LLVM source code tree to get a feeling. Practice makes a master!

Tests won't run: "The executable for the test bundle at '../DerivedData/../*.xctest' could not be found"

I have a Xcode 5.1 project (projA) which included a private framework (frameworkB) via Cocoapods. Everything was working, building and testing and even the weather was nice. But, because the frameworkB is being developed in parallel with the projA, I decided to include the project of the frameworkB (proj B) in projA, again via Cocoapods but as a reference with :path ='path/to/projB'
In the result the projB compiles and builds and runs on device, the tests target also compiles and builds but doesn't run, the simulator start and this message is displayed:
2014-04-14 11:08:34.990 xctest[98973:303] The executable for the test bundle at
/Users/myNameHere/Library/Developer/Xcode/DerivedData/projB-manyLettersHere/Build
/Products/Debug-iphonesimulator/projB.xctest could not be found.
Program ended with exit code: 1
Also the weather is not so nice anymore.
Google didn't help. Other stackoverflow question are more about transition from Sentest cu XCTest.
Any hint that will put me on the right path will be greatly appreciated.
The cause and solution to this problem is (as usual) very simple:
The framework that was being built contained a bundle, which was required, but (of course) was not generated by the Pod project, even if in the podspec i specified the spec.resources pram. The solution was to create a spec.resource_bundle with the required name and resource files.
Why it would throw this error and not a compile-time or runtime error i still don't know :|
(the projB.xctest was present at the path in error)

Problems building python interpreter with custom module

I am trying to build the python-2.6 interpreter on Linux with a custom module embeded into the interpreter. I tried following the instructions on 'Extending Python with C or C++' from the Python documentation but something keeps on going wrong. I keep getting the following error when building :
make: *** No rule to make target `Modules/_custommodule.c', needed by `Modules/_custommodule.o'. Stop.
I've checked the generated Makefile and it does contain references to my _custommodule.c file and has the proper libraries linked for dependencies but is not being made for some reason.
That's usually because you don't have a file called custommodule.c available to make. Check that:
that file exists.
you're in the right directory when you make.
If that doesn't work, Edit your post with a directory listing of that directory.

Installing a cpp library on linux

I'm trying to install a library (libspopc), but, when I run the make command, I get the errors:
strip libspopc.a libspopc.so
strip: 'libspopc.a': No such file
strip: 'libspopc.so': No such file
make: *** [install] Error
Working under the assumption that every version of the library I've tried isn't actually missing two of its files, what could cause this? I am running it as su, as instructed, if it's relevant.
While this question is only remotely related to programming (seems more like something for superuser.com), on linux you should whenever you can use the package manager of your system. In most cases, it let's you fetch the files as binaries (thus avoiding possible compilation frustrations), keeps your system clean and is (most importantly for me) easy to remove again. Oh yeah, and it helps you keep the library up to date.
Try looking in your package manager! If it's a fairly popular library, it's probably in your package manager's repositiories!
At least I know it's in mine!
$ bauerbill --aur -Ss libspopc
AUR/libspopc 0.9-1
A simple pop3 mail client library