I want to use a C library in a C++ code, without modifying it.
The library contains fragment of code non-compatible with c++ like :
- C++ keyword
new
anddelete
_Atomic
object- bad declaration
I compiled the C library into a .so
. And I also used it on an another C code and it worked perfectly (in fact I want to made a C++ version of this code).
My CMakeLists :
# Specify the minimum CMAKE version required
cmake_minimum_required(VERSION 2.8)
# Project name
project(myproject)
# Header files
set(HEADERS myCpp.h)
# Source files
set(SOURCES myCpp.cpp)
add_executable(myproject myCpp.cpp myCpp.h)
# Link libraries
LINK_DIRECTORIES(/usr/lib/libfrr.so)
target_link_libraries(${PROJECT_NAME} frr)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(CMAKE_CXX_FLAGS "-fpermissive")
My header starts with :
extern "C"{
#include "lib/libfrr.h"
}
I've got a tons of errors. A little compilation :
/lib/module.h:88:3: error: expected primary-expression before '.' token
.r.info = &_frrmod_info,
/lib/thread.h:123:2: error: '_Atomic' does not name a type
_Atomic unsigned int total_active;
lib/memory.h:163:13: error: 'struct memtype' has no member named 'n_alloc'
return mt->n_alloc;
/lib/libfrr.h:88:25: sorry, unimplemented: non-trivial designated initializers not supported
__VA_ARGS__}; \