c++ - rtai no such file or directory 错误编译

标签 c++ c linux compilation rtai

我试图从 Debian 6 编译一个 .cpp 程序。我有一个工作的 makefile,它只适用于 .c 文件,但我需要在 .cpp 上编译我的程序。所以这里是 makefile:

#
# Build the examples.
#

# The great thing about GNU Make is that it knows so much about your     lifestyle, you don't need to
# tell it the obvious things. This file is a minimal makefile.

# You run this makefile by typing `make' in the directory with the   makefile

# You can find out more about make by typing `info make'.

# This tells Make that we need to link everything with the robot code:
LDLIBS=/usr/lib/robot.a

CC=gcc

# This variable has a handy copy of all the things we aim to produce
EXEC= read_sensor turn_on_and_off control_joint cerrar_mano

# Thses are all the things we need to compile:
all: ${EXEC}  

CFLAGS=-I/usr/realtime/include/ -D_ISOC99_SOURCE -D_GNU_SOURCE - rtai_types -rtai_lxrt

# Make now looks around the directory, finds the read_sensor.c and
# turn_on_and_off.c files, works out it can compile them into the
# read_sensor and turn_on_and_off executables, and does so!

# However, for the kernel modules, we need to do a bit more.
rt_control: rt_control.o
ld -E -O2 -r -o $@ $^ 

# This is an example of making a binary from several object files, as an   example only!
fred: bert.o jim.o
ld -E -O2 -o $@ $^ 

# We need to tell the compiler quite a lot about where to find the right  header files
rt_control.o: control.c
$(CC) -c -O2  -DREALTIME -DRTAI_3  -I./include/ -I. -I../  -isystem     /usr/realtime/include/  -isystem /usr/src/linux/include   -o $@ $^


# We put some housekeeping in here:

# This target is used to remove intermediate files Make produces.
clean:; rm -f *.o
# This target is used to remove output files Make produces as well.
realclean: clean
rm -f ${EXEC}

所以当我在终端上写 make myprogramname.cpp 这就是我得到的:

In file included from /usr/include/robot/robot.h:38,
             from Programa_Hand2.cpp:4:
/usr/include/robot/sensor.h:24:44: error: rtai_types.h: No such file or  directory
/usr/include/robot/sensor.h:38:23: error: rtai_lxrt.h: No such file or directory
In file included from /usr/include/robot/robot.h:38,
             from Programa_Hand2.cpp:4:
/usr/include/robot/sensor.h:168: error: 'RTIME' does not name a type
In file included from /usr/include/robot/robot.h:38,
             from Programa_Hand2.cpp:4:
/usr/include/robot/sensor.h:178: error: 'RTIME' does not name a type
In file included from Programa_Hand2.cpp:4:
/usr/include/robot/robot.h:194: error: 'RTIME' does not name a type
/usr/include/robot/robot.h:244: error: 'RTIME' does not name a type
Programa_Hand2.cpp: In function 'int main()':
Programa_Hand2.cpp:18: error: expected initializer before 'printf'
Programa_Hand2.cpp:19: error: 'f' was not declared in this scope
hand@hand-cartagena:~/Desktop/Joaquin/examples$ make Programa_Hand2
g++     Programa_Hand2.cpp  /usr/lib/robot.a -o Programa_Hand2
In file included from /usr/include/robot/robot.h:38,
             from Programa_Hand2.cpp:4:
/usr/include/robot/sensor.h:24:44: error: rtai_types.h: No such file or  directory
/usr/include/robot/sensor.h:38:23: error: rtai_lxrt.h: No such file or directory
In file included from /usr/include/robot/robot.h:38,
             from Programa_Hand2.cpp:4:
/usr/include/robot/sensor.h:168: error: 'RTIME' does not name a type
In file included from /usr/include/robot/robot.h:38,
             from Programa_Hand2.cpp:4:
/usr/include/robot/sensor.h:178: error: 'RTIME' does not name a type
In file included from Programa_Hand2.cpp:4:
/usr/include/robot/robot.h:194: error: 'RTIME' does not name a type
/usr/include/robot/robot.h:244: error: 'RTIME' does not name a type
Programa_Hand2.cpp: In function 'int main()':
Programa_Hand2.cpp:18: error: expected initializer before 'printf'
Programa_Hand2.cpp:19: error: 'f' was not declared in this scope
make: *** [Programa_Hand2] Error 1

也尝试使用 gcc -o Programa_Hand2 Programa_Hand2.cpp 并得到相同的错误,我认为它是我必须用 makefile 更改的东西但不知道那里有什么问题 有任何想法吗?我是编程和 linux 的新手,所以我有点生气,因为我需要在 c++ 上编译程序,我编译它并在 c 上正常工作。感谢您的帮助!

编辑:从互联网上做了一些研究,似乎是 RTAI 不支持 C++;那么有什么办法可以用 C++ 编译它吗?另外,我的#includes 是:

#include <stdio.h>
#include <robot/robot.h>
#include <unistd.h>
#include <error.h>
#include <iostream>

#include "RobotConfig.h"

再次感谢!

最佳答案

简而言之,对于 C++ 文件,您需要使用命令 g++ 而不是 gcc。

您需要使用 C++ 编译器而不是 C 编译器来编译 C++ 文件,并且存在差异。

GNU C++ 编译器的命令是 g++ 假设你已经安装了它。这很可能是因为您似乎有一个 C 编译器。

在您的 Makefile 中添加一个名为 CXX 的变量,并将其设置为等于 g++。然后使用 CXX 变量而不是 CC 变量作为命令编译 C++ 代码。

$(CXX) -o <.output file name> <.cpp files go here>

关于c++ - rtai no such file or directory 错误编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38461831/

相关文章:

linux - 在 .bashrc 中包含其他文件

linux - 包含括号的 awk 协进程的转义序列

c++ - 将多个参数传递到 std::thread

c - 双向链表快速排序 C

c++ - 如何在从原始图像中提取的子图像中执行模板匹配过程并在原始图像中显示结果

c# - 将表单的父级设置为 "FindWindow"

linux - 替换字符串中的空格并转换为小写

c++ - 简单的自动换行功能最后一行问题

c++ - 为什么 libxml2 在元素名称上输出 "text"(当它不是 "text"时)?

c++ - 如何在 C++ 中计算 3 位小数精度的圆周率?