文件格式无法识别;作为链接描述文件处理 - 为arm处理器编译c代码

时间:2015-03-16 08:42:55

标签: c linux arm

我正在努力编写一个arm设备的演示程序。

文档不存在,我更习惯于Windows环境。

我已经安装并试用了Ubuntu 14和13.10,但两者都存在同样的问题。两者都是32位。

makefile是这样的:

#
# program makefile for the POS Application
#

# build on arm-linux platform
ARCH    = /opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-

# programs we use...
CP  = cp -f
MKDIR   = mkdir -p
RM  = rm -f
RMDIR   = rm -rf
TAR = tar -zcf
STRIP   = $(ARCH)strip
RANLIB  = $(ARCH)ranlib

# compiler names:
CC      = $(ARCH)gcc
CXX     = $(ARCH)g++

# flags for C/C++ compiler:
INCFLAG     = -I../include -I../sdk/include
OPTIM       = -Wall -O2 -Wunused
CFLAGS      = $(OPTIM)
CXXFLAGS    = $(OPTIM) -Wno-non-virtual-dtor

# libraries to link with:
LD_LIBS     = -ldl -lrt
LD_SDK      = -L../sdk -lkfsdk

LDFLAGS     = $(LD_LIBS) $(LD_SDK)

# Which targets should be built?
TARGET  = demo_app
#RELEASEDIR = ../release

# Be quiet when building...
#.SILENT:

#
# Files for this directory...
#
SRCDIR  = ../src

PATH1       = $(SRCDIR)/gui/
PATH2       = $(SRCDIR)/platform/

COBJECT     = \
        $(addprefix $(PATH1), $(addsuffix .o, $(basename $(notdir $(wildcard $(PATH1)*.c))))) \
        $(addprefix $(PATH2), $(addsuffix .o, $(basename $(notdir $(wildcard $(PATH2)*.c))))) \

CPPOBJECT   = \
        $(addprefix $(PATH1), $(addsuffix .o, $(basename $(notdir $(wildcard $(PATH1)*.cxx))))) \
        $(addprefix $(PATH2), $(addsuffix .o, $(basename $(notdir $(wildcard $(PATH2)*.cxx))))) \

#CFILES     = $(wildcard *.c)
#COBJECT    = $(patsubst %.c, %.o, $(CFILES))
#CPPFILES   = $(wildcard *.cxx)
#CPPOBJECT  = $(patsubst %.cxx, %.o, $(CPPFILES))

#
# Make everything...
#
all:    $(TARGET)
#   $(CP) $(TARGET) $(RELEASEDIR)
    @echo "All files have been made"
    @echo "            ************************************"
    @echo "            *                                  *"
    @echo "            *       POS APPLICATION      *"
    @echo "            *                                  *"
    @echo "            ************************************"
    @echo "succeed"

$(TARGET):  $(COBJECT) $(CPPOBJECT)
    @echo Linking $(TARGET)...
    $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
#   $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)

%.o:%.c
    @echo Compiling $<...
    $(CC) $(CFLAGS) $(INCFLAG) -o $@ -c $<

%.o:%.cxx
    @echo Compiling $<...
    $(CXX) $(CXXFLAGS) $(INCFLAG) -o $@ -c $<

#
# Clean old files...
#
clean:
    $(RM) *.o
    $(RM) $(PATH1)*.o
    $(RM) $(PATH2)*.o
    $(RM) $(TARGET)

#
# End of "$Id: Makefile 2011-01-24 08:21 $".
#
# DO NOT DELETE

我已经运行make clean,然后制作并获得以下消息:

Compiling ../src/platform/main.c...
/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-gcc -Wall -O2 -Wunused -I../include -I../sdk/include -o ../src/platform/main.o -c ../src/platform/main.c
Linking demo_app...
/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-gcc -o demo_app ../src/platform/main.o -Wall -O2 -Wunused -ldl -lrt -L../sdk -lkfsdk
/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/../lib/gcc/arm-unknown-linux-gnu/4.0.2/../../../../arm-unknown-linux-gnu/bin/ld:/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/../lib/gcc/arm-unknown-linux-gnu/4.0.2/../../../../arm-unknown-linux-gnu/lib/libdl.so: file format not recognized; treating as linker script
/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/ld:/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/bin/../lib/gcc/arm-unknown-linux-gnu/4.0.2/../../../../arm-unknown-linux-gnu/lib/libdl.so:1: parse error
collect2: ld return 1 exit status.

从我所做的谷歌搜索,将文件链接在一起似乎是一个问题,但我不知道为什么和出了什么问题。

我尝试过apt-get install gcc-arm-linux-gnueabi

/opt/gcc-4.0.2-glibc-2.3.5目录和子目录附带为设备提供的所谓SDK。

关于如何使其发挥作用的任何想法?

