project(testproject CXX C)
cmake_minimum_required(VERSION 3.0)
find_package(ROOT REQUIRED COMPONENTS RIO)
message(STATUS "ROOT ${ROOT_VERSION} found at ${ROOT_BINDIR}")
add_executable(testproject ./src/main.c ./src/create_rootfile.cpp)
target_link_libraries(testproject ROOT::RIO)
I get the error:
error: unknown type name ‘TFile’
which makes sense to me. But I also understand that I cannot include ROOT header files in my c code since they are written for c++, is that right? Because trying to include the TFile header in my c code then gives me the error that the header is not found.
Added the header file to my build and included it in the main.c file.
It still does not work. Tried to fiddle around with the suggested header without any success.
With your suggestion I get the following errors:
...../test/include/RootHeader.h:5:8: error: expected identifier or '('
extern "C" TFile* CreateRootFile();
^
...../test/src/main.c:5:2: error: must use 'struct' tag to refer to type 'TFile'
TFile* file = CreateRootFile();
^
struct
....../src/main.c:5:16: error: implicit declaration of function 'CreateRootFile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
TFile* file = CreateRootFile();
^
......./test/src/main.c:5:9: warning: incompatible integer to pointer conversion initializing 'struct TFile *' with an expression of type 'int' [-Wint-conversion]
TFile* file = CreateRootFile();
Ok that makes sense. What would be a workaround?
Defining another method in the cpp file taking the file and tree as input arguments? Would something like this work?
Unfortunately this is not possible. I try to modify open source software which comes with a waveform digitizing ADC which is completely written in C and quite complex.It comes with methods to store the data to ascii or binary files but I’d like to store it directly in a rootfile. I mean, another way I can think of is simply using the built in methods to store the data and then write another program which reads the ouput files and creates the rootfile. But that sounds quite cumbersome.
It is much easier to link a C++ “main” program against C libraries than the opposite (i.e., calling C functions from C++ is usually pretty straightforward).