<div dir="ltr"><div dir="ltr">On Thu, Dec 14, 2023 at 1:27 AM 2111191--- via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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>
<br>
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></blockquote><div><br></div><div>First, get rid of the "extern C" in front of the headers.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
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<br>
<br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>