Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant