1

So, I am developing an embedded library for RIOT OS. Since my library is using Cmake, but RIOT uses a simple Makefile, I just compile a static library and link this later to RIOT while compile time. So I compile the library: I pass all the include files to the CMAKE_C_FLAGS This is needed, since my library uses pthreads and RIOT has support for it.

-DCMAKE_C_FLAGS="-I/home/citrullin/git/riot_libs/core/include -I/home/citrullin/git/riot_libs/drivers/include -I/home/citrullin/git/riot_libs/sys/include -I/home/citrullin/git/riot_libs/boards/native/include -DNATIVE_INCLUDES -I/home/citrullin/git/riot_libs/boards/native/include/ -I/home/citrullin/git/riot_libs/core/include/ -I/home/citrullin/git/riot_libs/drivers/include/ -I/home/citrullin/git/riot_libs/cpu/native/include -I/home/citrullin/git/riot_libs/sys/include -I/home/citrullin/git/riot_libs/cpu/native/include -I/home/citrullin/git/riot_libs/examples/iota_transaction_node/bin/pkg/native/iota-wallet/src -I/home/citrullin/git/riot_libs/sys/posix/include -I/home/citrullin/git/riot_libs/sys/posix/pthread/include" .

So that works fine. But somehow cmake also tries to include linux header files for posix. Since this is embedded, it shouldn't do that.

Scanning dependencies of target iota_wallet
[ 11%] Building C object CMakeFiles/iota_wallet.dir/src/iota/addresses.c.obj
In file included from /usr/arm-none-eabi/include/sys/types.h:239:0,
                 from /usr/arm-none-eabi/include/stdio.h:61,
                 from /home/citrullin/git/riot_libs/examples/iota_transaction_node/bin/pkg/bluepill/iota-wallet/src/iota/common.h:4,
                 from /home/citrullin/git/riot_libs/examples/iota_transaction_node/bin/pkg/bluepill/iota-wallet/src/iota/addresses.c:2:
/usr/arm-none-eabi/include/sys/_pthreadtypes.h:154:20: note: previous declaration of 'pthread_mutex_t' was here
 typedef __uint32_t pthread_mutex_t;      /* identify a mutex */

So, my question: How can I tell cmake not to include the linux header files?

This is the current CMakeList.txt I use.

/e I tried the same with a Makefile. Same issue appears here.

make -e CFLAGS="-isystem /usr/arm-none-eabi/include/newlib-nano -I/home/citrullin/git/riot_libs/core/include -I/home/citrullin/git/riot_libs/drivers/include -I/home/citrullin/git/riot_libs/sys/include -I/home/citrullin/git/riot_libs/boards/bluepill/include -I/home/citrullin/git/riot_libs/boards/common/stm32f103c8/include -I/home/citrullin/git/riot_libs/cpu/stm32f1/include -I/home/citrullin/git/riot_libs/cpu/stm32_common/include -I/home/citrullin/git/riot_libs/cpu/cortexm_common/include -I/home/citrullin/git/riot_libs/cpu/cortexm_common/include/vendor -I/home/citrullin/git/riot_libs/sys/libc/include -I/home/citrullin/git/riot_libs/examples/iota_transaction_node/bin/pkg/bluepill/iota-wallet/src -I/home/citrullin/git/riot_libs/sys/posix/include -I/home/citrullin/git/riot_libs/sys/posix/pthread/include" lib
arm-none-eabi-gcc -c -o build/addresses.o src/iota/addresses.c -isystem /usr/arm-none-eabi/include/newlib-nano -I/home/citrullin/git/riot_libs/core/include -I/home/citrullin/git/riot_libs/drivers/include -I/home/citrullin/git/riot_libs/sys/include -I/home/citrullin/git/riot_libs/boards/bluepill/include -I/home/citrullin/git/riot_libs/boards/common/stm32f103c8/include -I/home/citrullin/git/riot_libs/cpu/stm32f1/include -I/home/citrullin/git/riot_libs/cpu/stm32_common/include -I/home/citrullin/git/riot_libs/cpu/cortexm_common/include -I/home/citrullin/git/riot_libs/cpu/cortexm_common/include/vendor -I/home/citrullin/git/riot_libs/sys/libc/include -I/home/citrullin/git/riot_libs/examples/iota_transaction_node/bin/pkg/bluepill/iota-wallet/src -I/home/citrullin/git/riot_libs/sys/posix/include -I/home/citrullin/git/riot_libs/sys/posix/pthread/include
In file included from /home/citrullin/git/riot_libs/sys/posix/pthread/include/pthread.h:38:0,
                 from src/iota/conversion.h:13,
                 from src/iota/addresses.c:8:
/home/citrullin/git/riot_libs/sys/posix/pthread/include/pthread_threading_attr.h:34:3: error: conflicting types for 'pthread_attr_t'
 } pthread_attr_t;
   ^~~~~~~~~~~~~~
