Hi folks,

I have a problem...

Der erste Ordner ./src mit der main hat folgendes Makefile (automatisch erzeugt)

include C:/IPG/hil/win32-4.0.5/include/MakeDefs

APP_VER     = "Car_Generic <insert.your.version.no>"
APP_NAME    = CarMaker.$(ARCH)$(EXE_EXT)

#OPT_CFLAGS = -g -O1

LD_LIBS     = $(CAR_LIB) $(EKF_LIB) $(CARMAKER_LIB) $(DRIVER_LIB) $(ROAD_LIB) $(TAME_LIB) 

OBJS        = CM_Main.o CM_Vehicle.o User.o
OBJS_xeno   = IO.o $(OBJS_CANIOGEN) $(OBJS_CANIOGEN_USER)
OBJS_linux  =
OBJS_win32  =


### UserVehicle vehicle model in C code
CAR_LIB     =   ../src.Car_c/libcar_$(ARCH).a
INC_CFLAGS +=   -I../src.Car_c


default:    $(APP_NAME)
$(APP_NAME):    $(OBJS_$(ARCH)) $(OBJS) $(LD_LIBS_MK) app_tmp.o
    $(QECHO) " LD     $@"
    $Q $(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
        $(OBJS_$(ARCH)) $(OBJS) $(LD_LIBS) $(LD_LIBS_OS) \
        app_tmp.o
    $(SET_EXE_PERMISSIONS) $@


install: $(APP_NAME)
    $(INSTALL_APP) $(APP_NAME) $(ARCH)

clean:
    -rm -f  *~ *% *.o core

app_tmp.c: Makefile $(OBJS_$(ARCH)) $(OBJS) $(LD_LIBS_MK)
    $(QECHO) " MK     $@"
    $Q $(CREATE_INFO_CMD)

depend .depend: Makefile
    $(QECHO) " MK     $@"
    $Q-$(CC)  $(CFLAGS)  $(DEPCFLAGS)  *.c > .depend
#   $Q-$(CCC) $(CCFLAGS) $(DEPCCFLAGS) *.cc >> .depend
include .depend

%.depend_caniogen:  Makefile
    $(QECHO) " MK     $@"
    $Q $(CANIOGEN) -mkrules "$*.o" > $@
ifneq ($(OBJS_CANIOGEN),)
include $(OBJS_CANIOGEN:.o=.depend_caniogen)
endif

Der zweite Ordner ./src.Car_centhält das Makefile (teils automatisch erzeugt)

include C:/IPG/hil/win32-4.0.5/include/MakeDefs


CAR_OBJS =  Car.o KalmanFilter.o rt_nonfinite.o rtGetInf.o rtGetNaN.o

# OPT_CFLAGS =  -g -O1

default: libcar_$(ARCH).a

libcar_$(ARCH).a: $(CAR_OBJS) Makefile
    $(RM) $@
    $(AR) urvs $@ $(CAR_OBJS)




clean:
    -rm -f  *~ *.bak *.ps *.log *% *.o *.s lib*.a core

mrproper: clean
    -rm -f lib*.a .depend*

# Der letzte Platzhalter bei *.c* schließt auch .cpp Dateien ein
depend .depend: Makefile
    -$(CC)  $(CFLAGS)  $(DEPCFLAGS)  *.c* > .depend

include .depend

### UserVehicle vehicle model in C code
CAR_LIB =../src.Car_c/libcar_$(ARCH).a
INC_CFLAGS +=-I../src.Car_c

Die Objekt-Dateien KalmanFilter.o rt_nonfinite.o rtGetInf.o rtGetNaN.osind hier neu und gehören zu einer Funktion KalmanFilter.cpp (plus .h und ein paar anderen files), die von Matlab erzeugt wurde.

Die betreffende Funktion Car_Calc() in ./src/Car.c enthält die Funktion KalmanFilter(Xe, Ad, Xi, U, Y, Ye, Px, P, statP, Pxi, Ptheta, xi, theta, Cd, Theta); Am Anfang der Datei habe ich die Zeile

#include "../src.Car_c/KalmanFilter.h"

eingefügt, um die Funktion aufrufen zu können.

Zunächst führe ich dann make im Ordner ./src.Car_c aus, wobei das funktioniert. Führe ich make im Ordner ./src aus kommt folgende Fehlermeldung:

 MK     app_tmp.c
 CC     app_tmp.o
 LD     CarMaker.win32.exe
../src.Car_c/libcar_win32.a(Car.o):Car.c:(.text+0x456b): undefined reference to `KalmanFilter'
make: *** [CarMaker.win32.exe] Error 1

Wo liegt der Fehler?

Vielen Dank für eure Mühe!!!

Please use English in this forum.

(Du bist glücklich dass ich Deutsch verstehen kann)

All seems correct. However, because your KalmanFilter.cpp file is a C++ file, and most other source files (especially Car.c) are C files, it might just be a problem with name-mangling. Your C files expect a C function called "KalmanFilter", but your KalmanFilter.cpp file defines a C++ function of the same name, which will be mangled (to account for overloading) and will thus not be found by the linker.

Have you declared your KalmanFilter function as extern "C" in your header file (under a #ifdef __cplusplus condition)?

Also, if everything else is in C, you might as well make the KalmanFilter file into C files as well.

Hi Mike,

I am sorry. I was very tired yesterday, so I switch to German somehow.

Thank you very much for your fast answer. I understand, it makes sense. I already thought, that mixing C and C++ takes more efforts. Have to read again the chapters about extern C etc.

Have a nice Chrismas!
Christian

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.