How do I link lcurl (libcurl4-openssl-dev on linux) to a .c file where the headers are in a different folder?
I have a waveshare e-ink display that I'm trying to write a C program for on a raspberry pi 0 that will display the weather. So far, the only issue I'm running into is getting the weather data itself from openweathermaps.
I'm not use to programming in C, so instead of creating a program from scratch, I got the e-ink examples from waveshare's github, and then copied one of the example files in the example directory and renamed it to EPD_weather.c and modified it. I then had to modify some other files (it was awhile ago, but I think it was the makefile and a header file). It works just fine to display some words on the e-ink display.
I've did some research, and people suggested using libcurl to get the data from the api. I installed libcurl4-openssl-dev, and then tried to add a line to my program that called the "curl_easy_init", I got an error that it was undefined. I then learned I had to link lcurl to my program.
My problem is when I try to follow the following line to link lcurl to my program, I get an error
gcc EPD_weather.c -lcurl
and the error is:
EPD_Test.h:33:10: fatal error: DEV_Config.h: No such file or directory
#include "DEV_Config.h"
^~~~~~~~~~~~~~
compilation terminated.
If it doesn't show up correctly, the carrot should be pointing first double quote.
If I go into EPD_weather.c, it includes the following headers:
#include "EPD_Test.h"
#include "EPD_7in5_V2.h"
#include <time.h>
#include <curl/curl.h>
My program is located in the c/examples folder, and EPD_7in5_V2.h is located in the c/lib/e-Paper folder. There is the EPD_Test.h file in the c/examples folder though, and that header file includes the following headers:
#ifndef _EPD_TEST_H_
#define _EPD_TEST_H_
#include "DEV_Config.h"
#include "GUI_Paint.h"
#include "GUI_BMPfile.h"
#include "ImageData.h"
#include "Debug.h"
#include <stdlib.h> // malloc() free()
If I try commenting out the first #include line, and running
gcc EPD_weather.c -lcurl
again, it then gives me the same error but for "GUI_Paint.h" instead. Those headers are also located somewhere in the c/lib directory or a subdirectory. (See the link above to their github to see the file structure.)
If I comment all of the header files out that are in EPD_Test.h, when I try compile, I get a bunch of errors, and the gcc EPD_weather.c -lcurl command still doesn't work.
Does anybody know how to link lcurl to a c file when the header file contains header files that are in other folders? I'm not use to having to deal with make files or c in general, so this is new to me. I've tried googling, but it seems like nobody else is having this problem. I don't know exactly what to search for.
EDIT: In case the mods restore this, I figured it out. Since I was using a make file, I guess I didn't need to worry about using gcc commands to link it. I had to modify the make file. This post let me to figuring out what I needed to do. https://stackoverflow.com/questions/6601041/linking-curl-in-makefile
Posted Dec 12, 2020, 9:40 PM UTC · edited