In file included from /usr/arm-none-eabi/include/sys/types.h:239:0,
                 from /usr/arm-none-eabi/include/stdio.h:61,
                 from src/iota/addresses.c:2:
/usr/arm-none-eabi/include/sys/_pthreadtypes.h:75:3: note: previous declaration of 'pthread_attr_t' was here
 } pthread_attr_t;
   ^~~~~~~~~~~~~~
In file included from /home/citrullin/git/riot_libs/sys/posix/pthread/include/pthread.h:38:0,
                 from src/iota/conversion.h:13,
                 from src/iota/addresses.c:8:
/home/citrullin/git/riot_libs/sys/posix/pthread/include/pthread_threading_attr.h:39:8: error: redefinition of 'struct sched_param'
 struct sched_param {
        ^~~~~~~~~~~
In file included from /usr/arm-none-eabi/include/sys/_pthreadtypes.h:23:0,
                 from /usr/arm-none-eabi/include/sys/types.h:239,
                 from /usr/arm-none-eabi/include/stdio.h:61,
                 from src/iota/addresses.c:2:
/usr/arm-none-eabi/include/sys/sched.h:48:8: note: originally defined here
 struct sched_param {
        ^~~~~~~~~~~

There are more of these duplicate definition errors. Looks like they are all of the same nature.

Steps to reproduce:

  1. Clone this repository (branch: iota_new_implementation)

  2. cd into the folder examples/iota_transaction_node

  3. Execute make

Version with Makefile. Commit: 7e1d8884ab135ae64cee02c8c1a447015f4325bc

Version with CMake. Commit: dbf32e727889afa3efb466cfdc8561e697af48b0

USEPKG += iota-wallet

in the Makefile of the example refers to this package. This Makefile is used to make the static library.

Cmake Log:

CmakeError.log

CMakeOutput.log

Console Output

Makefile:

Console Output

4

2 回答 2

1

问题不在于使用 POSIX 标头嵌入的 CMake。这是对错误的误解。

我认为混乱来自线路Scanning dependencies of target iota_wallet然后[ 11%] Building C object CMakeFiles/iota_wallet.dir/src/iota/addresses.c.obj。这是两个不同的步骤,它们都不涉及 CMake。CMake 没有扫描任何东西。当 CMake 生成 Makefiles 时,它只是将 CMakeLists.txt 添加为构建依赖项的一部分。如此更新 CMakeLists.txt 将在运行 make 时重新生成新的 Makefile。当它这样做时,它会打印Scanning dependencies....

实际问题发生在使用arm-none-eabi. newlib该编译器作为其 c 库附带。无论出于何种原因,都newlib包含一些 pthread 的头文件。每当您在源代码中包含头文件stdint.h时,它都会包含. 这与 RIOT 附带的头文件冲突。stdlib.hsys/types.hsys/_pthreadtypes.hpthreads

您可以通过编译来解决此问题-std=c99

或者您可以通过编辑文件来解决此问题/usr/arm-none-eabi/include/sys/_pthreadtypes.h

改变:

#if defined(_POSIX_THREADS) || __POSIX_VISIBLE >= 199506

至:

#if defined(_POSIX_THREADS)

仅供参考,Makefile 和 CMake 示例仍然存在问题,但与特定问题无关。

有关该问题的更多详细信息,请参阅https://github.com/RIOT-OS/RIOT/issues/10443 。newlib

于 2018-12-01T07:31:45.737 回答
-1

好的,首先,确保您将工具链 gcc 添加到路径中(参见wiki

然后,在这个github repo这个相关页面上构建,您可以查看实际使用 CMake 和 RIOT 的人的示例(这不是我的情况,显然也不是 RIOT 开发人员),他制作了自定义文件以查找RIOT 和目标板,所以我认为它应该作为一个起点有所帮助。

一旦你有 RIOT 检测工作,如果 pthread 问题仍然存在,在你按照 Fred 的建议手动编辑系统文件之前,我会考虑尝试从 CMake 强制 pthread 检测并提示 RIOT:

find_package (Threads REQUIRED PATHS ${RIOT_ROOT}/sys/posix/pthread/include NO_DEFAULT_PATH)

编辑重新考虑这个问题,也许我应该澄清一些事情:我认为最重要的想法是你正确地重新格式化你的 CMakeLists.txt 基于来自 polymcu repo 的那个,以正确设置交叉编译(尤其是设置CMAKE_SYSTEM_NAME)。一旦 CMake 了解它是交叉编译,它就不应该使用 POSIX,这应该导致__POSIX_VISIBLE >= 199506系统的部分包含评估为假,从而消除任何手动编辑的需要。这也是为什么,find_package我提出的命令是最后的手段,以防万一,应该马上使用。

当务之急是正确配置您的 CMake,这应该会使问题自行消失。

于 2018-12-01T07:48:22.317 回答