skipping incompatible library (lmono) while cross compiling c with mono - gcc

Ok for now i managed to call managed code (mono) from native C code
referring to:
http://www.mono-project.com/Embedding_Mono
which works on my host system (x86) ubuntu.
Now i try to crosscompile it for my target (arm) debian system.
Crosscompiler is arm-none-linux-gnueabi-gcc 2010 from Codesourcery
when i go for:
arm-none-linux-gnueabi-gcc 'pkg-config --cflags glib-2.0 --libs mono' -o main.o main.c
i get
Sourcery_G++_Lite/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lmono
so the libmono.so , libmono.a was found in /usr/lib and i go for:
arm-none-linux-gnueabi-gcc -L/usr/lib 'pkg-config --cflags glib-2.0 --libs mono' -o main.o main.c
which results in:
/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /usr/lib/libmono.so when searching for -lmono
/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /usr/lib/libmono.a when searching for -lmono
/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lmono
somebody has advice?
best regards
Gobliins

Build libmono for ARM first, instead of trying to use your x86 build.

Related

Error when cross compiling shared so which depends on another so

I am trying to cross compile my application for a arm based system.
I have 2 libraries compiled in the following way:
$ gcc -shared --sysroot=$DIR_PATH -o $LIBPATH/libfoo.so foo.o
$ gcc -shared --sysroot=$DIR_PATH -o $LIBPATH/libbar.so bar.o
A third library is compiled:
gcc -shared -o $LIBPATH/libfoobar.so --sysroot=$DIR_PATH -L$LIBPATH -Wl,rpath=$RUN_TIME_PATH foobar.o -lfoo -lbar
Then finally I compile a binary:
gcc -o app --sysroot=$DIR_PATH -L$LIBPATH -Wl,rpath=$RUN_TIME_PATH app.o -lfoobar
However when compiling app I get
warning: libfoo.so, needed by libfoobar.so, not found (try using -rpath or -rpath-link)
I believe you need to use -Wl,-rpath-link=$LIBPATH to tell the linker where to look to resolve runtime library references during the link operation.
More info can be found in the ld documentation: https://sourceware.org/binutils/docs-2.37/ld/Options.html

Libxml2: undefined reference to xmlTextReaderConstName

I have installed the latest libxml2-2.8.0, as usual: $ ./configure, $ make, $ make install.
The $ xml2-config --cflags --libs gives this output:
-I/usr/local/include/libxml2
-L/usr/local/lib -lxml2 -lm
But trying to compile any example...
$ gcc `xml2-config --cflags --libs` xmltest.c
The linker says:
/tmp/cc8ezrPl.o: In function `processNode':
xmltest.c:(.text+0x19): undefined reference to `xmlTextReaderConstName'
xmltest.c:(.text+0x38): undefined reference to `xmlTextReaderConstValue'
...etc.
Anything I've googled can be solved by xml2-config --cflags --libs flags, or upgrading to the latest version of libxml2, or something. Unfortunately, neither works for me.
What can be the steps to identify the problem?
Using Ubuntu 12.04 64-bit.
The libraries should be specified only after the source file so that the linker can resolve the undefined references in the source file. Try compiling the example with this
gcc -I/usr/local/include/libxml2 -L/usr/local/lib xmltest.c -lxml2 -lm

Static cross-compilation of GTK applications on Fedora for Windows?

I'm trying to build gtk3 applications for windows and since Fedora delivers mingw and precompiled libraries for gtk3 for mingw, I used it.
I got the normal compilation working via
i686-mingw32-gcc test.c `pkg-config --cflags --libs gtk+-win32-3.0`
Now I would like to link it statically (Fedora delivers precompiled libraries for that too) but i cannot get it to work. It tryed
i686-mingw32-gcc test.c -static `pkg-config --cflags --libs --static gtk+-win32-3.0`
but it results in
/usr/lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/bin/ld: cannot find -lgtk-3
/usr/lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/bin/ld: cannot find -lgdk-3
/usr/lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/bin/ld: cannot find -lpng14
/usr/lib/gcc/i686-pc-mingw32/4.6.1/../../../../i686-pc-mingw32/bin/ld: cannot find -lffi
AFAIK, static compilation is not supported for GTK+. Anyway, gcc arguments order is important for building with mingw.

Building a 32-bit app in 64-bit Ubuntu

After hours of googling, I decide to give up and ask you experts. I am trying to build a 32-bit application (xgap if anyone interested) in my 64 Ubuntu 11.10. I added the CFLAGS=-m32 and the LDFLAGS=-L/usr/lib32 in the makefile. The objects are built into 32 bit fine. The last step is to link all the objects and libraries for X windows into this executable---xgap. Somehow it keeps giving me this error:
gcc -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11 -lSM -lICE
/usr/bin/ld: skipping incompatible /usr/lib32/libXmu.so when searching for -lXmu
...
/usr/bin/ld: i386 architecture of input file `xcmds.o' is incompatible with i386:x86-64 output
...
I have installed ia32-libs and mutilib support. I think I just need to force the linker to generate a i386 output. I tried to put two ld flags in my gcc command as shown above: -melf_i386 and -oformat elf32-i386. But what happens is that gcc doesn't search for the 32 bit library in /usr/lib32 anymore. I wonder if I need to put those flags in some fixed order?
Thanks for any idea and help!
EDIT: when I add the -m32 flag in my last gcc command (the linking stage I believe), even if I have the -L/usr/lib32 flag in place, gcc doesn't search in /usr/lib32 anymore ( really weird...) and generates the following error:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libXaw.so when searching for -lXaw
/usr/bin/ld: skipping incompatible /usr/lib/libXaw.so when searching for -lXaw
/usr/bin/ld: cannot find -lXaw
collect2: ld returned 1 exit status
Any one has any idea why this happens? I am using the auto tool to configure and make. I am really good at modifying those script files.
You need to use link with -m32 as well.
gcc -m32 -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11 -lSM -lICE
All things considered, I think you should be able to drop the -L/usr/lib32 when using -m32.
I solved the problem. I think that gcc was expecting a static library archive. I used the getlibs script from http://ubuntuforums.org/showthread.php?t=474790 to download all the .a archives needed for linking. Then gcc worked. I think gcc did search in /usr/lib32 directory but didn't find the .a archives so went on to search in the standard directory which is /usr/lib, where it finds the incompatible *.so files.
But then the question is: the *.so files in /usr/lib32/ from package ia32-libs doesn't really have the libraries needed for linking? What are those files in /usr/lib32/ used for?

Makefile for a simple application

I have a file app.c which uses two libraries GStreamer and libXml2. To compile the application I type the following on Terminal
gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) app.c -o app -I/usr/include/libxml2 -lxml2
When I try to Makefile with the contents as follows :
all:
gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) app.c -o app -I/usr/include/libxml2 -lxml2
run:
./app
clean:
rm app
On running make command I get the errors as expected. What is the significance of
$(pkg-config --cflags --libs gstreamer-0.10)
on Echoing the above I get some files which when included in Makefile gives me the correct output.
pkg-config --cflags libraryX outputs the path to the header files of libraryX. Without this, the compiler does not know where to look for the header files, and compilation will fail.
Similarly, pkg-config --libs libraryX outputs the path to the actual compiled library files of libraryX. Without this, the linker does not know where to look for the library files, and linking will fail.
pkg-config --cflags --libs libraryX is just combining what I described above. Since you're using gcc to do both compilation and linking, you just pass those parameters together to gcc.

Resources