How to build linux MCC Pingpong example?

Hi,

I’m trying to build the MCC pingpong example available at http://repository.timesys.com/buildsources/m/mcc-pingpong/mcc-pingpong-1.0. I’m using toradex-linux at branch toradex_vf_4.1-next and Colibri_VF_LinuxConsoleImageV2.5_20151216.

The first problem is with the files included in pingpong.c

#include <linux/mcc_config.h>
#include <linux/mcc_common.h>
#include <mcc_api.h>
#include <linux/mcc_linux.h>

Do I need to copy these files to toradex-linux kernel folder or provide the headers inside the application folder?

The second problem is that my Makefile can’t link with libmcc? My Makefile is:

###############################################################################
# Setup build environment
###############################################################################

# Set the prefix for the cross compiler
CROSS_COMPILE ?= arm-linux-gnueabihf-

# Set path to the target libraries
OECORE_TARGET_KERNEL  ?= ../../linux-toradex/
OECORE_TARGET_SYSROOT ?= /srv/nfs/rootfs/
    
###############################################################################
# Setup project settings
###############################################################################

SRC = ./src/pingpong.c
INC += -I./src

PROG = mcc-pingpong
LIBS += -lmcc

# Set flags to the compiler and linker

ARCH_CFLAGS = -march=armv7-a -fno-tree-vectorize -mthumb-interwork \
        -mfloat-abi=hard -mtune=cortex-a5

CFLAGS = -O0 -g -Wall $(INC) $(ARCH_CFLAGS)
LDFLAGS = -L$(OECORE_TARGET_SYSROOT)usr/lib \
        -Wl,-rpath-link,$(OECORE_TARGET_SYSROOT)usr/lib \
        -L$(OECORE_TARGET_SYSROOT)lib \
        -Wl,-rpath-link,$(OECORE_TARGET_SYSROOT)lib

###############################################################################
# This section of Makefile usually needs no change
###############################################################################

# Toochain binaries
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
STRIP = $(CROSS_COMPILE)strip
RM = rm -rf

# Sets the output filename and objects files
PROG := $(PROG)
OBJS = $(SRCS:.c=.o)
DEPS = $(OBJS:.o=.o.d)

-include $(DEPS)
    
all: $(PROG)

$(PROG): $(OBJS) Makefile
        $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
#       $(STRIP) $@

%.O: %.C
        $(CC) -c $(CFLAGS) -O $@ $<
        $(CC) -MM $(CFLAGS) $< > $@.d

clean:
        $(RM) $(DEPS) $(OBJS) $(PROG)

Can anyone help me?

What linking error do you get?

@stefan.agner

The error that I was getting is -lmcc not found. I fixed this error by creating a symbolic link.

/srv/nfs/rootfs/usr/lib: sudo ln -s libmcc.so.1.0 libmcc.so

I don’t know why this is necessary.

To build the example I copied the files mcc_config.h, mcc_common.h and mcc_linux.h to linux-toradex/include/linux and add a include path to linux-toradex/include in Makefile.

Since mcc_api.h was not provided with the example I used the same used in MQX.

Is this the best method?

Yeah libmcc uses a versioned soname. There has also been an issue with mcc-pingpong related, which has been resolved with that patch:
https://lists.yoctoproject.org/pipermail/meta-freescale/2015-January/012227.html

You should link to libmcc in a similar fashion.

To make sure that all header files, static and dynamic libraries are in place, I recommend to use either the OpenEmbedded sysroot or the OpenEmbedded’s SDK feature.

OE sysroot option

After building a OE image, the sysroot will be available in the subdirectory ./out-glibc/sysroots/colibri-vf of your OE build directory. By using the gcc option --sysroot=/path/to/sysroot, you can make sure that the compiler picks up include files as well as libraries from that sysroot.

OE SDK option

Use the following command to build a SDK:

bitbake  -c populate_sdk angstrom-lxde-image

With that, you will get an SDK installer in the subdirectory out-glibc/deploy/sdk/. Install the SDK to your host, and you will have a sysroot /usr/local/oecore-x86_64/sysroots/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/. Use the --sysroot option for your cross compiler similar to above.