New to C++ and in need of some debugging Help

Well, I’ve made some progress. Took me a couple days to get everything sorted and installed so I can compile locally. Finally working through getting this flashed to my core

I am inevitably working through mistakes that are clearly user error, but I’ve hit one that I’m not sure about:

obj/src/openweathermap.o: In function HttpClient::get(http_request_t&, http_response_t&)': G:\Spark\core-firmware\build/../inc/HttpClient.h:73: undefined reference toHttpClient::request(http_request_t&, http_response_t&, http_header_t*, char const*)'
collect2.exe: error: ld returned 1 exit status
make: *** [core-firmware.elf] Error 1

It’s a little above my pay-grade I think. Any ideas?

@ross, you could try to move this block of HttpClient.h

private:
    /**
    * Underlying HTTP methods.
    */
    void request(http_request_t &aRequest, http_response_t &aResponse, http_header_t headers[], const char* aHttpMethod);
    void sendHeader(const char* aHeaderName, const char* aHeaderValue);
    void sendHeader(const char* aHeaderName, const int aHeaderValue);
    void sendHeader(const char* aHeaderName);

to the top of the class definition (between class HttpClient { and public:) and then try building again.

Your error message suggests that HttpClient::request() is used (aka referenced) before it is declared.
The line void request(http_request_t &aRequest, http_response_t &aResponse, http_header_t headers[], const char* aHttpMethod); without an actual implementation is called a prototype and is meant to “tell” the compiler what is meant if someone starts talking about HttpClient::request() and it’d not need to complain, because an implementation will follow somewhere else.

Since I expect that @nmattisson and @Coffee had no such error messages when they built their projects, I’d expect there must be slight differences in the used compilers/compiler settings - some look ahead within the current files they are trying to parse/compile before complaining, while others insist in having seen every token prototyped or implemented before allowing to use it.

1 Like

Just from glancing at it, I’d say it looks like a linker error. Did you add HttpClient to your build file?

build.mk should have a line like this:
CPPSRC += $(TARGET_SRC_PATH)/HttpClient.cpp

@nmattisson ugh, duh. Left one out.

And with that…It’s working!!! Added an if else to change the core LED based on the temp. You can’t imagine how excited I was when that damned little LED changed colors.

Thanks for the help everyone, especially @Coffee

1 Like

Great @ross! I’m happy to see it work, and I’m glad that HttpClient sees some more use!
It’s a new library so it will likely have flaws, and if you find any don’t hesitate to let me know.

1 Like