Trying to call metal_spi_get_device in a c++ class
Opened this issue · 0 comments
Emil808 commented
Hi, I'm trying to make a device driver and want to use the metal spi API. When I make a c++ class and try to use metal_spi_get_device, compiling will result in an undefined reference. Is it something with the makefile?
I back track and tried it with something simple, I have these:
main.c
#include "func.h"
int main(){
func_init();
return 0;
}
func.h
#ifdef __cplusplus
extern "C" {
#endif
void init_func(void);
#ifdef __cplusplus
}
#endif
func.cpp
#include "func.h"
#include <metal/spi.h>
#ifdef __cplusplus
extern "C" {
#endif
void init_func(void){
metal_spi_get_device(1);
}
#ifdef __cplusplus
}
#endif
makefile
ROGRAM ?= sandbox
CFILES = $(wildcard *.c)
CXXFILES= $(wildcard *.cpp)
OBJFILES = $(CFILES:.c=.o)
CXXOBJFILES = $(CXXFILES:.cpp=.o)
$(PROGRAM): $(OBJFILES) $(CXXOBJFILES) #$(wildcard *.c) $(wildcard *.h) $(wildcard *.S) $(wildcard *.cpp)
$(CXX) $(CXXFLAGS) -Iinclude $(OBJFILES) $(CXXOBJFILES) $(LDFLAGS) -lstdc++ $(LOADLIBES) $(LDLIBS) -o $@
%.o : %.c %.cpp
$(CXX) $(CXXFLAGS) -c $@ $<
clean:
rm -f $(PROGRAM) $(PROGRAM).hex $(OBJFILES)