Duplicate symbol error but Xcode doesn't specify where

I have an Xcode project that include a .c file and .h header file. I am getting a duplicate symbol error and I cannot pinpoint what part of my code is the issue or maybe if it's a configuration issue in my Xcode settings or not.

Here's my .h header file code with my declarations:

#define smc_h

#include <stdint.h>
#include <mach/mach.h>
#include <IOKit/IOKitLib.h>
    
    typedef struct {
        uint32_t datasize;
        uint32_t datatype;
        uint8_t data[8];
        
    } SMCVal_t;
    
    extern io_connect_t conn;
    
    kern_return_t openSMC(void);
    kern_return_t closeSMC(void);
    kern_return_t readSMC(char *key, SMCVal_t *val);
    
    double convertToFahrenheit(SMCVal_t *val);
    
#endif /* smc_h */

And here is my .c implementation:

#include "smc.h"
#include <mach/mach.h>
#include <IOKit/IOKitLib.h>




io_connect_t conn;

kern_return_t openSMC(void) {
    
    kern_return_t result;
    kern_return_t service;
    io_iterator_t iterator;

    service = IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceMatching("AppleSMC"), &iterator);
    if(service == 0) {
        printf("error: could not match dictionary");
        return 0;
    }
    result = IOServiceOpen(service, mach_task_self(), 0, &conn);
    IOObjectRelease(service);
    return 0;
}

kern_return_t closeSMC(void) {
    return IOServiceClose(conn);
    
}


kern_return_t readSMC(char *key, SMCVal_t *val) {
kern_return_t result;
uint32_t keyCode = *(uint32_t *)key;

SMCVal_t inputStruct;
SMCVal_t outputStruct;

inputStruct.datasize = sizeof(SMCVal_t);
inputStruct.datatype = 'I' << 24;         //a left shift operation. turning the I into an int by shifting the ASCII value 24 bits to the left

inputStruct.data[0] = keyCode;
result = IOConnectCallStructMethod(conn, 5, &inputStruct, sizeof(SMCVal_t), &outputStruct, (size_t*)&inputStruct.datasize);

if (result == kIOReturnSuccess) {
    if (val -> datasize > 0) {
        if (val -> datatype == ('f' << 24 | 'l' << 16 | 't' << 8 )) {    //bit shifting to from 32bit operation associated with the ASCII charecters'f', 'l', and 't', sets datatype field.
            double temp = *(double *)val -> data;
            return temp;
        }
    }
}
return 0.0;

}

  double convertToFahrenheit(SMCVal_t *val) {
   
        if(val -> datatype == ('f' << 24 | 'l' << 16 | 't' << 8 )) {         //checking if val->datatype is equal to the result of the bit-shifting operation.
        double temp = *(double *)val -> data;
        return (temp * 9.0 / 5.0) + 32.0;
        
    }
    return 0.0;
}


Replies

I am getting a duplicate symbol error and I cannot pinpoint what part of my code is the issue

Xcode hides this away. You need to look at the build log and then click to reveal the actual linker error messages.

Search the forum for “undefined symbol” to find detailed instructions.