Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i wrote a small cpp program to call API using with GET method. Facing the below linking issue please suggest how to resolve the issue.

/tmp/ccu3AelN.o: In function `cpr::Response cpr::Get<std::string>(std::string&&)':
rest_api_call.cpp:(.text._ZN3cpr3GetIISsEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsEEENS_8ResponseEDpOT_]+0x19): undefined reference to `cpr::Session::Session()'
rest_api_call.cpp:(.text._ZN3cpr3GetIISsEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsEEENS_8ResponseEDpOT_]+0x4a): undefined reference to `cpr::Session::Get()'
rest_api_call.cpp:(.text._ZN3cpr3GetIISsEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsEEENS_8ResponseEDpOT_]+0x57): undefined reference to `cpr::Session::~Session()'
rest_api_call.cpp:(.text._ZN3cpr3GetIISsEEENS_8ResponseEDpOT_[_ZN3cpr3GetIISsEEENS_8ResponseEDpOT_]+0x68): undefined reference to `cpr::Session::~Session()'
/tmp/ccu3AelN.o: In function `void cpr::priv::set_option<std::string>(cpr::Session&, std::string&&)':
rest_api_call.cpp:(.text._ZN3cpr4priv10set_optionISsEEvRNS_7SessionEOT_[_ZN3cpr4priv10set_optionISsEEvRNS_7SessionEOT_]+0x2a): undefined reference to `cpr::Session::SetOption(std::string const&)'
collect2: error: ld returned 1 exit status


What I have tried:

Below is my source code,

#include "cpr.h"
#include<bits stdc++.h="">
using namespace std;
int main()
{
cout << "Action: Retrieve all products" << endl;
auto r = cpr::Get(cpr::Url{ "https://jsonplaceholder.typicode.com/todos/1" });
//curl -XGET https://jsonplaceholder.typicode.com/todos/1
std::cout << "Returned Text:" << r.text << std::endl;
}
Posted
Updated 7-Feb-20 4:53am
v2

You are missing the module that contains the definition of cpr::Session. If it is in a library then you need to add the library name to your build. Check the cpr documentation to see where it is.
 
Share this answer
 
Comments
Member 14737711 8-Feb-20 0:27am    
I have gone through the document but i found only source code of "CPR". I didn't find the library files in provided source code path https://github.com/whoshuu/cpr
Richard MacCutchan 8-Feb-20 3:59am    
That is a third-party library so you need to talk to the people who wrote it.
jungletek 22-Mar-20 12:53pm    
There aren't any pre-compiled libraries, you need to build it yourself.
Member 14737711 10-Feb-20 2:30am    
Please suggest whom i have to contact
Richard MacCutchan 10-Feb-20 3:14am    
Read my previous message again.
 
Share this answer
 
Comments
Member 14737711 8-Feb-20 0:30am    
i downloaded the source code of CPR and included to my local directory. So, while compiling my cpp program uses cpr.h file.
CPallini 8-Feb-20 4:25am    
That is not enough. You must link your object files with the library.
Member 14737711 10-Feb-20 2:31am    
yes, where do i find the linking libraries i.e -L cpr/lib -l cpr
CPallini 10-Feb-20 3:10am    
You should find the folder of the library on your system. For instance, if the cpr.h file is in the /home/user/cpr/include folder then the library possibly is in the /home/user/cpr/lib and you should link with the
-L /home/user/cpr/lib -l cpr

switches
Member 14737711 11-Feb-20 0:01am    
cpr folder doesn't exist in my Unix file system. Plz suggest where can i find those libraires in website.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900