谢谢

尼尔

编辑1:

如果我在libdl.so上执行了更多操作,则会显示libdl.s0.2。如果我更多该文件,它会给出libdl-2.3.5.so。最后,如果我做了readelf -h libdl-2.3.5.so该文件,我得到:

ELF 

    Header:
      Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 
      Class:                             ELF32
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            ARM
      ABI Version:                       0
      Type:                              DYN (Shared object file)
      Machine:                           ARM
      Version:                           0x1
      Entry point address:               0xc78
      Start of program headers:          52 (bytes into file)
      Start of section headers:          9864 (bytes into file)
      Flags:                             0x2, has entry point, GNU EABI
      Size of this header:               52 (bytes)
      Size of program headers:           32 (bytes)
      Number of program headers:         7
      Size of section headers:           40 (bytes)
      Number of section headers:         32
      Section header string table index: 29

我做file libdl-2.3.5.so我得到了:

/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/arm-unknown-linux-gnu/lib/libdl-2.3.5.so: ELF 32-bit LSB shared object, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped

由于篇幅很长,我在这里编辑了。

尼尔

2 个答案:

答案 0 :(得分:0)

这是一个示例make文件,
它包括依赖文件的创建和使用 包含头文件。 它使用'sed'生成依赖文件。 一般来说,它希望所有文件都在 本地目录,因此您需要对其进行修改 您的多个源文件目录等

SHELL = /bin/sh


BINDIR  :=  /home/user/bin


.PHONY: all
all : $(BINDIR)/$(name) 


#
# macro of all *.c files 
# (NOTE:
# (the following 'wildcard' will pick up ALL .c files
# (like FileHeader.c and FunctionHeader.c 
# (which should not be part of the build
# (so be sure no unwanted .c files in directory
# (or change the extension
#
SRC := $(wildcard *.c)
OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
INC := $(SRC:.c=.h)


MAKE    :=  /usr/bin/make

CC      :=  /usr/bin/gcc

CP      :=  cp

MV      := mv

LDFLAGS :=  -L/usr/local/lib

DEBUG   :=  -ggdb3

CCFLAGS :=  $(DEBUG) -Wall -W

# pre processor flags, not C++ flags
#CPPFLAGS += =MD


LIBS    :=   -lssl -ldl -lrt -lz -lc -lm



#
# link the .o files into the executable 
# using the linker flags
# -- explicit rule
#
$(name): $(OBJ) $(COMMON_OBJ) ../makefile.mak ../makefile.bot
    #
    # ======= $(name) Link Start =========
    $(CC) $(LDFLAGS) -o $@ $(OBJ) $(COMMON_OBJ) $(LIBS)
    # ======= $(name) Link Done ==========
    #



# note:
# using MV rather than CP results in all executables being re-made everytime
$(BINDIR)/$(name): $(name)
    #
    # ======= $(name) Copy Start =========
    sudo $(CP) $(name) $(BINDIR)/.
    # ======= $(name) Copy Done ==========
    #



#
#create dependancy files -- inference rule
# list makefile.mak as dependancy so changing makfile forces rebuild
#
%.d: %.c 
    # 
    # ========= START $< TO $@ =========
    $(CC) -M $(CPPFLAGS) $< > $@.$$$$;                      \
    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;     \
    rm -f $@.$$$$
    # ========= END $< TO $@ =========



# 
# compile the .c file into .o files using the compiler flags
# -- inference rule
#
%.o: %.c %.d 
    # 
    # ========= START $< TO $@ =========
    $(CC) $(CCFLAGS) -c $< -o $@ -I. 
    # ========= END $< TO $@ =========
    # 



.PHONY: clean
clean: 
    # ========== CLEANING UP ==========
    rm -f *.o
    rm -f $(name).map
    rm -f $(name)
    rm -f *.d
    # ========== DONE ==========




# include the contents of all the .d files
# note: the .d files contain:
# <filename>.o:<filename>.c plus all the dependancies for that .c file 
# I.E. the #include'd header files
# wrap with ifneg... so will not rebuild *.d files when goal is 'clean'
#
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEP)
endif

答案 1 :(得分:0)

首先道歉,需要很长时间才能恢复原状,感冒了并且躺在床上。

我终于弄清楚发生了什么,事实证明它很简单,就像往常一样。

arm设备的SDK附带了放在/ opt下的GCC。事实证明,由于某种未知的原因,我所拥有的副本已经解开了,但在/opt/gcc-4.0.2-glibc-2.3.5/arm-unknown-linux-gnu/arm下丢失了所有链接-unknown-linux-gnu / lib目录。

感谢undur_gongor,你的评论使我更接近这些文件,我设法找到原始的.tar.bz2文件,解压缩到正确的目录和所有链接,并且它编译正常。

尼尔