简体   繁体   English

致命错误:json-c/json.h:没有这样的文件或目录交叉编译 ubuntu x64 for raspberry pi arm

[英]fatal error: json-c/json.h: No such file or directory Cross compiling on ubuntu x64 for raspberry pi arm

I am trying to compile my code on my Ubuntu x64 laptop for the Raspberry Pi.我正在尝试在我的 Ubuntu x64 笔记本电脑上为 Raspberry Pi 编译我的代码。

I am able to compile and run the code on Ubuntu laptop without any issue.我能够在 Ubuntu 笔记本电脑上编译和运行代码,没有任何问题。 However when I try to compile it for Raspberry Pi I get the following error:但是,当我尝试为 Raspberry Pi 编译它时,出现以下错误:

$make
/home/nmohan/Development/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-gcc -g -Wall -Wextra -I /home/nmohan/github/NiRobot/inc -fPIC -shared -L/home/nmohan/github/NiRobot/Obj_arm -Wl,-rpath=/home/nmohan/github/NiRobot/Obj -o  /home/nmohan/github/NiRobot/Obj_arm/libRSXA.so /home/nmohan/github/NiRobot/lib/RSXA.c -lNMT_stdlib -lNMT_log -ljson-c -lc  -Ljson-c
/home/nmohan/github/NiRobot/lib/RSXA.c:11:25: fatal error: json-c/json.h: No such file or directory
compilation terminated.
Makefile:101: recipe for target '/home/nmohan/github/NiRobot/Obj_arm/libRSXA.so' failed
make: *** [/home/nmohan/github/NiRobot/Obj_arm/libRSXA.so] Error 1
#---------------------------------------#
#                                       #
#            Global Varibles            #
#                                       #
#---------------------------------------#
PROJ_DIR    = /home/nmohan/github/NiRobot
BIN_DIR     = $(PROJ_DIR)/bin
OBJ_DIR     = $(PROJ_DIR)/Obj
OBJ_DIR_ARM = $(PROJ_DIR)/Obj_arm
INC_DIR     = $(PROJ_DIR)/inc
LIB_DIR     = $(PROJ_DIR)/lib
OUT_DIR     = $(PROJ_DIR)/bld
OUT_DIR_ARM = $(PROJ_DIR)/bld_arm
CFLAGS      = -g -Wall -Wextra -I $(INC_DIR)
SFLAGS      = -fPIC -shared
RPATH       = -L$(OBJ_DIR) -Wl,-rpath=$(OBJ_DIR)
RPATH_ARM   = -L$(OBJ_DIR_ARM) -Wl,-rpath=$(OBJ_DIR)
GCC_DIR     = /home/nmohan/Development/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-gcc

#---------------------------------------#
#                                       #
#              Targets                  #
#                                       #
#---------------------------------------#
OBJS        = NMT_stdlib.so \
              NMT_log.so \
              RSXA.so \
              PCA9685.so \
              MTDR.so \
              CAM_MOTOR_CTRL.so \
              HCxSR04.so

#---------------------------------------#
#                                       #
#            Dependancies               #
#                                       #
#---------------------------------------#
NMT_STDLIB_LIBS     = -lc

NMT_LOG_LIBS        = -lc \
                      -lNMT_stdlib \

RSXA_LIBS           = -lNMT_stdlib \
                      -lNMT_log \
                      -ljson-c \
                      -lc 

PCA9685_LIBS        = -lNMT_stdlib \
                      -lNMT_log \
                      -lc \
                      -lwiringPi \
                      -lcrypt \
                      -lm \
                      -lrt \
                      -lRSXA

MTDR_LIBS           = -lNMT_stdlib \
                      -lNMT_log \
                      -lwiringPi \
                      -lPCA9685 \
                      -lcrypt \
                      -lm \
                      -lrt \
                      -lRSXA

CAM_MOTOR_CTRL_LIBS = -lNMT_stdlib \
                      -lNMT_log \
                      -lwiringPi \
                      -lMTDR \
                      -lPCA9685 \
                      -lcrypt \
                      -lm \
                      -lrt \
                      -lRSXA


HCxSR04_LIBS        = -lNMT_log \
                      -lNMT_stdlib \
                      -lRSXA \
                      -lwiringPi \
                      -lcrypt \
                      -lm \
                      -lrt

TARGET_OBJS := $(foreach OBJ,$(OBJS),$(OBJ_DIR)/lib$(OBJ))
TARGET_OBJS_ARM := $(foreach OBJ,$(OBJS),$(OBJ_DIR_ARM)/lib$(OBJ))

all: $(TARGET_OBJS) \
     $(TARGET_OBJS_ARM)
.PHONY: all

$(OBJ_DIR)/lib%.so: $(LIB_DIR)/%.c $(INC_DIR)/%.h
    gcc $(CFLAGS) $(SFLAGS) $(RPATH) -o  $@ $< $($(*)_LIBS)

$(OBJ_DIR_ARM)/lib%.so: $(LIB_DIR)/%.c $(INC_DIR)/%.h
    $(GCC_DIR) $(CFLAGS) $(SFLAGS) $(RPATH_ARM) -o  $@ $< $($(*)_LIBS)

$(OBJ_DIR)/lib%.so: $(LIB_DIR)/%.cpp $(INC_DIR)/%.hpp
    g++ $(CFLAGS) $(SFLAGS) $(RPATH) -o  $@ $< $($(*)_LIBS)

It depends on json-c/json.h.这取决于 json-c/json.h。 You need to include these files that were not found.您需要包含这些未找到的文件。

Installing libjson-c-dev package.安装 libjson-c-dev package。

sudo apt install libjson-c-dev

I've had a similar problem.我遇到过类似的问题。 It's because of the json.h which is not part of the, in my case, gcc-arm-10-3-2017.07...-aarch64-none-linux-gnu.这是因为 json.h 不是 gcc-arm-10-3-2017.07...-aarch64-none-linux-gnu 的一部分。 I simply cloned json-c git and compiled it with the cross-compiler, too.我只是克隆了 json-c git 并用交叉编译器编译了它。 Then you can reference to the output, or you can inlcude the whole git into your project and compile it all in one.然后你可以引用output,或者你可以将整个git包含到你的项目中并编译它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM