Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Not able use Check-C framework with arm-none-eabi-gcc compiler #321

Open
Kallappambk opened this issue Jan 11, 2021 · 3 comments
Open

Comments

@Kallappambk
Copy link

Hi,

i am trying to use Check framework for unit testing of C. and i have installed check framework as per the
step given in the below link https://libcheck.github.io/check/web/install.html#aptitude
and trying to compile unit test code using arm-none-eabi-gcc compiler,
but issue is like it is not able to find check.h header file during compilation.
and i have tried to use the same thing with gcc compiler and it is working perfectly fine.
Note :
Environement : Ubuntu 18.04
gcc version : 7.5.0
arm-none-eabi-gcc version : 6.3.1

Console log :
rohit@rohit:~/WorkSpace/Unit_testing/LinStack_UnitTesting/lin-stack-slave/tests$ arm-none-eabi-gcc test_lin.c
test_lin.c:2:19: fatal error: check.h: No such file or directory
#include <check.h>

Kindly help me how to use the check framework with arm-none-eabi-gcc toolchain as i am new to these things.
Thanks in advance

@mikkoi
Copy link
Contributor

mikkoi commented Jan 11, 2021

The arm-none-eabi-gcc version of GCC uses a non-standard include path. Use command gcc -xc -E -v - (arm-none-eabi-gcc -xc -E -v -) to see the include path.

I am not sure where libcheck is installed. Probably under /usr/local/include. You need to point the compiler to that directory: maybe arm-none-eabi-gcc -I/usr/local/include/. You might also need to specify the library path, option -L<path>.

If you will start to use Check, consider building it from scratch with the ARM toolchain. Then you will get the benefit of the library being compiled with the same build options as your main project. You can incorporate Check into you build system easily if you are using e.g. CMake or GNU Autotools.

@Kallappambk
Copy link
Author

hello @mikkoi ,

Thanks for your response.

I build the check with sources, and the check .h files are is present in the /usr/local/include folder.
but when I tried to compile like below getting the errors

arm-none-eabi-gcc -I/usr/local/include/ -L"/usr/lib" test_lin.c

error log:

rohit@rohit:~/Rohit_WorkSpace/Unit_testing/LinStack_UnitTesting/lin-stack-slave/tests$ arm-none-eabi-gcc -I/usr/local/include/ -L"/usr/lib" test_lin.c
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function exit': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to _exit'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function _sbrk_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to _sbrk'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function _write_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/writer.c:58: undefined reference to _write'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function _close_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/closer.c:53: undefined reference to _close'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function _fstat_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to _fstat'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function _isatty_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to _isatty'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function _lseek_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to _lseek'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function _read_r': /build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/readr.c:58: undefined reference to _read'
collect2: error: ld returned 1 exit status

I build the check with the following commands :

$ ./configure
$ make
$ make check
$ sudo make install

I also tried to build specifically for the arm-none-eabi-gcc compiler by executing the below command
./configure CC=arm-none-eabi-gcc

but getting error like :
rohit@rohit:~/Rohit_WorkSpace/arm_check/check-0.15.2$ ./configure CC=arm-none-eabi-gcc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... arm-none-eabi-gcc
checking whether the C compiler works... no
configure: error: in /home/rohit/Rohit_WorkSpace/arm_check/check-0.15.2': configure: error: C compiler cannot create executables See config.log' for more details

is anything i am missing ?
kindly help me to compile the test_lin.c file with arm-gcc-none-eabi compiler.

test_lin.c :

#include <stdio.h>
#include <check.h>
int main()
{

   printf("unit testing for the lin stack");

}

@mikkoi
Copy link
Contributor

mikkoi commented Jan 13, 2021

I wrote earlier

If you will start to use Check, consider building it from scratch with the ARM toolchain. Then you will get the benefit of the library being compiled with the same build options as your main project. You can incorporate Check into you build system easily if you are using e.g. CMake or GNU Autotools.

I was wrong about that. Sorry for the extra trouble. The compiler arm-none-eabi-gcc compiles code directly for 32-bit Arm Cortex-A, Arm Cortex-M, and Arm Cortex-R processor families. We cannot run that code in Ubuntu even if we succeeded in compiling it. The compilation fails because you are using library calls which are not present in that extremely limited libc library which Arm compiler uses (to make the executable smaller and more efficient).

You need to use a different approach. Isolate those parts of the code you want to test. Compile and link them separately with the normal GCC processor under normal circumstances. When compiling with normal GCC, it is easy to include Check.

AFAIK Check has never been used in an embedded solution project. We are breaking new ground here. I hope you succeed. I will help where I can but I have no experience from embedded code. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants