How to build jansson using premake? - c

I am trying to build jansson C library using premake.
The designers of the library require us to:
./configure
make
make install
the above steps generates jansson_config.h that is needed for the build.
What I want to do is:
./configure
premake4 gmake
make
What happens when I do that is that the build fails saying that jansson_config.h is missing.
How would I be able to achieve what I want?

Building with other build systems than those directly supported by Jansson is documented here: https://jansson.readthedocs.org/en/2.7/gettingstarted.html#other-systems
Basically, you just take src/jansson_config.h.in, copy it to src/jansson_config.h and edit it, replacing all #var# placeholders to match your target system.

Related

cmake - How to make sure a program(dependency) is installed on users machine

My c programm(for linux) needs users to have a specific programm lets say "foo" be installed to work. I am using cmake to generate build files.
This program is to be distributed.
How can I make sure that it is installed using cmake.
I found this but it's for checking at runtime. I want to check it before building the program.
If foo provides a CMake package, use find_package to find foo:
find_package(foo REQUIRED)
# Use the foo::foo imported target or foo_EXECUTABLE cache variable
There are many built-in packages for CMake including Python and FLEX.
If foo does not provide a CMake package and you only need the path to the executable, then you can use find_program:
find_program(Foo_EXECUTABLE foo REQUIRED)
From here you can use the Foo_EXECUTABLE variable in your execute_process or add_custom_command calls.

Compiling in a dynamic C library (dylib) into a program on OS X

I've written a little C program which uses libusb. Now I want to distribute this program to "normal" (not dev) Mac OS X computers. But when I ported the compiled file to a test machine I got the following error:
dyld: Library not loaded: /opt/local/lib/libusb-0.1.4.dylib
Referenced from: /Users/kitty/myprogram
Reason: image not found
Trace/BPT trap: 5
When I copy the files (works only with all the files)
/opt/local/lib/libusb-0.1.4.dylib /opt/local/lib/libusb-1.0.a
/opt/local/lib/libusb.a
/opt/local/lib/libusb-1.0.0.dylib /opt/local/lib/libusb-1.0.dylib
/opt/local/lib/libusb.dylib
from my machine to the target machine the program works flawlessly.
But I really want to create or compile everything into a single executable. How is this possible?
Using -static while compiling does not work since not all libraries can be compiled into the final app statically (see this SO question here).
So how can I make a single neat little application file?
You can convert a static library to a dynamic library, but I'm not aware of a way to do the reverse as you want it.
If you're building an app with a bundle, you need to put the library you want to distribute inside your bundle, in the Frameworks directory, and link against that.
If you are not building a bundle-based app, just a single binary, you may need to provide instructions for your users on how to install the library on their system (e.g. via Homebrew).
Here's how you do it for bundle-based apps:
Apple has a document about run-path dependent libraries but doesn't actually explain how to set this up for a newbie.
Here's how it should work:
Add the libusb.dylib you want to use to your project.
It should automatically get added to your "Link Binary with Libraries" phase in your project's "Build Phases". If not, add it here.
Add a new "Copy Files" build phase.
In the "Destination" drop-down box, select "Frameworks". This is the
Frameworks directory in your app's final bundle.
Then press the "+" icon in that copy build phase and add your library.
If you had any manual linking options like -L/usr/local/lib and -lusb, remove them.
Clean and build.
When you now look into your app bundle, you'll see that the library is copied to <bundle_path>/Contents/Frameworks/. You can now start the app from wherever you want, the dynamic link loader knows it needs to look at <path_to_binary>/../Frameworks/ to find your library.
But: you may need to rebuild your libusb to have the install_name set to #rpath/../Frameworks/libusb.dylib or use the install_name_tool CLI tool fix that path for your copy of libusb.dylib that you added to your project.

Is it possible to build a package with bitbake without poky?

I have all compiled binaries for target machine. I want to create a binary package - say .ipk, .rpm - for target machine. As this suggested to clone poky, which will have bitbake within it. But, as this document says, we can directly use bitbake without poky, however, it not mentioned anywhere that we need poky as well as bitbake to build a custom package. But of course poky is required if we have to compile source code and create binaries.
If I don't need to compile any source code at all, does I need to have Poky?
Is it possible to build a package with only bitbake?
First, Poky is a reference distribution that contains primarily bitbake and openembedded-core.
Yes, you need oe-core to build packages as the logic to build packages is part of oe-core, not bitbake.

Build system for project that uses C and Haskell

I am working on a project that uses C and Haskell. Currently, I am using CMake to build a C shared library and cabal to build a Haskell executable. Is there a more unified way to do this? Can I invoke cabal from the Makefile generated by CMake or is there a way to build the C library directly from Cabal? Thanks.
CMake could also do what you want. It does however duplicate lots of the functionality of cabal. So you could call cabal from whatever build tool you choose to use (for cmake, using a custom command, for makefiles, it's pretty self-explanatory), build binaries directly (see cabal build -v).
See Is it possible to use cmake for Haskell projects?.

Regarding linking CLI Parser to my application

I am using an open source CLI parser (this one -> http://sourceforge.net/projects/cliparser/) to add command line interface to my application and it works really neat on its own, but I am having trouble adding it to my application. The documentation provided is very meager and I have limited experience with makefiles. If anyone has used this parser before could you help me out with it?
Specifically, how do I make the parser run within my program? The document says"link your parser against libparser.a" What does that mean?
Thanks!
When you compile your program, you need to link against the library. If using GCC, this is done via two ways:
You can specify the path to the library:
gcc myapp.c /somepath/libparser.a
Or, if it is in your standard library directory you should be able to do:
gcc myapp.c -l parser

Resources