【问题标题】:Undefined reference to libusb functions对 libusb 函数的未定义引用
【发布时间】:2016-12-07 20:39:21
【问题描述】:

我从依赖 libusb 的供应商那里获得了一些示例代码。当我尝试使用 make 编译时,我得到了这个:

mkdir -p .obj
gcc -I./ -I../libsoccptp/include -std=gnu++11 -pthread -g -o .obj/authentication.o -c authentication.cpp -lusb-1.0 -lusb
gcc -std=gnu++11 -pthread -g -o ../out/bin/authentication .obj/authentication.o -L../out/lib -lsoccptp -L/usr/lib -lusb-1.0 -lstdc++ -lusb-1.0 -lusb
../out/lib/libsoccptp.so: undefined reference to `libusb_has_capability'
../out/lib/libsoccptp.so: undefined reference to `libusb_hotplug_register_callback'
../out/lib/libsoccptp.so: undefined reference to `libusb_handle_events_timeout_completed'
../out/lib/libsoccptp.so: undefined reference to `libusb_hotplug_deregister_callback'
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target '../out/bin/authentication' failed
make: *** [../out/bin/authentication] Error 1

我发现很多其他人的帖子有类似的问题让 libusb 正确链接。但似乎其他人的解决方案只是确保将-lusb-1.0-lusb 作为参数添加到编译器。显然,我的供应商已经设置了 Makefile 来做到这一点。我还验证了我在 Ubuntu 上安装了最新版本的 libusb-1.0,据说这与我的供应商使用的环境相同。

为什么链接不正确?

作为参考,这里是 Makefile:

ROOT_DIR ?= ..
OUT ?= ../out
OUT_DIR := $(OUT)/bin
CC := gcc

LIBS := -L${OUT}/lib -lsoccptp -L/usr/lib -lusb-1.0 -lstdc++

override INCLUDES += -I./ -I${ROOT_DIR}/libsoccptp/include

.PHONY: clean

OBJ_DIR := .obj
SOURCES := authentication.cpp shoot_an_image_and_get_it.cpp check_LiveView_status_and_get_images.cpp parser_handling.cpp list_objects.cpp change_camera_setting.cpp
OBJECTS := $(addprefix $(OBJ_DIR)/, $(notdir $(SOURCES:.cpp=.o)))
TARGETS := $(addprefix ${OUT_DIR}/, $(notdir $(basename ${SOURCES})))

all: ${OUT_DIR} $(OBJ_DIR) ${TARGETS}

objs: $(OBJ_DIR) $(OBJECTS)

$(OBJ_DIR)/%.o : %.cpp
    $(CC) $(INCLUDES) -std=gnu++11 -pthread -g -o $@ -c $< -lusb-1.0 -lusb

$(OUT_DIR)/%: $(OBJ_DIR)/%.o
    ${CC} -std=gnu++11 -pthread -g -o $@ $< ${LIBS} -lusb-1.0 -lusb

${OUT_DIR}:
    mkdir -p ${OUT_DIR}

$(OBJ_DIR):
    mkdir -p $(OBJ_DIR)

clean:
    rm -rf ${TARGETS} $(OBJ_DIR)

【问题讨论】:

    标签: linker libusb libusb-1.0


    【解决方案1】:

    在与提供该软件的供应商的工程师讨论后,确定我使用的是更新版本的 Ubuntu (v16),然后他们开发了该软件。当我在旧版本(v14)上编译时,它编译得很好。

    工程师无法解释 Ubuntu 16 中哪些更改破坏了他们的代码,但这暂时解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2011-10-26
      • 1970-01-01
      • 2019-09-05
      • 2011-09-19
      • 2017-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      相关资源
      最近更新 更多