so I have serveal C++ files and basically need to call a C function after the C++ part of my program is done. So if there is a way to just somehow magically "start the C file" (I hope you know what I mean) I would be glad to hear about that too. Now to my actual problem: I'm trying to call the C function at the end of my main function in the main C++ file. I already saw all of this Call a C function from C++ code and tried to do everything the correct way, my header file for the C file looks kind of like this:
#ifndef H_FILE
#define H_FILE
#ifdef __cplusplus
extern "C" {
#endif
void foo();
void bar();
#ifdef __cplusplus
}
#endif
I then tried to include the header file in the C++ file with this:
extern "C" {
#include "folder/file.h"
}
I also alternatively tried a basic #include "folder/file.h"
But I'm getting a undefined reference error when I'm trying to use the foo() function from my C file. My .pro file looks kind of like this:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Example
TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
SOURCES += main.cpp\
folder/file.c \
HEADERS += main.h \
So I guess I have to add some kind of flag for it to be compiled correctly, but what exactly am I missing? Thank you for your help!