<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 14 Dec 2023, at 4:13 AM, 2111191--- via petsc-users <petsc-users@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><div>Dear SLEPc Developers,<br><br>I a am student from Tongji University. Recently I am trying to write a c++ program for matrix solving, which requires importing the PETSc library that you have developed. However a lot of errors occur in the cpp file when I use #include <petscts.h> directly. I also try to use extern "C" but it gives me the error in the picture below. Is there a good way to use the PETSc library in a c++ program? (I compiled using cmake and my compiler is g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)).<br></div></div></blockquote><div><br></div><div>This compiler (gcc 4.8.5) is known to not be C++11 compliant, but you are using the -std=c++11 flag.</div><div>Furthermore, since version 3.18 (or maybe slightly later), PETSc requires a C++11-compliant compiler if using C++.</div><div>Could you switch to a newer compiler, or try to reconfigure?</div><div>Also, you should not put all the include inside an extern { }.</div><div>In any case, you’ll need to send the compilation error log and configure.log to <a href="mailto:petsc-maint@mcs.anl.gov">petsc-maint@mcs.anl.gov</a> if you want further help, as we won’t be able to give a better diagnosis with just the currently provided information.</div><div><br></div><div>Thanks,</div><div>Pierre</div><br><blockquote type="cite"><div><div>My cmakelists.txt is:<br><br>cmake_minimum_required(VERSION 3.1.0)<br><br>set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)<br><br>set(PETSC $ENV{PETSC_DIR}/$ENV{PETSC_ARCH})<br>set(SLEPC $ENV{SLEPC_DIR}/$ENV{PETSC_ARCH})<br>set(ENV{PKG_CONFIG_PATH} ${PETSC}/lib/pkgconfig:${SLEPC}/lib/pkgconfig)<br><br>set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") <br>set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") <br><br>project(test)<br><br>add_executable(${PROJECT_NAME} eigen_test2.cpp)<br>find_package(PkgConfig REQUIRED)<br><br>pkg_search_module(PETSc REQUIRED IMPORTED_TARGET PETSc)<br>target_link_libraries(${PROJECT_NAME} PkgConfig::PETSc)<br><br>The testing code is:eigen_test2.cpp<br>extern "C"{<br> //#include <petsc.h><br> #include <petscts.h><br> #include <petscdm.h><br> #include <petscdmda.h><br> #include <petscdraw.h><br>}<br><br>int main(int argc,char **argv)<br>{ <br> return 0;<br>}<br><br><br><br>Best regards<br><br>Weijie Xu</div></div></blockquote></div><br></body></html>