-1

I'm trying to compile demo main file (https post with the chunked-encoding data) from github repo using, I have installed libghc-iproute-dev and libnl3.

gcc -o main -Imbedtls/include -fPIC -DHAVE_CONFIG_H -D_U_="attribute((unused))" main.c -O2 mbedtls/library/libmbedx509.a mbedtls/library/libmbedtls.a mbedtls/library/libmbedcrypto.a

I can't compile porgram, here is what I got:

main.c: In function ‘main’:
main.c:133:8: warning: implicit declaration of function ‘http_open_chunked’; did you mean ‘http_read_chunked’? [-Wimplicit-function-declaration]
if(http_open_chunked(&hi2, url) == 0)
^~~~~~~~~~~~~~~~~
http_read_chunked
main.c:137:12: warning: implicit declaration of function ‘http_write_chunked’; did you mean ‘http_read_chunked’? [-Wimplicit-function-declaration]
if(http_write_chunked(&hi2, data, size) != size)
^~~~~~~~~~~~~~~~~~
http_read_chunked
/tmp/cc7m6wMn.o: In function main': main.c:(.text.startup+0x3b): undefined reference to http_init'
main.c:(.text.startup+0x48): undefined reference to http_init' main.c:(.text.startup+0x59): undefined reference to http_open_chunked'
main.c:(.text.startup+0x9e): undefined reference to http_write_chunked' main.c:(.text.startup+0xd3): undefined reference to http_write_chunked'
main.c:(.text.startup+0x120): undefined reference to http_write_chunked' main.c:(.text.startup+0x139): undefined reference to http_strerror'
main.c:(.text.startup+0x157): undefined reference to http_close' main.c:(.text.startup+0x15f): undefined reference to http_close'
main.c:(.text.startup+0x19c): undefine

d reference to `http_read_chunked'
collect2: error: ld returned 1 exit status

I also tried to include netlink libraries, using:

#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>

And try to compile using the line:

gcc -o main -fPIC -DHAVE_CONFIG_H -D_U_="attribute((unused))" -O2 -I/usr/include/libnl3/netlink/ -Imbedtls/include main.c ApiService.c mbedtls/library/libmbedx509.a mbedtls/library/libmbedtls.a mbedtls/library/libmbedcrypto.a

Then I got:

ApiService.c:17:8: warning: implicit declaration of function ‘http_open_chunked’; did you mean ‘http_read_chunked’? [-Wimplicit-function-declaration]
if(http_open_chunked(&hi2, url) == 0)
^~~~~~~~~~~~~~~~~
http_read_chunked
ApiService.c:21:12: warning: implicit declaration of function ‘http_write_chunked’; did you mean ‘http_read_chunked’? [-Wimplicit-function-declaration]
if(http_write_chunked(&hi2, data, size) != size)
^~~~~~~~~~~~~~~~~~
http_read_chunked
ApiService.c: In function ‘getTask’:
ApiService.c:106:5: warning: format not a string literal and no format arguments [-Wformat-security]
sprintf(data, cJSON_Print(task));
^~~~~~~
https.c: In function ‘mbedtls_net_connect_timeout’:
https.c:496:18: error: ‘errno’ undeclared (first use in this function); did you mean ‘h_errno’?
else if( errno == EINPROGRESS )
^~~~~
h_errno
https.c:496:18: note: each undeclared identifier is reported only once for each function it appears in
https.c:496:27: error: ‘EINPROGRESS’ undeclared (first use in this function)
else if( errno == EINPROGRESS )
^~~~~~~~~~~
https.c:515:33: error: ‘EINTR’ undeclared (first use in this function); did you mean ‘NLE_INTR’?
if(errno == EINTR) continue;
^~~~~
NLE_INTR
Makefile:16: recipe for target 'compile' failed

Link to repo https://github.com/HISONA/https_client. Please help I trying to compile that whole day, nothing works for me.

Amadeus
  • 63
  • 1
  • 7
  • Please read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly don't forget how to create a [mcve]. – Some programmer dude May 04 '19 at 18:52
  • Did you try `make`? – EOF May 04 '19 at 18:53
  • Yes, I did it, it caused the same error as in the first example – Amadeus May 04 '19 at 18:55
  • Sorry I just don't have much time to solve this but I will definitely read this later – Amadeus May 04 '19 at 18:58

1 Answers1

1

The implicit declaration of function error means that the compiler cannot locate the function in your workspace. you should indicate to the caller where the http_open_chunked function reside in your code by including the header (.h) file where it is impleented.

  • Its part of lnetlink library but when I'm including this, it causes warning: warning: implicit declaration of function ‘http_write_chunked’; did you mean ‘http_read_chunked’? [-Wimplicit-function-declaration] if(http_write_chunked(&hi2, data, size) != size) ^~~~~~~~~~~~~~~~~~ http_read_chunked. gcc -lnetlink doesn't work for me neither https://stackoverflow.com/questions/27634846/libnetlink-gcc-undefined-reference-to-rtnl-open[/link] – Amadeus May 04 '19 at 19:17
  • you have many errors, also `undeclared (first use in this function)` which means the compiler can't recognise the variable.. * when you have many errors, you should always handle the first one. * you should follow the header hierarchy and make sure of the nested headers, if exists, contains the right declaration. –  May 04 '19 at 19:27
  • Thanks I solved this in the example there were badly named functions – Amadeus May 04 '19 at 19:48
  • glad to hear that:) ok, misspelling references is considered as not known by the compiler too.. –  May 04 '19 at 20:00