How to build a stm32 with cmake - c

I want to build a stm32 project with cmake. The host is Linux ubuntu 4.4.0-98-generic.
This is my CMakeLists.txt script file. I wrote this file refer to my Makefile. The Makefile works well.
cmake_minimum_required (VERSION 3.5)
set (CMAKE_SYSTEM_NAME Generic)
set (CMAKE_SYSTEM_PROCESSOR arm)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_ASM_COMPILER arm-none-eabi-as)
set (CMAKE_C_COMPILER arm-none-eabi-gcc)
set (CMAKE_OBJCOPY arm-none-eabi-objcopy)
set (CMAKE_OBJDUMP arm-none-eabi-objdump)
set (CMAKE_SIZE arm-none-eabi-size)
set (TARGET hUart)
set (MCU stm32f401re)
set (BOARD stm32f401re-nucleo)
set (APP uart)
set (CMAKE_ASM_FLAGS
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
)
set (CMAKE_C_FLAGS
-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
-fno-common -fsigned-char -fmessage-length=0
-Wall -Wextra -Wshadow
-Os -ffunction-sections -data-sections
-g3
-std=c11
)
set (CMAKE_EXE_LINKER_FLAGS
-spec=nosys.specs -spec=nano.specs -u _printf_float -u _scanf_float
-Wl,--gc-sections -Wl,-map=${TARGET}.map,--cref
)
add_definitions (
-DNDEBUG
-DSTM32F401xE -DUSE_HAL_DRIVER -DUSE_FULL_ASSERT
-DUSE_STM32F4XX_NUCLEO
)
project (${TARGET})
include_directories (
drivers/${MCU}/cmsis
drivers/${MCU}/hal
bsp/${BOARD}
projects/${BOARD}
apps/${APP}
)
file (GLOB STARTUP
drivers/${MCU}/startup/*.s
)
message (STATUS "[DBG]: ${STARTUP})
file (GLOB CMSIS_SRCS
drivers/${MCU}/cmsis/*.c
drivers/${MCU}/hal/*.c
)
file (GLOB BSP_SRCS
bsp/${BOARD}/*.c
)
file (GLOB APP_SRCS
projects/${BOARD}/*.c
apps/uart/*.c
)
message (STATUS "[DBG]: ${APP_SRCS})
set (LINKER_SCRIPT drivers/${MCU}/linker/STM32F401VEHx_FLASH.ld)
add_executable (${TARGET}.elf ${STARTUP} ${CMSIS_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
add_custom_target (${TARGET}.bin
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin
)
add_custom_target (${TARGET}.lst
DEPENDS ${TARGET}.elf
COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst
The error log like this.
ompiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /usr/bin/arm-none-eabi-gcc
Build flags: -mcpu=cortex-m4;-mthumb;-mfloat-abi=hard;-mfpu=fpv4-sp-d16;-fno-common;-fsigned-char;-fmessage-length=0;-Wall;-Wextra;-Wshadow;-Os;-ffunction-sections;-data-section
Id flags:
The output was:
1
cc1: warning: unrecognized gcc debugging option: t
cc1: warning: unrecognized gcc debugging option: -
cc1: warning: unrecognized gcc debugging option: s
cc1: warning: unrecognized gcc debugging option: e
cc1: warning: unrecognized gcc debugging option: c
cc1: warning: unrecognized gcc debugging option: t
cc1: warning: unrecognized gcc debugging option: i
cc1: warning: unrecognized gcc debugging option: o
cc1: warning: unrecognized gcc debugging option: n
cc1: warning: unrecognized gcc debugging option: s
/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libg.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.243r.c
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.253r.c
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.260r.c
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.245r.l
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.249r.l
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.231r.i
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.293r.s
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.247r.l
The C compiler identification could not be found in "/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c.244r.r
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/bin/arm-none-eabi-c++
Build flags:
Id flags:
The output was:
1
/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
Determining if the C compiler works failed with the following output:
Change Dir: /home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/local/bin/make" "cmTC_ff236/fast"
/usr/local/bin/make -f CMakeFiles/cmTC_ff236.dir/build.make CMakeFiles/cmTC_ff236.dir/build
make[1]: Entering directory '/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ff236.dir/testCCompiler.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_ff236.dir/testCCompiler.c.obj -c /home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp/te
Linking C executable cmTC_ff236
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_ff236.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_ff236.dir/testCCompiler.c.obj -o cmTC_ff236
/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_ff236.dir/build.make:98: cmTC_ff236] Error 1
make[1]: Leaving directory '/home/hoya/hWorkspace/EmbeddedStudy/projects/stm32f401re-nucleo/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:126: cmTC_ff236/fast] Error 2
Now, how can I fix this?
And, how to create the dependencies? I can do it '-MM -MT' options on Makefile.
All other options are exactly same as Makefile.

Related

How to Compile Openssl for linux-mips32 on a windows machine?

I have been struggling to build openssl for linux-mips32 using VS2015x native Tools.
I have set up perl and use the following command to configure:
perl Configure linux-mips32
--prefix=C:\Users\srivaspr\Downloads\openssl-1.0.2k.tar\openssl\builder
--openssldir=C:\Users\srivaspr\Downloads\openssl-1.0.2k.tar\openssl\builder
The configuration command works fine.
But when I use make command it gives the following error:
making all in crypto...
make[1]: Entering directory 'C:/Users/srivaspr/Downloads/openssl-1.0.2k.tar/openssl/crypto'
gcc -I. -I.. -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -mips2 -mabi=32 -O3 -Wall -DBN_DIV3W -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DAES_ASM -c -o cryptlib.o cryptlib.c
gcc: error: unrecognized argument in option '-mabi=32'
gcc: note: valid arguments to '-mabi=' are: ms sysv
gcc: error: unrecognized command line option '-mips2'
make[1]: *** [<builtin>: cryptlib.o] Error 1
make[1]: Leaving directory 'C:/Users/srivaspr/Downloads/openssl-1.0.2k.tar/openssl/crypto'
make: *** [Makefile:287: build_crypto] Error 1
I have searched through the internet multiple times but could not find anything relevant. Any help would be appreciated.

QT5.7 Cross compile for AM1808 ARM9

Currently, we are working on QT for application development for our hardware that runs on the AM1808 processor.
At present, we developed our app using QT creator with compiler version Qt 4.8.7.
We are planning to upgrade it with Qt 5.7 and for that, we download the corresponding package from
http://download.qt.io/official_releases/qt/5.7/5.7.1/single/qt-everywhere-opensource-src-5.7.1.tar.gz
We successfully download this and now need to configure according to our current arm toolchain.
we have modified the qmake.conf as per below,
#
# qmake configuration for building with arm-linux-gnueabi-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
// modifications to g++.conf
//QMAKE_CC = arm-linux-gnueabi-gcc
//QMAKE_CXX = arm-linux-gnueabi-g++
//QMAKE_LINK = arm-linux-gnueabi-g++
//QMAKE_LINK_SHLIB = arm-linux-gnueabi-g++
// modifications to linux.conf
//QMAKE_AR = arm-linux-gnueabi-ar cqs
//QMAKE_OBJCOPY = arm-linux-gnueabi-objcopy
//QMAKE_NM = arm-linux-gnueabi-nm -P
//QMAKE_STRIP = arm-linux-gnueabi-strip
QMAKE_CC = arm-none-linux-gnueabi-gcc
QMAKE_CXX = arm-none-linux-gnueabi-g++
QMAKE_LINK = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++
QMAKE_AR = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy
QMAKE_STRIP = arm-none-linux-gnueabi-strip
load(qt_config)
after that, we run config command
./configure -opensource -confirm-license -prefix /usr/local/Qt5 -no-pch -xplatform linux-arm-gnueabi-g++
but we found the following error,
System architecture: 'arm'
Host architecture: 'i386'
arm-none-linux-gnueabi-g++ -c -fvisibility=hidden fvisibility.c
Symbol visibility control enabled.
cc1plus: error: unrecognized command line option '-fuse-ld=gold'
arm-none-linux-gnueabi-g++ -o libtest.so -shared -Wl,-Bsymbolic-functions -fPIC bsymbolic_functions.c
bsymbolic_functions.c:2:2: error: #error "Symbolic function binding on this architecture may be broken, disabling it (see QTBUG-36129)."
Symbolic function binding disabled.
checking for C++14...
arm-none-linux-gnueabi-g++ -c -pipe -O2 -std=gnu++1y -Wall -W -fPIC -I. -I../../../mkspecs/linux-arm-gnueabi-g++ -o c++14.o c++14.cpp
cc1plus: error: unrecognized command line option '-std=gnu++1y'
make: *** [c++14.o] Error 1
C++14 disabled.
checking for default C++ standard edition...
arm-none-linux-gnueabi-g++ -pipe -O2 -Wall -W -fPIC -I. -I../../../mkspecs/linux-arm-gnueabi-g++ -o c++default.ii -E c++default.cpp
default C++ standard edition enabled.
checking for 64-bit std::atomic...
arm-none-linux-gnueabi-g++ -c -pipe -O2 -std=gnu++11 -Wall -W -fPIC -I. -I../../../mkspecs/linux-arm-gnueabi-g++ -o atomic64.o atomic64.cpp
cc1plus: error: unrecognized command line option '-std=gnu++11'
make: *** [atomic64.o] Error 1
64-bit std::atomic disabled.
checking for 64-bit std::atomic in -latomic...
arm-none-linux-gnueabi-g++ -c -pipe -O2 -std=gnu++11 -Wall -W -fPIC -I. -I../../../mkspecs/linux-arm-gnueabi-g++ -o atomic64.o atomic64.cpp
cc1plus: error: unrecognized command line option '-std=gnu++11'
make: *** [atomic64.o] Error 1
64-bit std::atomic in -latomic disabled.
checking for std::atomic for function pointers...
arm-none-linux-gnueabi-g++ -c -pipe -O2 -std=gnu++11 -Wall -W -fPIC -I. -I../../../mkspecs/linux-arm-gnueabi-g++ -o atomicfptr.o atomicfptr.cpp
cc1plus: error: unrecognized command line option '-std=gnu++11'
make: *** [atomicfptr.o] Error 1
std::atomic for function pointers disabled.
ERROR: detected a std::atomic implementation that fails for function pointers.
Please apply the patch corresponding to your Standard Library vendor, found in
/opt/qt-everywhere-opensource-src-5.7.1/qtbase/config.tests/common/atomicfptr
so, please suggest us correct method to compile this qt5 version.
Your toolchain is too old. Qt 5.6 was the last release which doesn't require a more or less fully C++ 11 compliant compiler. This changed with Qt 5.7.
Either upgrade your toolchain to 4.8 (at least) or try Qt 5.6.

eclipse build error in c project

i use eclipse ide for c project on mac computer
i install usblib
sudo brew install libusb
and my program
#include <stdio.h>
#include <stdlib.h>
#include <libusb-1.0/libusb.h>
int main(void) {
libusb_context **libcontext;
int status = libusb_init(libcontext);
if (status == 0) {
printf("success");
}
}
the libusb is at
when i build error
10:17:53 **** Build of configuration Debug for project testusb ****
make all Building file: ../src/testusb.c Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -stdlib=libstdc++ -MMD -MP
-MF"src/testusb.d" -MT"src/testusb.o" -o "src/testusb.o" "../src/testusb.c" ../src/testusb.c:16:6: warning: unused variable
'status' [-Wunused-variable]
int status = libusb_init(libcontext);
^ ../src/testusb.c:16:27: warning: variable 'libcontext' is uninitialized when used here [-Wuninitialized]
int status = libusb_init(libcontext);
^~~~~~~~~~ ../src/testusb.c:15:29: note: initialize the variable 'libcontext' to silence this warning
libusb_context libcontext;
^
= NULL 2 warnings generated. Finished building: ../src/testusb.c Building target: testusb
Invoking: Cross GCC Linker gcc -L/opt/local/lib -o "testusb"
./src/testusb.o Undefined symbols for architecture x86_64:
"_libusb_init", referenced from:
_main in testusb.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to
see invocation) make: * [testusb] Error 1
how to fix that?
thanks #Fang suggestion Libusb undefined reference to
i solve the problem.
first type
pkg-config --list-all
query all installed libraries,check libusb whether installed,
then type
pkg-config --libs libusb
link against the libusb i want to use
there should be the output
-lusb
then right click project properties->c/c++ Build->Setting->Cross GCC Linker Miscellaneous,type -lusb-1.0

Error while trying to create shared library

I am trying to create the shared library (.so) so that I can call it using .External command from R for the lassoshooting package:
https://cran.r-project.org/web/packages/lassoshooting/
Basically, I have downloaded the package source from the above website. However, when I go the the correct directory (.../lassoshooting/src) and use the command
R CMD SHLIB -o ccd_r.so ccd_r.c
I get the following error:
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o ccd_r.so ccd_r.o -L/Library/Frameworks/R.framework/Resources/lib
-lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [ccd_r.so] Error 1
Why is this happening?

Msys compile of C code

I'm not very familiar with compiling C code, especially on Windows using MinGW/Msys. Here is my problem. I am attempting to compile an open-source M3u8-segmenter C code for Windows. The open-source examples all deal with linux, but I have successfully compiled the code on my Mac OSX machine without a problem.
In Msys on Windows, the ./configure is successful, but once I do the Make, I get the following error. It appears to related to the signal.h include, but I'm not sure. Any insight would be appreciated.
make[1]: Entering directory `/home/install/m3u8-segmenter-master/tests'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/install/m3u8-segmenter-master/tests'
make[1]: Entering directory `/home/install/m3u8-segmenter-master'
gcc -DPACKAGE_NAME=\"m3u8-segmenter\" -DPACKAGE_TARNAME=\"m3u8-segmenter\" -DPAC
KAGE_VERSION=\"0.3\" -DPACKAGE_STRING=\"m3u8-segmenter\ 0.3\" -DPACKAGE_BUGREPOR
T=\"http://github.com/johnf/m3u8-segmenter/issues\" -DPACKAGE_URL=\"http://m3u8-
segmenter.inodes.org\" -DPACKAGE=\"m3u8-segmenter\" -DVERSION=\"0.3\" -DSTDC_HEA
DERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_
H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -
DHAVE_UNISTD_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SIGNAL_H=1 -DHAVE_GETOPT_H=1 -DHAVE
_STDLIB_H=1 -DHAVE_MALLOC=1 -DHAVE_MEMMOVE=1 -DHAVE_MEMSET=1 -DHAVE_STRRCHR=1 -D
HAVE_STRTOL=1 -I. -Ic:/msys/1.0/local/include -g -O2 -Wall -Wextra -Wdeclar
ation-after-statement -Wpointer-arith -funsigned-char -Werror -Wall -Wstrict-pro
totypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wcast-qual -Wneste
d-externs -Wshadow -Wbad-function-cast -Wwrite-strings -MT m3u8_segmenter-m3u8-
segmenter.o -MD -MP -MF .deps/m3u8_segmenter-m3u8-segmenter.Tpo -c -o m3u8_segme
nter-m3u8-segmenter.o `test -f 'm3u8-segmenter.c' || echo './'`m3u8-segmenter.c
m3u8-segmenter.c: In function 'main':
m3u8-segmenter.c:212:22: error: storage size of 'act' isn't known
m3u8-segmenter.c:413:5: error: implicit declaration of function 'sigaction' [-We
rror=implicit-function-declaration]
m3u8-segmenter.c:413:5: error: nested extern declaration of 'sigaction' [-Werror
=nested-externs]
m3u8-segmenter.c:212:22: error: unused variable 'act' [-Werror=unused-variable]
cc1.exe: all warnings being treated as errors
make[1]: *** [m3u8_segmenter-m3u8-segmenter.o] Error 1
make[1]: Leaving directory `/home/install/m3u8-segmenter-master'
make: *** [all-recursive] Error 1
To emulate UNIX on Windows, Cygwin is more appropriate than MSys/MinGW as pointed by this post

Resources