Building library issue libudns - c

First of all thanks for your attention and help.
I have been trying to ./configure and build a program that use a lot of libraries, and specifically libudns. I have been installing several libraries that were needed or by apt-get or by compile, and all of them works, but libudns (which is freaking me out).
This program make use of a configure script that include the following lines of code that add the flag -ludns to the Makefile:
if [ "x$WITH_UDNS" == "xy" ]; then
mkl_lib_check "udns" HAVE_UDNS fail CC "-ludns" \
"#include <udns.h>
void *f();void *f(){return dns_init;}"
fi
When I type ./configure the script checks if all libraries are presents on the system by pkg-config and by compile, as you can see in the following snap:
As you can see, configure cannot see this library.
What I have done is try to install this package by the two different ways:
By pkg-config: sudo apt-get install libudns-dev
By compile:
git clone https://github.com/shadowsocks/libudns
cd libudns
./autogen.sh
./configure && make
sudo make install
With this two ways, I have both:
/usr/lib/x86_64-linux-gnu/libudns.so
/usr/local/include/udns.h
These paths are the same where others libraries are installed, for example PostgreSQL, which you can that is detected:
/usr/lib/x86_64-linux-gnu/libpq.so
/usr/include/postgresql/libpq-fe.h
But the result is always the same:
Does anybody knows how to link this library?
Also, I have try these other things:
Copy udns.h to /usr/include: sudo cp /usr/local/include/udns.h /usr/include/udns.h
Make a sample program only to emulate this check:
#include <stdio.h>
#include <udns.h>
struct dns_ctx* ctx;
void *f();
void * f(){return dns_init;}
int main(int argc, char** argv){
int do_open = 0;
printf("Hola, mundo\n");
f(ctx, do_open);
}
And when I try to build this program with:
gcc main.c -o hello_world -ludns
it WORKS!?!
I have also try to build this program without the -ludns flag, and it gives me the same error as before:
So, I do not understand where is the fail, considering that as you can see in the second image, the -ludns flag is present.
Thanks a lot for your time. Any advise will be welcomed.

Related

Running Ruby in C

I’m trying to run a block of Ruby code inside a C program.
I have the following code:
#include <ruby.h>
int main(int argc, char* argv[])
{
/* Construct the VM */
ruby_init();
/* Ruby goes here */
/* Destruct the VM */
return ruby_cleanup(0);
}
But when I try to run the program, I get the following error:
fatal error: ruby.h: No such file or directory
#include <ruby.h>
I read that it is needed to tell the compiler about the include paths for the required headers with the following code in Ubuntu:
pkg-config --cflags --libs ruby-2.5
gcc -I/usr/include/ruby-2.5.0 -I/usr/include/ruby-2.5.0/x86_64-linux -lruby
I have already done that, but the problem isn’t solved.
Here is the link: https://silverhammermba.github.io/emberb/embed/
Follow the steps in How can I include a needed C library using GCC?.
I don't understand the difference between the two -l, but try to follow the following structure. If I'm right, your command will be like:
gcc -I/usr/include/ruby-2.5.0 -L/usr/include/ruby-2.5.0/x86_64-linux -lruby
Where:
-I <searchpath to include files>
-L <searchpath to the lib file>
-l <thelibname>
I don't know if the library is the first or the second parameter, but you can check it.

Cross-compiled library not found by toolchain

I'm new to developing for embedded systems, but I have installed arm-linux-gnueabi-gcc via the Linux Mint package manager and managed to build a few programs successfully.
I'm currently struggling with getting a program to compile using libusb. I've done the following:
Downloaded and unpacked the libusb 1.0.20 sources from https://sourceforge.net/projects/libusb/.
Compiled and installed them using the following commands:
~/Downloads/libusb-1.0.20 $ ./configure --host=arm-linux-gnueabi --prefix=/opt/ --disable-udev
~/Downloads/libusb-1.0.20 $ sudo make
~/Downloads/libusb-1.0.20 $ sudo make install
(The reason for sudo-ing the make commands was because I encountered permission problems related to removing old files.)
Copied a small sample file from somewhere on the internet:
#include <libusb-1.0/libusb.h>
#include <stdio.h>
int main()
{
int i=0;
libusb_context **c = NULL;
i = libusb_init(c);
printf("\nusing libusb.h\n");
return 0;
}
Tried to build it and run it with gcc:
~/Desktop/libtest $ gcc libtest1.c -o libtest1 -lusb-1.0
~/Desktop/libtest $ ./libtest1
using libusb.h
However, when I try to do the same with arm-linux-gnueabi-gcc, it can't find the library:
~/Desktop/libtest $ arm-linux-gnueabi-gcc libtest1.c -o libtest1 -lusb-1.0
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lusb-1.0
collect2: error: ld returned 1 exit status
Where did I go wrong? Is there something else I need to do in order to use the library? Did I fail at compiling the library for the arm compiler? I didn't include the compiler output here since it's quite long, but there are no obvious errors. This might be a very stupid question, but I'm completely clueless.

Linking C library to R

I recently found this C library (http://libxlsxwriter.github.io/), and attempted to use it with R.
Getting the C library to work by itself was not difficult. I downloaded zlib and libxlsxwriter using msys2, and ran make in the libxlsxwriter folder.
Now I can run this Hello-World example, lets call it test.c:
#include "xlsxwriter.h"
void main() {
lxw_workbook *workbook = workbook_new("myexcel.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
int row = 0;
int col = 0;
worksheet_write_string(worksheet, row, col, "Hello me!", NULL);
workbook_close(workbook);
}
Now I can compile test.c by running:
cc test.c -o test -lxlsxwriter -lz
And then run the executable:
./test
And now I have a Hello-World excel document.
Getting it to work with R has been much trickier. If I simply run:
R CMD SHLIB test.c
I get this error: ibxlsxwriter/include/xlsxwriter/common.h:19:42: fatal error: xlsxwriter/third_party/queue.h: No such file or directory
#include "xlsxwriter/third_party/queue.h"
Yet the file is clearly there when I check.
Any advice on how to connect this C library with R? At this point I am just trying to get the hello-world example to run from R.
Would it be a better approach to start out building a package, with xlsxwriter in the inst folder, and then try to write a makevars that will get xlsxwriter to compile correctly? I know I would have to include PKG_CPPFLAGS = -I../inst/libxlsxwriter but I am guessing I would need more than that.
You may want to try Continuum's Anaconda R packages. They use MSYS2 packages fairly directly. The toolchain package is called m2w64-toolchain and the posix package is sometimes useful for building R packages too.
conda install -c r r-essentials m2w64-toolchain posix
Disclaimer: I work for Continuum, but I also work on MSYS2.

"loading shared libraries" error using VLFeat in C

I am trying to use VLFeat library in C, as given on the website
http://www.vlfeat.org/gcc.html.
I downloaded and installed the library. I use the glnxa64 architecture. The library is located at /A/B/C/vlfeat-0.9.18
My code is as follows:
extern "C" {
#include <vl/generic.h>
#include <vl/sift.h>
}
int main (int argc, const char * argv[])
{
VL_PRINT ("Hello world!") ;
return 0;
}
I compile my code using the following statement,
g++ main.cpp -o vlfeat-test -I/A/B/C/vlfeat-0.9.18 -L/A/B/C/vlfeat-0.9.18/bin/glnxa64/ -lvl
But when I run it, I get the following error
./vlfeat-test: error while loading shared libraries: libvl.so: cannot open shared object file: No such file or directory
When your program is loaded, linux loads the necessary libraries.
You need to create a symbolic link in /usr/lib/ to your libvl.so file
sudo ln -s /home/[YourPATH]/vlfeat-0.9.20/bin/[YourArchitecture]/libvl.so /usr/lib/libvl.so
Before running your test, in the same console:
export LD_LIBRARY_PATH=/A/B/C/vlfeat-0.9.18/bin/glnxa64:$LD_LIBRARY_PATH
then
./vlfeat-test
I think the problem is when your program load. Linux doesn't know where your vl library is.
copy libvl.so to /usr/lib
sudo cp [VLFEAT_PATH]/bin/[YOUR_ARCHITECTURE]/libvl.so /usr/lib
[This worked for same problem when using the .mex files through MATLAB in Ubuntu].
You may need to update the links and cache to the recent shared libraries by running
sudo ldconfig
You can permanently add the library path /A/B/C/vlfeat-0.9.18/bin/glnxa64 or a custom directory with your (links to) shared libraries, e.g., /home/username/lib in the ldconfig files:
sudo vim /etc/ld.so.conf
to add the line(s)
/A/B/C/vlfeat-0.9.18/bin/glnxa64
Verify by running
ldconfig -v | grep libvl.so

Linux : Glib was not found

I have a sample C project that use GLib Library. In that source code, it use :
#include <glib.h>
When I compile, I found this error : "Glib.h : no such file or folder". I have google and find out that I should install this lib. So I use those command:
apt-get install libgtk2.0-dev
apt-get install glade
After that, I have checked and see already exist this header file in my system: usr/include/glib-2.0/glib.h But when I compile, I still meet problem above.
So I have change include line to :
#include <glib-2.0/glib.h>
So, after that, when I compile, I meet error inside glib.h header :
#ifndef __G_LIB_H__
#define __G_LIB_H__
#define __GLIB_H_INSIDE__
#include <glib/galloca.h>
#include <glib/garray.h>
// more code here
glib/galloca.h : no such file or directory. Because this error is inside system header file, I cannot modify anymore and still cannot compile.
I don't know how to fix this. I have read some post, that they change makefile. But, because my project is compiled automatically by IDE (CodeBlock) and I cannot really write a makefile, so that method doesn't suitable for me.
Please tell me a way to fix this.
Thanks :)
There must be some problem with how you build. To compile C programs that use GLib, you need package libglib2.0-dev. You can either install it directly, or install libgtk2.0-dev, which pulls it in as a dependency. So you have the packages you need.
The correct way to compile a GLib program is to use -I with the path to the GLib include files.
An example (from How to compile a helloworld GLib program? on askubuntu):
gcc $(pkg-config --cflags --libs glib-2.0) hello_glib.c
This should let you compile this program:
#include <stdio.h>
#include <glib.h>
int main(int argc, char** argv) {
GList* list = NULL;
list = g_list_append(list, "Hello world!");
printf("The first item is '%s'\n", g_list_first(list)->data);
return 0;
}
The errors you are getting indicate that you are not setting the include path (-I) correctly. How to do this depends on your build system/IDE.
In Code::Blocks, you must set the include path and the linker options in the appropriate configuration dialog. Run pkg-config --cflags --libs glib-2.0, which will output something like
-I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -lglib-2.0
The directories after -I must be set in the compiler options of your project (should be under Project -> Build Options -> Search Directories), and the names after -l must be set in the linker settings. Another option is to create a Makefile, and let Code::Blocks use that.
See e.g. Q: What do I need to know when using 3rd party libs? in the Code::Blocks Wiki.
You should not alter your source code (e.g. the #include directives).
You just need to use pkg-config (both for compiling, with --cflags, and for linking, with --libs), preferably with a builder program like make.
This is an example for exactly your situation: a Makefile using pkg-config to compile some source program using glib

Resources