Im getting a duplicate symbols error when I build my Xcode project and Xcode doesn't specify what or where in my code is there a duplicate:
"1 duplicate symbols" "Showing Recent Issues Linker command failed with exit code 1 (use -v to see invocation) "
#include <stdio.h>
#include <IOKit/IOKitLib.h>
typedef struct {
uint32_t datasize;
uint32_t datatype;
uint8_t data[32];
} SMCVal_t;
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'
float temp = *(float *)val -> data;
return temp;
}
}
}
return 0.0;
}
double getTemperature(char *key) {
SMCVal_t val;
kern_return_t result;
result = readSMC(key, &val);
if(result == kIOReturnSuccess) {
if (val.datasize > 0) {
printf("val.datasize: %u\n", val.datasize);
if (val.datatype != 0) {
double temperature = (double)val.data[0];
return temperature;
}
}
}
return 0.0;
}
double convertToFahrenheit(double Fahrenheit) {
return (Fahrenheit * (9.0 / 5.0)) + 32.0;
}
int main(void) {
kern_return_t result;
result = openSMC();
if(result == kIOReturnSuccess) {
double temp = getTemperature("TC0P");
double temperatureInFahrenheit = convertToFahrenheit(temp);
printf("temp: %.2f\n", temperatureInFahrenheit);
result = closeSMC();
}
return 0;
}