这是你好.cpp。我在 OS X 上。我直接从源代码构建了 PETSc。
#include <petscvec.h>
int main(int argc,char **argv)
{
Vec x;
PetscInitialize(&argc, &argv, NULL, NULL);
VecCreateSeq(PETSC_COMM_SELF, 100, &x);
VecSet(x, 1.);
PetscFinalize();
return 0;
}
这是我的makefile
PETSC_BASE_DIR=/Users/buddha/src/petsc
PETSC_LIB_DIR=${PETSC_BASE_DIR}/lib
PETSC_INCLUDE_DIR=${PETSC_BASE_DIR}/include
INCLUDES=$(PETSC_INCLUDE_DIR)
LIBS=$(PETSC_LIB_DIR)
CC=g++
EXEC=oy
ARGS=-Wall -lstdc++
CPP=hellp.cpp
#CPP=oy.cpp
all: hello.cpp
$(CC) $(ARGS) -I$(INCLUDES) -L$(LIBS) -o $(EXEC) $<
clean:
rm $(EXEC)
run:
./$(EXEC)
哪个产量
make
g++ -Wall -lstdc++ -I/Users/buddha/src/petsc/include
-L/Users/buddha/src/petsc/lib -o oy hello.cpp
Undefined symbols for architecture x86_64:
"_PetscFinalize", referenced from:
_main in hello-924d8b.o
"_PetscInitialize", referenced from:
_main in hello-924d8b.o
"_VecCreateSeq", referenced from:
_main in hello-924d8b.o
"_VecSet", referenced from:
_main in hello-924d8b.o
"_ompi_mpi_comm_self", referenced from:
_main in hello-924d8b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
看来图书馆链接正确。很多关于这个话题的讨论都说尝试使用 g++,我正在这样做。