Issue
I am trying to make a MakeFile for linking Curl, but I cannot find a good source to learn and implement my MakeFile, following is what I have written for my MakeFile:
CC=g++
CFLAGS=-g -Wall
BIN=~/Documents/Github/Covid-Visualizer/testing
all: $(BIN)
%: %.cpp
$(CC) $(CFLAGS) $< -o $@ -lcurl
and following is the code for my testing project:
#include <iostream>
#include <curl/curl.h>
using namespace std;
int main()
{
CURL *curl=curl_easy_init();
if(!curl)
{
fprintf(stderr,"init failed\n");
return EXIT_FAILURE;
}
// set options
curl_easy_setopt(curl, CURLOPT_URL, "https://jacobsorber.com");
// perform actions
CURLcode result=curl_easy_perform(curl);
if(result!=CURLE_OK)
{
fprintf(stderr, "download problem \n");
}
curl_easy_cleanup(curl);
return EXIT_SUCCESS;
}
I am expecting the following from this MakeFile:
g++ -g -Wall test.cpp -o test.out -lcurl
But I assume due to wrong implementation I am getting the following error when I use make test
:
g++ test.cpp -o test
/usr/bin/ld: /tmp/cc5miClt.o: in function `main':
test.cpp:(.text+0xd): undefined reference to `curl_easy_init'
/usr/bin/ld: test.cpp:(.text+0x5c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: test.cpp:(.text+0x68): undefined reference to `curl_easy_perform'
/usr/bin/ld: test.cpp:(.text+0x9d): undefined reference to `curl_easy_cleanup'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: test] Error 1
Following is the output for make -r test
:
make: *** No rule to make target 'test'. Stop.
Additional Information-
Platform: Linux
Any help will be appreciated!
Solution
OK, well, that's your problem. As I said, make will only look for makefiles named Makefile
(or makefile
or, if you're using GNU make, GNUmakefile
) by default. You have named your makefile MakeFile
. So make is not reading that file. So none of your rules or recipes are available.
You should either rename your makefile to be Makefile
(or one of the other options above), or else you have to tell make what the name of your makefile is with the -f
option:
make -f MakeFile test
Answered By - MadScientist