J'essaie d'utiliser gnuplot_i, une interface gnuplot pour ANSI-C, pour mon projet C++. (Voir here dans la section de téléchargement) Il semble juste composé d'un en-tête et un fichier source. Le Makefile crée juste un fichier objet, j'ai donc décidé d'intégrer complètement ces deux fichiers dans mon projet. Cependant, je reçois des erreurs de références non définies aux fonctions qui sont implémentées dans le fichier source mentionné ci-dessus. Prenons l'exemple simplifié (main.cpp) suivant:référence non définie à `gnuplot_init() '
#include <gnuplot_i.h>
int main(int argc, char** argv) {
gnuplot_ctrl * h;
h = gnuplot_init();
return 0;
}
Le fichier d'en-tête peut être obtenu here et le fichier source here.
L'erreur que je reçois est la suivante:
build/Debug/GNU-Linux/main.o: In function `main':
/<some path>/proj/test/main.cpp:18: undefined reference to `gnuplot_init()'
collect2: error: ld returned 1 exit status
Cependant gnuplot_init()
est implémenté dans le fichier source qui est compilée dans un fichier objet qui est ensuite utilisé pour relier le programme. Vous pouvez le voir dans le journal complet ci-dessous. De plus, le fichier objet généré contient le symbole nécessaire:
$ nm gnuplot_i.o | grep gnuplot_init
0000000000000000 T gnuplot_init
journal complet:
cd '/<some path>/proj/test'
/usr/bin/make -f Makefile CONF=Debug clean
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory '/<some path>/proj/test'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux/test
make[1]: Leaving directory '/<some path>/proj/test'
CLEAN SUCCESSFUL (total time: 52ms)
cd '/<some path>/proj/test'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/<some path>/proj/test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/test
make[2]: Entering directory '/<some path>/proj/test'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/gnuplot_i.o.d"
gcc -c -g -I. -MMD -MP -MF "build/Debug/GNU-Linux/gnuplot_i.o.d" -o build/Debug/GNU-Linux/gnuplot_i.o gnuplot_i.c
gnuplot_i.c: In function ‘gnuplot_tmpfile’:
gnuplot_i.c:696:5: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
close(unx_fd);
^~~~~
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -I. -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/test build/Debug/GNU-Linux/gnuplot_i.o build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/<some path>/proj/test/main.cpp:18: undefined reference to `gnuplot_init()'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:64: dist/Debug/GNU-Linux/test] Error 1
make[2]: Leaving directory '/<some path>/proj/test'
make[1]: *** [nbproject/Makefile-Debug.mk:60: .build-conf] Error 2
make[1]: Leaving directory '/<some path>/proj/test'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 304ms)
Comme j'utilise un buildsystem généré automatiquement à partir NetBeans les Makefile sont assez grands et complexes. Mais il devrait être assez évident à partir du journal quelles commandes ont été émises. Qu'est-ce qui ne va pas ici? Est-ce un problème que je lier les fichiers C-Object et les fichiers C++-Object? D'après ce que je comprends, cela ne devrait pas.