Question

I'm trying to use libbz2 library with ROOT framework but I haven't reached any success. I wrote test app without ROOT using libbz2 and it works fine. Here is my code:

#ifndef BZlib_H
#define BZlib_H

#include <bzlib.h>
#include <iostream>

class BZlib : public std::streambuf, virtual public std::istream
{
BZFILE * fbz2File;
...
}

He is my makefile:

CC=g++
TARGET=bzip_happiness
HEADERS=$(wildcard *.h)
SOURCES=$(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)

# Flags
CXXFLAGS = -c -g

all: $(TARGET)

$(OBJECTS): $(HEADERS)

.cpp.o:
    $(CC) -Wall $(CXXFLAGS) $< -o $@

$(TARGET): $(OBJECTS)
    $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) -L. -lbz2 -Wl,-rpath,.

clean:
    rm -f $(TARGET) $(OBJECTS)

.PHONY: all clean

When I try to use this code with the ROOT framework, compilation fails with the following message:

>  - Generating dictionary BBaseCint.cc
rootcint -f BBaseCint.cc \
-c -I. -I../mfileio -I../mfbase -I../mastro -I../MBase -I../mbase -I../mgui -DMARSVER=\"2.4\" -D__MARS__   BZlib.h  BBaseIncl.h BBaseLinkDef.h 
Error: Too many '}' /usr/include/bzlib.h:275:
make: *** [BBaseCint.cc] Segmentation fault
make: *** Deleting file `BBaseCint.cc'

All my code is the same except the headers:

#ifndef BZlib_H
#define BZlib_H

#ifndef ROOT_TObject
#include <TObject.h>
#endif

#include <bzlib.h>
#include <iostream>

class BZlib : public std::streambuf, virtual public std::istream, public TObject
{
private:
    BZFILE * fbz2File;
    ...
    ClassDef(BZlib, 0)
};
#endif

Line 275 in bzlib.h contains the following code:

#ifdef __cplusplus
}
#endif

which is the closing brace for

#ifdef __cplusplus
extern "C" {
#endif

How can I solve the problem?

Was it helpful?

Solution

Oook, the problem is rootcint cannot interprate extern "C".

The solution is to replace the following code in bzlib.h

#ifndef BZ_IMPORT                                                           
#define BZ_EXPORT                                                           
#endif                                                                      

#ifndef BZ_NO_STDIO
/* Need a definitition for FILE */                                          
#include <stdio.h>                                                          
#endif                                                                      

#ifdef _WIN32
#   include <windows.h>                                                     
#   ifdef small
      /* windows.h define small to char */                                  
#      undef small                                                          
#   endif
#   ifdef BZ_EXPORT
#   define BZ_API(func) WINAPI func                                         
#   define BZ_EXTERN extern                                                 
#   else
   /* import windows dll dynamically */                                     
#   define BZ_API(func) (WINAPI * func)                                     
#   define BZ_EXTERN                                                        
#   endif                                                                   
#else
#   define BZ_API(func) func                                                
#   define BZ_EXTERN extern                                                 
#endif  

with

#ifndef BZ_NO_STDIO
/* Need a definitition for FILE */
#include <cstdio>
#endif


#define BZ_EXTERN extern "C"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top