Makefile cmake for embedded:删除Linux POSIX头

Makefile cmake for embedded:删除Linux POSIX头,makefile,cmake,gnu-make,riot-os,Makefile,Cmake,Gnu Make,Riot Os,因此,我正在为RIOT OS开发一个嵌入式库。由于我的库使用的是Cmake,但RIOT使用的是一个简单的Makefile,所以我只编译了一个静态库,并在编译时将其链接到RIOT。因此,我编译库:我将所有包含文件传递给CMAKE_C_标志 这是必需的,因为我的库使用pthreads并且RIOT支持它 -DCMAKE_C_FLAGS="-I/home/citrullin/git/riot_libs/core/include -I/home/citrullin/git/riot_libs/driver

因此,我正在为RIOT OS开发一个嵌入式库。由于我的库使用的是Cmake,但RIOT使用的是一个简单的Makefile,所以我只编译了一个静态库,并在编译时将其链接到RIOT。因此,我编译库:我将所有包含文件传递给CMAKE_C_标志 这是必需的,因为我的库使用pthreads并且RIOT支持它

-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" .
这样就行了。但不知何故,cmake也试图为posix包含linux头文件。因为这是嵌入的,所以不应该这样做

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 */
所以,我的问题是:我如何告诉cmake不要包含linux头文件

这是

/e我用一个Makefile做了同样的尝试。同样的问题也出现在这里

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 {
        ^~~~~~~~~~~
这些重复定义错误还有很多。看起来他们都是一样的

复制步骤:

克隆此分支:物联网新实施

将cd放入文件夹examples/iota\u transaction\u节点

执行make

带有Makefile的版本。提交:7e1d8884ab135ae64cee02c8c1a447015f4325bc

使用CMake的版本。提交:dbf32e727889afa3efb466cfdc8561e697af48b0

USEPKG += iota-wallet
在示例的Makefile中,引用。 用于创建静态库

Cmake日志:

生成文件:


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

我认为混淆源于目标物联网钱包的行扫描依赖性,然后[11%]构建C对象CMakeFiles/iota\u wallet.dir/src/iota/addresses.C.obj。这是两个不同的步骤,它们都不涉及CMake。CMake没有扫描任何东西。当CMake生成Makefiles时,它只是将CMakeLists.txt添加为构建依赖项的一部分。因此,在运行make时,更新CMakeLists.txt将重新生成新的makefile。执行此操作时,它将打印扫描依赖项

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

您可以通过使用-std=c99编译来解决这个问题

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

更改:

如果定义了|POSIX_线程| | POSIX_可见>=199506

致:

如果已定义_POSIX_线程

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


有关newlib问题的更多详细信息,请参阅。

好的,首先,确保已将工具链gcc添加到路径cf中

然后,在此基础上,你可以看一看实际使用CMake和RIOT的人的例子,这不是我的情况,显然也不是RIOT开发者的情况,他制作了自定义文件来查找RIOT和目标板,所以我认为这应该是一个有帮助的起点

一旦您进行了防暴检测,如果pHOST问题仍然存在,在您手动编辑弗莱德建议的系统文件之前,我会考虑尝试将来自CMake的pTrk检测提示为RoOT:

find_package (Threads REQUIRED PATHS ${RIOT_ROOT}/sys/posix/pthread/include NO_DEFAULT_PATH)
编辑重新思考这个问题,也许我应该澄清一些事情: 我认为最重要的一点是,您需要根据正确设置交叉编译的设置来正确地重新格式化CMakeLists.txt。 一旦CMake了解到它是交叉编译,它就不应该使用POSIX,这将导致系统include的uu POSIX_VISIBLE>=199506部分计算为false,从而消除任何手动编辑的需要。 这也是为什么我建议的find_package命令是最后的手段,以防万一,不应该立即使用


首要任务是正确配置您的CMake,这将使问题自行解决。

我不确定您是否可以在包含stdlib.h的同时做到这一点。。。你能避免这个include吗?@Silmathoron我在RIOT中将它改为native,所以使用了arm-none-eabi编译器。我改变了问题。混淆之处在于arm none eabi包含pthreads的头文件。这不应该存在,因为arm none eabi不针对任何供应商或操作系统。pthreads是特定于操作系统的东西。我对此有点惊讶。。。也许这是一个错误的怀疑,但也许你没有告诉编译器你认为你是什么。你能发布cmake配置日志吗?我认为这个设置不足以进行交叉编译。看见我注意到RIOT OS有一个用于生成工具链文件的助手脚本@弗雷德,我把回购协议联系起来了,你可以复制它。我不确定,但我想我已经使用了工具链生成器。我可以用Makefile重现相同的问题。您可以在这里看到使用cmake时,Makefile的外观
nt指出,由于这个问题,所有使用Makefiles构建的RIOT POSIX测试在使用gnu99编译时都有相同的编译器错误。命令是:RIOT/tests/pthread$CFLAGS=-std=gnu99 make BOARD=bluepillyes,显然。。。gnu99导致uuu POSIX_VISIBLE>=199506计算为true…gnu99意味着使用gnu编译器扩展名,而不是让c库在与正确的RIOS系统头文件冲突的非标准头文件中定义pthread。很明显,c库不是POSIX系统库,但这是标志的结果,请参阅和以获取示例