Basically, I have the paho-mqtt-c library installed in my rootfs using Yocto build environment. Since it was already included in meta-oe layer, I simply had to add that recipe to IMAGE_INSTALL_append variable.
I confirmed this by checking the following:
root#am65xx-evm:/usr/lib# ls | grep mqtt
libpaho-mqtt3a.so.1
libpaho-mqtt3a.so.1.0
libpaho-mqtt3as.so.1
libpaho-mqtt3as.so.1.0
libpaho-mqtt3c.so.1
libpaho-mqtt3c.so.1.0
libpaho-mqtt3cs.so.1
libpaho-mqtt3cs.so.1.0
Being a novice with building cross-compiled applications and setting up tool chains, I have a basic question which I couldn't exactly find an answer for.
Now that my target machine has the library installed, how to I develop an application on my host machine running Ubuntu 18.04 LTS?
I can do apt-get install and get the same library, but using the cross compiler to compile the C file, it is not able to see the the MQTT Library.
For example:
~/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc mqtt-test.c -l paho-mqtt3c
mqtt-test.c:4:10: fatal error: MQTTClient.h: No such file or directory
#include "MQTTClient.h"
^~~~~~~~~~~~~~
compilation terminated.
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
SRC_URI = "file://mqtt-test.c \
file://COPYING"
S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"
DEPENDS = "paho-mqtt-c"
do_compile() {
${CC} mqtt-test.c -o mqtt-test ${CFLAGS} -lpaho-mqtt3c
}
do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/mqtt-test ${D}${bindir}
}
This is the recipe I used with the following directory structure:
Ignore the lmbench and hello-world - they were a sample from TI's tutorial.
Notice the DEPENDS = "paho-mqtt-c"
Apparently the -lpaho-mqtt3c flag with the do_compile() seemed to work this time.
I still wonder why I could't simply invoke the Linaro compiler and compile this separately.
Related
I am trying to write a PulseAudio module. To start, first, I wrote the following minimal code for a module as mentioned by this documentation.
#include <pulsecore/module.h>
int pa__init(pa_module *m)
{
return 0;
}
I tried compiling it with this command:
gcc -g -shared -o module-test.so module-test.c
But it gives error:
pulsecore/module.h: No such file or directory
#include <pulsecore/module.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
After searching on the internet, I found that I have to installed libpulse-dev, but I have already installed pulseaudio and libpulse-dev as you can see below.
jyotesh#jyotesh-VM:~$ sudo apt install pulseaudio libpulse-dev
[sudo] password for jyotesh:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libpulse-dev is already the newest version (1:11.1-1ubuntu7.2).
pulseaudio is already the newest version (1:11.1-1ubuntu7.2).
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
I have tried searching for the header file using locate, find, apt-file, etc. I am not able to find where this header file is.
Does anyone know how to compile the PulseAudio module?
I was able to compile the code and build module-test.so file by following the steps from here and here. I will repeat the steps here:
First, I built and installed PulseAudio v12.2 from the source code.
# Clone PulseAudio git repository
git clone https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
# I wanted 12.2 version of PulseAudio, so I checked out that version
cd pulseaudio
git checkout tags/v12.2
# Install the dependencies
sudo apt-get -y build-dep pulseaudio
# Build PulseAudio source code
./bootstrap.sh
make
# Install and configure dynamic linker run-time bindings (so that
# ld can find the libraries that you specify while building your module)
sudo make install
sudo ldconfig
After this, I wrote minimal code for a module.
#include <config.h> // this is required, otherwise you will get compilation errors
#include <pulsecore/module.h>
int pa__init(pa_module *m)
{
return 0;
}
To compile this, I used the command
gcc -g -shared -fPIC -I/home/jyotesh/pulseaudio -I/home/jyotesh/pulseaudio/src -L/home/jyotesh/pulseaudio/.libs -L/usr/local/lib/pulseaudio -o module-test.so module-test.c -lpulsecore-12.2 -lpulsecommon-12.2 -lpulse
I've installed
sudo apt-get install libbluetooth-dev
to have bluetooth package in my environment.
Hence, using the following command can successfully compile the bluetooth code using gcc.
gcc -o bt bt.c -lbluetooth
However, when I tried to use the cross-compiler to compile the source code
$CC -o bt2 bt.c -lbluetooth
I got the fatal error:
fatal error: bluetooth/bluetooth.h: No such file or directory
compilation terminated
Is there anything I've done wrong or I need to link this library to this cross-compiler ?
Thanks
I guess your cross compiler comes with a complete toolchain and SDK.
You must check that e.g. libBluetooth.so installed into your SDK under /usr/lib or /usr/local/lib folders and the correct header, as the one installed for i386/x64 platform, is present into SDK.
In case of the header and lib exist you must change your #include into your code to match the path into your SDK.
I build embedded machines that run an RT_PREMPT version of Linux. It's an Ubuntu 10.04 installation running an Linux 2.6 kernel. Yes, it's an old kernel, but I'm stuck with it for awhile.
When I compiled the kernel, I used gcc version 4.4. On this system, there is a kernel module I have been compiling successfully for three years.
From my Makefile...
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) \
modules
My current project requires support for c++14, so I updated gcc and g++ to version 5.1.0 by building from source. All my user-mode software compiles, but when I went to build an updated version of my kernel module, I get the following error right away:
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-54-generic'
CC [M] /home/tbj/srcroot/ctsengine-hg/CtsRt/ctsrt_main.o
In file included from include/linux/compiler.h:40:0,
from include/linux/stddef.h:4,
from include/linux/list.h:4,
from include/linux/module.h:9,
from /home/tbj/srcroot/ctsengine-hg/CtsRt/ctsrt_main.c:31:
include/linux/compiler-gcc.h:86:30: fatal error: linux/compiler-gcc5.h: No such file or directory
In short:
fatal error: linux/compiler-gcc5.h: No such file or directory
If I use gcc 4.4 again (I left it installed on my computer in a different directory), it compiles and runs perfectly.
Obviously, I'm missing something. Is it not possible to compile a kernel module with a newer version of the compiler than what the operating system was compiled with? That seems unlikely to me. Is there a configuration step I'm missing? Is there a system variable I need to update? Are there extra headers I'm supposed to download? I ran apt to update build-essential, but it was up to date. I have the source and headers for the kernel on my system. I'm not sure what else I would download.
Any insights to this problem are greatly appreciated. Thank you in advance.
Your kernel version is too old and it is missing linux/compiler-gcc5.h.
The header is included from linux/compiler-gcc.h and its name is generated by preprocessor macro based on current compiler version:
#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
This header was introduced around version 3.18.
You might try to get this file from a newer kernel source and put in into include/linux.
Open a terminal and type:
$ ls -r /usr/src/linux-headers-$(uname -r)/include/linux/ | \
grep -P "compiler-gcc\d.h" | \
head -n 1
this will hopefully output the latest gcc header suitable for your linux kernel.
In my case it is compiler-gcc4.h. Now you can link this file to compiler-gcc5.h in the following way:
$ sudo ln -s /usr/src/linux-headers-$(uname -r)/include/linux/compiler-gcc4.h \
/usr/src/linux-headers-$(uname -r)/include/linux/compiler-gcc5.h
I'm trying to get address sanitizer working on FreeBSD 10.1 Release, but whenever I try to compile a program with -fsanitize=address I get undefined references to _asan_stack_malloc_1 etc, etc. I found
https://forums.freebsd.org/threads/gcc-clang-address-sanitizer.47985/ on google but the suggestion of adding -L/usr/local/lib -I/usr/local/include didn't resolve the linking issue. I tried the llvm binaries for FreeBSD but when I go to compile with that clang I get /usr/bin/../lib/clang/3.6.0/lib/freebsd/libclang_rt.asan-x86_64.a , no such file or directory. . Either way I'm not sure what library I need to link or where it is.
Below is the program I tried compiling and here is the command I used,
clang -fsanitize=address san.c
#include <stdio.h>
int main(void)
{
return 0;
}
As an alternative to building LLVM, as suggested in this answer on Unix SE, you can install llvm37 from ports, which supports AddressSanitizer, and build with that:
# pkg install llvm37
$ clang37 -fsanitize=address san.c
To use asan on FreeBSD you can build llvm with asan support as shown below or you can install from packages/ports like in Kevinoid's answer.
Step one, grab the latest stable llvm source.
fetch http://llvm.org/releases/3.9.0/llvm-3.9.0.src.tar.xz
Now uncompress the llvm source directory.
tar -xvf llvm-3.9.0.src.tar.xz
Next change directory to llvm and grab the clang source files.
cd llvm-3.9.0.src/tools && fetch http://llvm.org/releases/3.9.0/cfe-3.9.0.src.tar.xz
Uncompress clang.
tar -xvf cfe-3.9.0.src.tar.xz
Enter the projects directory and grab compiler-rt.
cd ../projects && fetch http://llvm.org/releases/3.9.0/compiler-rt-3.9.0.src.tar.xz
Uncompress compiler-rt.
tar -xvf compiler-rt-3.9.0.src.tar.xz
Goto the root llvm directory and make a build directory for cmake.
cd ../ && mkdir build && cd build
Use cmake to setup the llvm build.
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON [-DLLVM_ENABLE_WERROR=ON] [-DLLVM_TARGETS_TO_BUILD=X86] -DBUILD_SHARED_LIBS=ON ../
Build llvm and go grab some tea, it will take a bit.
make -j12
If the build worked you should be left with clang with asan support. Make sure to remove the old compiler, /usr/bin/clang, /usr/bin/clang++ and /usr/bin/cc.
Then install the new clang by doing sudo make install. Finally you will probably want to link /usr/bin/cc to /usr/local/bin/clang by running sudo ln /usr/local/bin/clang /usr/bin/cc.
After doing all these steps you should be able to compile code with the -fsanitize=address compile option.
I'd like to implement some features of libgcrypt in my program, but it is currently running on Windows, OSX, and Linux (Arch/Xubuntu), so I can only really do so if I can build it for all three platforms. On OSX and Linux I had no problem.
I got the sources from the github page for libgcrypt and libgpg-error, and I've successfully built and run the libraries on both Linux and OSX, so I know that my test code is valid (which I am now having trouble with on Windows w/MinGW).
I did the following on Xubuntu (and similar on Arch but using pacman instead of apt-get):
sudo apt-get install mingw32 mingw32-runtime mingw32-binutils
to get the cross compiling tool chain and
git clone https://github.com/Chronic-Dev/libgcrypt.git
git clone https://github.com/Chronic-Dev/libgpg-error.git
cd libgpg-error
autoreconf -vfi
./autogen.sh --build-w32
make
sudo make install
cd ../libgcrypt
autoreconf -vfi
./autogen.sh --build-w32
make
sudo make install
to build, and it successfully builds these files in home/myuser/w32root/:
libgcrypt.a
libgcrypt.def
libgcrypt.dll.a
libgcrypt.la
libgpg-error.dll.a
libgpg-error.la
include/
gcrypt.h
gcrypt-module.h
gpg-error.h
I took these files over to windows, and tried compiling the test code (named main.c locally) with
gcc main.c -o main.exe -lgcrypt
but I get undefined reference errors leading me to the conclusion that the library wasn't linked correctly (initially only using libgcrypt.a), so I looked some stuff up, and found that some libraries require a set of files like .a, .def, et al. to work, so I dropped them all in C:\Mingw\lib to see if it made a difference; it didn't. The following was also silent in finding the library file to link, but didn't resolve the undefined references:
gcc main.c -o main.exe -lgcrypt -lgpg-error
So I'm not really sure where to go from here. The readme doesn't get into cross compiling too much, like what files to copy and link once you're on the Windows side. Any pointers (to docs for it I missed maybe?) are appreciated! Thanks a bunch for reading my wall of text.