首页 > 解决方案 > 即使安装了 4 个软件包,我也无法在 Raspbian Buster 上使用 curl/curl.h

问题描述

我正在尝试使用以下示例获取 URL 的内容:https ://curl.haxx.se/libcurl/c/url2file.html

我已经安装了以下内容:

sudo apt-get install libcurl4
sudo apt-get install libcurlpp-dev
sudo apt-get install libcupt4-2-downloadmethod-curl
sudo apt-get install libcurl4-openssl-dev

我已将该代码添加到 C++ 程序中。该程序有一个不包含任何与libcurl. makefile 使我能够使用hzeller 的 rpi-rgb 库

CXXFLAGS=-Wall -O3 -g -Wextra -Wno-unused-parameter
OBJECTS=Big_ppd_display_try1.o
BINARIES=Big_ppd_display_try1

OPTIONAL_OBJECTS=text_example.o coz_try1.o
OPTIONAL_BINARIES=text_example coz_try1


# Where our library resides. You mostly only need to change the
# RGB_LIB_DISTRIBUTION, this is where the library is checked out.
RGB_LIB_DISTRIBUTION=rpi-rgb-led-matrix
RGB_INCDIR=$(RGB_LIB_DISTRIBUTION)/include
RGB_LIBDIR=$(RGB_LIB_DISTRIBUTION)/lib
RGB_LIBRARY_NAME=rgbmatrix
RGB_LIBRARY=$(RGB_LIBDIR)/lib$(RGB_LIBRARY_NAME).a
LDFLAGS+=-L$(RGB_LIBDIR) -l$(RGB_LIBRARY_NAME) -lrt -lm -lpthread

all : $(BINARIES)

$(RGB_LIBRARY): FORCE
    $(MAKE) -C $(RGB_LIBDIR)

Big_ppd_display_try1: Big_ppd_display_try1.o  $(RGB_LIBRARY)
    $(CXX) $(CXXFLAGS) Big_ppd_display_try1.o -o $@ $(LDFLAGS) $(MAGICK_LDFLAGS)

%.o : %.cc
    $(CXX) -I$(RGB_INCDIR) $(CXXFLAGS) -c -o $@ $<

Big_ppd_display_try1.o : Big_ppd_display_try1.cc
    $(CXX) -I$(RGB_INCDIR) $(CXXFLAGS) $(MAGICK_CXXFLAGS) -c -o $@ $<

clean:
    rm -f $(OBJECTS) $(BINARIES) $(OPTIONAL_OBJECTS) $(OPTIONAL_BINARIES)

FORCE:
.PHONY: FORCE

undefined reference对所有libcurl功能都有:

pi@raspberrypi:/var/www/html/4panel $ sudo make all
make -C rpi-rgb-led-matrix/lib
make[1]: Entering directory '/var/www/html/4panel/rpi-rgb-led-matrix/lib'
make[1]: Leaving directory '/var/www/html/4panel/rpi-rgb-led-matrix/lib'
g++ -Wall -O3 -g -Wextra -Wno-unused-parameter Big_ppd_display_try1.o -o Big_ppd_display_try1 -Lrpi-rgb-led-matrix/lib -lrgbmatrix -lrt -lm -lpthread 
/usr/bin/ld: Big_ppd_display_try1.o: in function `main':
/var/www/html/4panel/Big_ppd_display_try1.cc:240: undefined reference to `curl_global_init'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:243: undefined reference to `curl_easy_init'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:246: undefined reference to `curl_easy_setopt'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:249: undefined reference to `curl_easy_setopt'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:252: undefined reference to `curl_easy_setopt'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:255: undefined reference to `curl_easy_setopt'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:262: undefined reference to `curl_easy_setopt'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:265: undefined reference to `curl_easy_perform'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:272: undefined reference to `curl_easy_cleanup'
/usr/bin/ld: /var/www/html/4panel/Big_ppd_display_try1.cc:274: undefined reference to `curl_global_cleanup'
collect2: error: ld returned 1 exit status
make: *** [Makefile:24: Big_ppd_display_try1] Error 1

我在 Linux PC 上使用 Visual Studio Code 来检查代码是否存在错误并进行调试,但那里没有错误或警告。

该代码与 libcurl 示例中的代码相同,只是它全部处于一个大while(true)循环中,因为我需要它作为 Raspberry Pi 4 上的一个进程无限期地运行。

你怎么看 ?

标签: c++curl

解决方案


推荐阅读