Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Trying to call metal_spi_get_device in a c++ class #628

Open
Emil808 opened this issue Jan 14, 2022 · 0 comments
Open

Trying to call metal_spi_get_device in a c++ class #628

Emil808 opened this issue Jan 14, 2022 · 0 comments

Comments

@Emil808
Copy link

Emil808 commented Jan 14, 2022

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant