Cross compiling PCRE with CodeSourcery toolchain? - gcc

I am trying to compile PCRE with CodeSourcery
here is my configure script
#!/bin/bash
PROJECT_BASE=$(pwd);
PROJECT_REPOSITORY=$PROJECT_BASE/download
INSTALL_PREFIX=$PROJECT_BASE/compiled/armv5te
mkdir -p $INSTALL_PREFIX && mkdir -p $PROJECT_BASE/download && mkdir -p $PROJECT_BASE/build
export TOOL_PREFIX=${HOME}/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux
SYSROOT=$HOME/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/arm-none-linux-gnueabi/libc
export CC="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-gcc --sysroot=$SYSROOT"
export CXX="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-g++ --sysroot=$SYSROOT"
#CC="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-gcc"
#CXX="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-g++"
export AR="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-ar"
export RANLIB="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-ranlib"
export LD="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-ld"
export STRIP="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-strip"
export NM="${TOOL_PREFIX}/bin/arm-none-linux-gnueabi-nm"
export CCLD=$LD
export CHOST=arm-none-linux-gnueabi
PARENT_DIR=$(pwd);
cd $PROJECT_BASE/build && tar -xzvf $PROJECT_REPOSITORY/pcre-8.34.tar.gz && cd ./pcre-8.34
#LDFLAGS_DEP="-lc"
#CPPFLAGS="-I${INSTALL_PREFIX}/include"
# CFLAGS="-march=armv5t -marm -mlittle-endian -mglibc -static -I${INSTALL_PREFIX}/include"
LDFLAGS="-L${INSTALL_PREFIX}/lib"
./configure --prefix=$INSTALL_PREFIX/pcre --with-sysroot --target=arm-none-linux-gnueabi --host=x86_64 && make && make install;
cd -;
cd ${PARENT_DIR};
now it is successfully compiled but when i tried to execute that binary on android i get:
./pcregrep: not found
also having similar issue when cross-comping curl, openssl but when i run a test code
#include <stdio.h>
int main(){
printf("Hell ya it works");
return 0;
}
and compile with following option
arm-none-linux-gnueabi-gcc hello.c -static -o hello.c
it works

You're trying to use a Linux compiler with Android. It's not completely broken because Android is Linux, but Android doesn't come with the same set of libraries, as standard.
It's probably possible to install the Linux libraries (from the appropriate CodeSourcery libc directory), but that's a tricky process because the Android files will already be in the standard locations so they'll have to be installed to one side, somehow, and if you don't know what you're doing it'll get into a horrible mess.
The best solution is probably to use entirely static linking. That said, you might still find that libcurl is unhappy because, even statically linked, it requires that it can dlopen the DNS library of the host system, and I don't know how Android likes to do that.
I would suggest you try to get hold of a purpose-built Android toolchain (I believe Linaro do one) that is designed to use Android's "Bionic" C library, rather than GNU/Linux's "Glibc".

