Unable to link against BFD [duplicate]

假装没事ソ 提交于 2019-12-24 07:26:32

问题


I am trying to include this file in my project: http://cairo.sourcearchive.com/documentation/1.9.4/backtrace-symbols_8c-source.html

But it requires linking against BFD. I have both binutils and binutils-devel installed. I have tried linking with -lbfd as well as directly to /usr/lib64/libbfd.so and /usr/lib64/libbfd.a (which both do exist). I also tried searching pkg-config to see if there was a different flag I should be using, but there is no reference to BFD or binutils in pkg-config.

No matter what I've tried I get the following errors:

undefined reference to 'bfd_init'
undefined reference to 'bfd_openr'
undefined reference to 'bfd_check_format'
undefined reference to 'bfd_checkformat_matches'
undefined reference to 'bfd_close'
undefined reference to 'bfd_map_over_sections'

First I am compiling my logger and the backtrace-symbols.c file I linked to above (as the logger is where I intend to use this for printing traces). Then I am linking those two object files together into a combined object file:

CC = clang
CFLAGS = -g -Wall -c
SOURCE = simplog.c
OBJ = simplog.o, simplog-temp.o, backtrace-symbols.o

all:
    $(CC) $(CFLAGS) $(SOURCE); mv simplog.o simplog-temp.o; \
    $(CC) -ansi $(CFLAGS) backtrace-symbols.c; \
    ld -r simplog-temp.o backtrace-symbols.o -o simplog.o

clean:
    rm -f $(OBJ) 

Then I am linking this object file into my main project:

CC= clang++
PROG= ./bin/chiplus8
OBJS= ./src/main.o ./src/Chip8.o ./src/EmuCPU.o ./src/SimpleLogger/simplog.o
LIBS= 
CXXFLAGS= -g -Wall -std=c++11 $(shell pkg-config --cflags ${LIBS})
LDFLAGS= $(shell pkg-config --static --libs ${LIBS})

all: logger $(PROG)

$(PROG): $(OBJS)
    mkdir -p ./bin/
    $(CC) -g -rdynamic -o $(PROG) $(LDFLAGS) -lbfd -liberty $(OBJS)
    rm -f $(OBJS)

logger:
    cd ./src/SimpleLogger; make clean all

clean:
    rm -f $(PROG) $(OBJS)

I'm really not sure what I need to do to get this to link properly anymore. Is there something I'm missing?


回答1:


Change:

$(PROG): $(OBJS)
    mkdir -p ./bin/
    $(CC) -g -rdynamic -o $(PROG) $(LDFLAGS) -lbfd -liberty $(OBJS)
    rm -f $(OBJS)

To this:

$(PROG): $(OBJS)
    mkdir -p ./bin/
    $(CC) -g -rdynamic -o $(PROG) $(LDFLAGS) $(OBJS) -lbfd -liberty
    rm -f $(OBJS)

Object files have to be placed before libraries with the compilation command. See this question.



来源:https://stackoverflow.com/questions/20915623/unable-to-link-against-bfd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!