Cross Compile ncurses application for ARM linux - linux

I want to cross compile an application from my workstation (x86, linux) for an ARM application processor. First I build for my system:
gcc -static -g -Wall -c main.c -o main.o
gcc -g -Wall main.o -o myApplication -lncurses
this build like I want and also work. If I want to build this for arm
arm-linux-gnueabi-gcc -static -g -Wall -c main.c -o main.o
arm-linux-gnueabi-gcc -g -Wall main.o -o myApplication -lncurses
But this will not compile.
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lncurses
collect2: Error
So: how to cross-compile a ncurses Application in this way?

One easy way to do it would be to download a binary release of ELLCC. It comes with a pre-built libraries, including ncurses. The download page is here. If you grab e.g. http://ellcc.org/releases/ellcc-x86_64-linux-eng-0.1.27.tgz (The version number will change over time), you can untar it. For the ARM, your build lines would look like:
~/ellcc/bin/ecc -target arm-linux-engeabihf -g -Wall -c main.c -o main.o
~/ellcc/bin/ecc -target arm-linux-engeabihf -g -Wall main.o -o myApplication -lncurses
It creates a static binary, so you don't have to worry about shared library versions.

Related

rules for programname.c not found

I am trying to run automake and autoconf in my project. However when I run make, I get an error "no rules to make inz.c required by inz.o". However I don't have inz.c in my project. I guess it might by an error in configuration, but it is my first time using autoconf/automake, so I'd like to kindly ask for assistance. I am running under Linux
The sturcture is as following:
inz (main folder)
-configure.ac
-inz.cbp
-inz.depend
-inz.layout
-Makefile.am
--src\main.cpp
--src\main.hpp
--src\packetcapture.cpp
--src\packetcapture.hpp
--src\packetprocess.cpp
--src\packetprocess.hpp
--src\Makefile.am
configure.ac:
AC_INIT([inz], 1.0)
AC_CONFIG_AUX_DIR([build])
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
Makefile.am:
SUBDIRS = src
dist_doc_DATA = README.md
src\Makefile.am:
bin_PROGRAMS = inz
inz_sources = main.cpp packetcapture.cpp packetprocess.cpp
include_HEADERS = main.hpp packetcapture.hpp packetprocess.hpp
commands to compile the project itself: (it also uses -lndpi -lpthread and -lpcap)
g++ -Wall -std=c++0x -Wunused -g -Wno-deprecated-declarations -Iinclude -I./ -c /inz/src/main.cpp -o obj/Debug/src/main.o
g++ -Wall -std=c++0x -Wunused -g -Wno-deprecated-declarations -Iinclude -I./ -c /inz/src/packetcapture.cpp -o obj/Debug/src/packetcapture.o
commands I run to confiugre automake/autoconf (from the main folder):
autoreconf --install
cd build
../configure
make
You need to be careful with variable names because they are case sensitive.
You're declaring inz_sources, but that's not a special variable for automake. inz_SOURCES would be.
Without a special _SOURCES variable, automake will go on to assume that inz is built from inz.c. But you don't have that file so it fails.

Use only local library with cross compiler

I'm trying to build one application with cross compiler on linux. Application is based on OpenEmbedded project. Compiler and all cross compiled libraries are located in build folder. But for one package build script is trying to use a library from my linux environment.
Command which is called from make script at the end:
/bin/sh ./arm-ABC-linux-gnueabi-libtool --tag=CXX --mode=link
arm-ABC-linux-gnueabi-g++ -march=armv7-a -mtune=cortex-a8
-mfpu=neon -mfloat-abi=softfp -g --std=c++0x -pthread -L/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-Wl,-rpath-link,/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-Wl,-O1 -Wl,--hash-style=gnu -L/opt/my/lib -o modbus_server_test modbus_server_test.o Serial.o SerialUtil.o Crc.o RtuFramer.o Pdu.o
SerialMaster.o
/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/local/apr/lib/libapr-2.la
-lcrypt -luuid -lrt -lcrypt -lpthread -ldl -lexpat -lstdc++
Most important from here that is use -lexpat flag for libexpat.so.1.5.2 library. This library is cross compiled and located in the build folder, and at the same time, we have one in my linux environment.
As result I recieve the next error:
| arm-ABC-linux-gnueabi-libtool: link:
arm-ABC-linux-gnueabi-g++ -march=armv7-a -mtune=cortex-a8
-mfpu=neon -mfloat-abi=softfp -g --std=c++0x -pthread -Wl,-rpath-link -Wl,/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-Wl,-O1 -Wl,--hash-style=gnu -o .libs/modbus_server_test modbus_server_test.o Serial.o SerialUtil.o Crc.o RtuFramer.o Pdu.o
SerialMaster.o
-L/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-L/opt/my/lib /usr/local/apr/lib/libapr-2.so -L/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib
/usr/lib/x86_64-linux-gnu/libexpat.so
/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libuuid.so
-lrt -lcrypt -lpthread -ldl /home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libexpat.so
/home/ABC/build/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libstdc++.so
-lm -pthread -Wl,-rpath -Wl,/usr/local/apr/lib -Wl,-rpath -Wl,/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib
| /usr/lib/x86_64-linux-gnu/libexpat.so: file not recognized: File
format not recognized
| collect2: ld returned 1 exit status
| make[2]: *** [modbus_server_test] Error 1
From output I can see that it include two libraries: one from linux environment (/usr/lib/x86_64-linux-gnu/libexpat.so which is x86) and one from the build folder (build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libexpat.so which is for ARM).At the end it complains about x86 type.
How can I exclude this library from searching in global environment? Why it even trying to use both of them?

