因此,我正在为RIOT OS开发嵌入式库。由于我的库使用的是Cmake,但是RIOT使用简单的Makefile,因此我只编译一个静态库,然后在编译时将此库链接到RIOT。所以我编译了库:我将所有包含文件传递给CMAKE_C_FLAGS 这是必需的,因为我的库使用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头文件?
这是current CMakeList.txt I use.
/ 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 {
^~~~~~~~~~~
这些重复的定义错误更多。看起来它们具有相同的性质。
复制步骤:
克隆此repository(分支:iota_new_implementation)
cd进入文件夹examples / iota_transaction_node
执行make
带有Makefile的版本。提交:7e1d8884ab135ae64cee02c8c1a447015f4325bc
带有CMake的版本。提交:dbf32e727889afa3efb466cfdc8561e697af48b0
USEPKG += iota-wallet
该示例的Makefile中的指向this package。 This Makefile用于创建静态库。
Cmake日志:
Makefile:
答案 0 :(得分:0)
使用POSIX标头嵌入的问题不是CMake。 这是对该错误的误解。
我认为混乱来自Scanning dependencies of target iota_wallet
行,然后是[ 11%] Building C object CMakeFiles/iota_wallet.dir/src/iota/addresses.c.obj
行。这是两个不同的步骤,都不涉及CMake。 CMake没有扫描任何东西。当CMake生成Makefile时,它只是将CMakeLists.txt添加为构建依赖项的一部分。这样一来,更新CMakeLists.txt即可在运行make时重新生成新的Makefile。执行此操作时,它会打印Scanning dependencies...
。
实际问题出在用arm-none-eabi
编译源代码。
该编译器附带newlib
作为其c库。无论出于何种原因,newlib
都包含一些pthread头文件。只要您在源代码中包含诸如stdint.h
或stdlib.h
之类的头文件,它就会包含sys/types.h
,然后再包含sys/_pthreadtypes.h
。这与RIOT附带的pthreads
头文件冲突。
您可以通过使用-std=c99
进行编译来解决此问题。
或者您可以通过编辑文件/usr/arm-none-eabi/include/sys/_pthreadtypes.h
解决此问题。
更改:
#if defined(_POSIX_THREADS) || __POSIX_VISIBLE >= 199506
收件人:
#if defined(_POSIX_THREADS)
仅供参考,Makefile和CMake示例仍然存在问题,但与特定问题无关。
有关newlib
问题的更多详细信息,请参见https://github.com/RIOT-OS/RIOT/issues/10443。
答案 1 :(得分:-1)
好吧,首先,请确保已将工具链gcc添加到路径中(参见wiki)
然后,在此github repo和this associated page的基础上,您可以查看一些实际在RIOT中使用CMake的人的例子(这不是我的情况,也不是RIOT开发人员的情况) ),他制作了自定义文件来查找RIOT和目标板,因此我认为这对您有帮助。
一旦RIOT检测正常工作,如果pthread问题仍然存在,那么在按照Fred的建议手动编辑系统文件之前,我会考虑尝试将CMake的pthread检测强制带给RIOT:
find_package (Threads REQUIRED PATHS ${RIOT_ROOT}/sys/posix/pthread/include NO_DEFAULT_PATH)
编辑重新考虑该问题,也许我应该澄清一些事情:
我认为最重要的想法是您根据the one from the polymcu repo重新格式化CMakeLists.txt以正确设置交叉编译(尤其是设置CMAKE_SYSTEM_NAME
)。
一旦CMake知道它是交叉编译的,就不应该使用POSIX,它应该导致系统__POSIX_VISIBLE >= 199506
部分的include评估为false,从而消除了任何手动编辑的需要。
这也是为什么我提出的find_package
命令是万不得已的情况,以防万一,应该立即使用 。
优先考虑的是正确配置您的CMake,这将使问题自行解决。