"Christmas - the time to fix the computers of your loved ones" « Lord Wyrm

C: undefined reference to function

wergor 20.04.2020 - 18:57 2685 3
Posts

wergor

connoisseur de mimi
Avatar
Registered: Jul 2005
Location: graz
Posts: 4021
ich habe eine c library:
Code:
//tmp117.h

#ifndef TMP117_H_
#define TMP117_H_

//[...]

/*
 * resets and initializes a TMP117 sensor.
 * @return true on success (sensor responds), false otherwise
 */
bool TMP117Init(TMP117Settings *settings);

//[...]

#endif /* TMP117_H_ */
Code:
//tmp117.c

#include "tmp117.h"

bool TMP117Init(TMP117Settings *settings) {
  //[...]
}

//[...]
und benutze sie wie folgt:
Code:
#include "tmp117.h"

void setup() {
  // put your setup code here, to run once:

  TMP117Settings tmp117_settings[1];
  tmp117_settings[0].address = ADDRESS_0x48;
  
  for (int i = 0; i < 1; i++) {
    TMP117Init(&tmp117_settings[0]);
  }
}
das gefällt dem compiler nicht:
Zitat
C:\Users\wergor\Documents\Arduino\TMP117test/TMP117test.ino:11: undefined reference to `TMP117Init(TMP117Settings*)'
(arduino IDE)
Zitat
.pio\build\genericSTM32F103CB\src\main.cpp.o: In function `setup()':
main.cpp: (.text._Z5setupv+0xa): warning: undefined reference to `TMP117Init(TMP117Settings*)'
(platformIO)

woran liegt das? :confused:
Bearbeitet von wergor am 20.04.2020, 19:33

COLOSSUS

Administrator
Frickler
Avatar
Registered: Dec 2000
Location: ~
Posts: 11897
Du musst deinem Compiler wohl auch noch mitteilen, dass er (bzw. sein Linker) die Library, deren Header du includest, beim Linken auch verwenden soll. Vermutlich: `g++ -ltmp117 <your_other_args_here>`. Evtl. brauchst du auch noch "-L<lib_dir>" im Argumentvektor, falls die Library nicht in den Default-Pfaden (kA unter Windows) installiert ist.

Vinci

hatin' on summer
Registered: Jan 2003
Location: Wien
Posts: 5774
Das liegt am Name Mangling von C++. Du braucht einen extern "C" Block rund ums include.

wergor

connoisseur de mimi
Avatar
Registered: Jul 2005
Location: graz
Posts: 4021
@colossus ich benutze die arduino ide und platformio, afaik kann ich da die parameter fürn compiler nicht so einfach ändern.
@vinci das wars! danke!
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz