Search code examples
ceclipseibm-cloudundefined-referenceiot

undefined reference to function that is already defined


Currently trying to build a project in eclipse. The project explorer is shown below:

enter image description here

In cabbie.c I get the error, undefined reference to initialize..., in the code below:

#include <stdio.h>
#include <stdlib.h>
#include "../iotfclient.h"

Iotfclient client;
int rc;

int main() {
    /* Setup your example here, code that should run once
     */

    rc = initialize(&client, "h7dzt2", "Edison_cabquam", "notwindows95", "token", "Over_9000");

    /* Code in this loop will run repeatedly
     */
    for (;;) {

    }

    return 0;
}

The function is already defined in iotfclient.h which was included as a header file. Is it correct to define it as ../iotfclient.h? Am I supposed to make a Makefile? The function prototype in iotfclient.h is given below:

int initialize(Iotfclient *client, char *orgId, char *deviceType, char *deviceId, char *authmethod, char *authtoken);
/**
* Function used to initialize the IBM Watson IoT client using the config file which is generated when you register your device
* @param client - Reference to the Iotfclient
* @param configFilePath - File path to the configuration file 
*
* @return int return code
* error codes
* CONFIG_FILE_ERROR -3 - Config file not present or not in right format
*/

This project is trying to connect the bluemix IOT Platform.


Solution

  • initialize() is declared in iotfclient.h. However, it's not necessary defined. In other words, the compiler knows identifier initialise stands for a function, but to create a program, you have also to tell the linker how the function works, that is, add the function body.

    Try including ../iotfclient.c.