Voici hello.cpp. Je suis sur OS X. J'ai construit PETSc directement à partir de la source.Erreur lors de la compilation de l'exemple PETSc sous OS X
#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;
}
Et voici mon 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)
qui donne
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
Il semble que la bibliothèque est un lien correctement. Une grande partie du bavardage à propos de ce sujet dit d'essayer d'utiliser g ++, ce que je fais.
Mon C++ - Fu est faible. J'ai ajouté 'LIBS = -L $ (PETSC_LIB_DIR) -l $ (PETSC_LIB_DIR)/libpetsc.dylib' et j'obtiens' ld: bibliothèque introuvable pour -l/usr/local/Cellar/petsc/3.7.6_3/lib/libpetsc.dylib' (utilise maintenant les librairies Cellar) Est-ce parce qu'il veut un '.a'? –
Essayez juste -lpetsc. Le compilateur recherchera la bibliothèque dans le dossier -L que vous avez spécifié. –
Merci beaucoup! Je veux retraiter à Python et à la Chapelle maintenant ... –