Its a mismatch between libc of code-sourcery tool-chain and libc which is in target rootfs.
libc in the host cross-compiler and deployed on the device rootfs are different
arm-none-linux-gnueabi-gcc hello.c -static -o hello.c
it works `
This works since you compiling statically so there is no need to copy libc to target here.
But pcre you built dynamically .check file ./pcregrep if its dynamic linked then
one easiest way compile statically as hello eg. and run on your target.
otherwise copy libc from tool chain to target and export it then it will work

Related

Linking against static Lua libraries on macOS

I'm trying to compile and link a program (using CMake) that uses Lua 5.3's C interface on Mac OS X 10.15.7. However I have these problems:
brew install lua#5.3 only installs dynamic libraries
I cannot copy static libraries built from source to /usr/local due to System Integrity Protection (?)
I don't know how to make CMake find the libraries if I put them anywhere else (using find_package(Lua 5.3 REQUIRED)
What's the easiest way to solve this?
If I correctly understand your question, you are trying to use Lua's C API, which means that you need access to the principal header files lua.h, lualib.h, and lauxlib.h, as well the static library liblua.a that is created when the interpreter is built.
I would recommend downloading lua-5.3.5.tar.gz from lua.org and then building from source.
This can be done easily from the Terminal:
$ wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
$ tar xzf lua-5.3.5.tar.gz
$ cd lua-5.3.5
$ make macosx
After that you should be able to do make install as well, which copies the Lua interpreter to /usr/local/bin, I believe.
If you do not want the key Lua header files put into your include path, build your program with -I and -L flags. Also, don't forget the -llua -ldl -lm flags when linking your program.

How to Compile mingw-w64-crt

I'm on Windows 10 and using the latest version of MSYS2 (with gcc installed: pacman -S gcc)
I'm trying to compile mingw-w64-headers and mingw-w64-crt from mingw-w64-v7.0.0
Inside of my MSYS2 installation directory C:\msys2 I have created the folder mingw-w64 which I reference in the prefix argument below.
To compile each of these I use the same steps (replace name of library where appropriate):
mkdir mingw-w64-crt && cd mingw-w64-crt
../mingw-w64-v7.0.0/mingw-w64-crt/configure --prefix=/mingw-w64
make
make install
This works for mingw-w64-headers however for mingw-w64-crt I encounter errors at the make step. Specifically: incompatible types when assigning to type 'mbstate_t' {aka 'struct anonymous'} from type 'int'. A more detailed error image can be found here.
I would appreciate some guidance as to how to proceed.
I suggest that you just open one of MSYS2's MinGW environments (by running mingw32.exe or mingw64.exe) and then install the complete MinGW-w64 toolchain by running this:
pacman -S $MINGW_PACKAGE_PREFIX-toolchain
The toolchain includes GCC, the MinGW-w64 libraries, and the MinGW-w64 headers. If those prebuilt MinGW-w64 things are good enough for you, then you're done.
If you want to compile your own MinGW-w64, then should be able to use the environment you just installed to do it. To double-check that you are using the right toolchain, run which gcc and make sure it returns /mingw64/bin/gcc or /mingw32/bin/gcc.
Performing the following has allowed me to successfully compile:
pacman -S $MINGW_PACKAGE_PREFIX-toolchain
mkdir mingw-w64-crt && cd mingw-w64-crt
../mingw-w64-v7.0.0/mingw-w64-crt/configure --prefix=/mingw-w64 --with-sysroot=/mingw64
make -j %NUMBER_OF_PROCESSORS%
make install

How to override default linker compiling with configure?

I need to install a package (ROOT) from source on OSX using GCC 4.7.3 as a compiler. Default compiler on OSX is clang, so I look to configure command options to change it. I see that I can change it:
with compiler options, prefix with --with-, overrides default value
cc alternative C compiler and options to be used
cxx alternative C++ compiler and options to be used
But when I run:
./configure --with-cxx=g++ --with-cc=gcc
I see:
Checking for C compiler ... gcc
Checking for C++ compiler ... g++
Checking for linker (LD) ... clang++
So it trying to compile with gcc and link with clang, this obviously leads to failure. But I can't find an option in configure how to change linker used by make.
Is there a default options of configure to change linker? Something like --with-cxxlinker.
If not - how can I find and change the linker used by specific package?
The recommended way of building ROOT from source is to use git and obtain the most recent production version available. As of today that is version 5.34.19.
Open Terminal.app (then use each of the commands in succession):
cd ~/desktop && mkdir root
git clone http://root.cern.ch/git/root.git && cd root
./configure
make
make install
The nice thing about using git is that it contains a complete source tree for all systems (72 MB). You shouldn't need to use any special ./configure commands (unless you want to use add-on components).
You could also install the Mac Ports version by using the command:
sudo port install root

How do I compile and run GCC 4.9.x?

I'm running debian wheezy and wanted to upgrade from GCC 4.7.2 to GCC 4.9.0.
As per these instructions I installed libgmp-dev, libmpfr-dev and libmpc-dev (my package manager gave me versions 2:5.0.5+dfsg-2, 3.1.0-5 and 0.9-4 respectively) and ran the following to compile gcc (note that in my case it was 4.9.0 instead of 4.6.2):
tar xzf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.6.2/configure --prefix=$HOME/gcc-4.6.2
make
make install
I now have a objdir directory full of stuff, but where is g++, and where should I put this directory?
I'm guessing I should move it to usr/local and add something to my PATH variable, but I don't know what exactly, and how to make sure it is searched before my old gcc install.
After doing these commands (note the --prefix option of configure)
$PWD/../gcc-4.9.0/configure --prefix=$HOME/gcc-4.9.0
make install
the new gcc will be installed in $HOME/gcc-4.9.0 directory (there should be subdirectories like bin, lib, share inside it).
Full path to gcc will be $HOME/gcc-4.9.0/bin/gcc, and g++ (which is symlink to gcc) will be here: $HOME/gcc-4.9.0/bin/g++.
There can be no separate g++ in objdir because gcc compiler driver implements drivers for several languages; the mode (C or C++) is selected based on argv[0] (name of binary, which was used to run driver: gcc or g++; this mode also affects linking flags) and on source file extensions (gcc accepts both C and C++ programs as input for compilation into object files). So, g++ may be generated as symlink by make install, and the place to store generated symlink is $prefix/bin.
After building the GCC and installing it in the $HOME/gcc-4.9.0 directory, you can use it; but default system gcc will be not updated. Update of distributive gcc should be done via distributive tools (apt, dpkg-build, etc). Current prebuild version of system-wide gcc for Wheezy is 4.7.2, 4.8.2 for Jessie and Sid and 4.9-2 for "Experimental".

cross compile opencv for porting to TI DM6446

I have set up target fs on
/home/myself/filesys/bin..etc//
GCC
compile:
host $ arm_v5t_le-gcc hello.c -o hello
run:
target $ cd /opt/hello
target $./hello
I have installed opencv2.3 on host ubuntu machine now I want opencv to be ported to DM6446
so i follow
uncompress opencv2.3 tarball
sudo cmake OpenCV-2.3.1
sudo make ARCH=arm CROSS_COMPILE=arm_v5t_le-
but when I run the sample test from bin it runs on x86 machine which was made for ARM
I think I am not following the correct procedure to make opencv.
Is there anything I have to do to make opencv for ARM architecture,
what are the steps to follow in cross compiling?
The 2nd command you executed should provide a clue as to whether you are cross-compiling or not. If you look closely it would have shown that it was building for the i686 and not for the ARM platform.
This blog discusses how to Cross Compile using cmake.
cmake uses different environment variables from standard make (so don't use ARCH, and CROSS-COMPILE).

Resources