Unable to compile C program on Mac, but able to compile on Linux

I facing some trouble compiling my programming assignment on my local machine. The program is distribute to us with makefiles and compilation commands that are known to work on the school's Scientific Linux servers. My local machine is Mac OS X El Capitan.
When I compile my program running make on my Mac, I get the following error that prevents compilation from proceeding:
myid-MacBook-Pro:mp6 myid$ make
gcc -g -lm -std=c99 -Wall -Werror -c lodepng.c
clang: error: -lm: 'linker' input unused
make: *** [lodepng.o] Error 1
But when I push that very same code as work in progress to the Linux servers and compile there, everything works fine. The linux servers use gcc and not clang:
[netid#linux-a2 mp6]$ make
gcc -g -lm -std=c99 -Wall -Werror -c functions.c
gcc -g -lm -std=c99 -Wall -Werror main.o lodepng.o imageData.o functions.o -o mp6 -lm
gcc -g -lm -std=c99 -Wall -Werror -c test.c
gcc -g -lm -std=c99 -Wall -Werror test.o lodepng.o imageData.o functions.o solution.o -o test -lm
In the makefile, these are the variable definitions:
CC=gcc
CFLAGS=-g -lm -std=c99 -Wall -Werror
and the target definition for loadpng.o
lodepng.o: lodepng.c
$(CC) $(CFLAGS) -c lodepng.c
I would appreciate any help on understanding this error and overcoming it.
Thank you very much.
Also, on this note, I thought I would say that I've noticed a subtle difference between Clang and GCC. It seems to me that even warnings generated by Clang would prevent the compilation to proceed so the warnings behaves like errors. But for GCC, if it generates warnings, it still compiles the object file. Please correct me if I'm mistaken.
Right now you're getting a compilation error on your Mac because you're trying to pass linker commands (i.e. -lm) into a compilation(i.e. -c). Do not give link flags when you compile (-c flag) your source files.
In the other compilation snippet you provided, the unused linker command seems to pass by unnoticed which isn't a good thing.
For your last question, the flag -Werror should force all compilation warnings to become errors -- which is exactly what you are describing.

Source-built clang-3.7 on Linux not finding Block_copy

I built and installed llvm/clang-3.7 from source on my Ubuntu Linux system (I'm building from source because my development environment at work does not have apt-get available). The gcc version is 4.8.2. I followed the clang build instructions at http://clang.llvm.org/get_started.html, and everything worked fine (mkdir build; cd build; cmake -G "Unix Makefiles" ../llvm; make; make install). However, I'm now finding that a program to test Block_copy fails to compile. The program is auto-generated by autoconf when I try to build gnustep-base. The part that fails is:
int
main ()
{
return _Block_copy ();
;
return 0;
}
My compile command is:
clang -o conftest -m64 -march=opteron -mno-3dnow -ggdb -O2 -Wall -I/home/build/GNUstep/Local/Library/Headers -I/home/build/GNUstep/Local/Library/Headers -I/home/build/GNUstep/System/Library/Headers -fgnu-runtime -x objective-c -m64 -L/home/build/GNUstep/Local/Library/Libraries -L/home/build/GNUstep/Local/Library/Libraries -L/home/build/GNUstep/System/Library/Libraries conftest.c -lrt -ldl -lpthread -rdynamic -m64 -fgnu-runtime -L/home/build/GNUstep/Library/Libraries -L/home/build/GNUstep/Local/Library/Libraries -L/home/build/GNUstep/System/Library/Libraries -lobjc -lm
Do I need to build clang with a special option to enable blocks, or should I be linking with another library?
Do I need to build clang with a special option to enable blocks
No. But you may need -fblocks option using the clang binary.
-fblocks
Enable the "Blocks" language feature.
should I be linking with another library?
AFAIK, Yes.
_Block_copy is a part of BlocksRuntime.
BlocksRuntime Block.h
BlocksRuntime runtime.c
Have you compiled compiler-rt? It includes BlocksRuntime. The document explains how to build compiler-rt.

How to create a library (Ansi C) with private functions in linux?

I am trying to create a library (static or shared) that has only a specified functionality accessible for those who use that library.
If I generate the library as follows, all functions implemented in the library are usable from an external application. Can I hide some functions?
gcc -fPIC -g -c -Wall -I/usr/include/extrernalLibDIR modulo1.c
gcc -fPIC -g -c -Wall modulo2.c
gcc -fPIC -g -c -Wall modulo3.c
gcc -shared -Wl,-soname,libMyLib.so.1 -o libMyLib.so.1.0.1 modulo1.o modulo2.o modulo3.o -lc
gcc -g -Wall main.c -o app -I/usr/include/PCSC/ -lMyLib -lpcsclite
And another question: what should I do to avoid having to include a third party library (libpcsclite) that uses my library just created? I wonder if I generate in my library including libpcsclite library.
Pretty grateful!!

Resources