1

リモートビルドホスト(仮想ボックス)に接続するNetbeans7.1.1をインストールしました。特定のウェブサイトで見つけたプログラムをコンパイルしようとしました。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>

// Appelée à la rencontre de chaque balise ouvrante
void debut_element(void *user_data, const xmlChar *name, const xmlChar **attrs) {
printf("Début de l'élément : %s\n", name);
}

int main() {
// Initialisation à zéro de tous les membres (NULL pour un pointeur par conversion)
xmlSAXHandler sh = { 0 };

// Affectation des fonctions de rappel
sh.startElement = debut_element;

xmlParserCtxtPtr ctxt;
// Création du contexte
if ((ctxt = xmlCreateFileParserCtxt("catalogue.xml")) == NULL) {
    fprintf(stderr, "Erreur lors de la création du contexte\n");
    return EXIT_FAILURE;
}
// Fonctions de rappel à utiliser
ctxt->sax = &sh;
// Analyse
xmlParseDocument(ctxt);
// Le document est-il bien formé ?
if (ctxt->wellFormed) {
    printf("Document XML bien formé\n");
} else {
    fprintf(stderr, "Document XML mal formé\n");
    xmlFreeParserCtxt(ctxt);
    return EXIT_FAILURE;
}
// Libération de la mémoire
xmlFreeParserCtxt(ctxt);

return EXIT_SUCCESS;
}

ただし、コンパイル中にこのエラーメッセージが表示されました

Copying project files to /home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/ at saebyuk@redHat
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory `/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat'
"/usr/bin/gmake"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/xml_decoder_red_hat
gmake[2]: Entering directory `/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat'
gmake[2]: Warning: File `main.cpp' has modification time 2.1e+04 s in the future
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++    -c -g -Wall -I/usr/include/libxml2 -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++     -I/usr/include/libxml2 -o dist/Debug/GNU-Linux-x86/xml_decoder_red_hat build/Debug/GNU-Linux-x86/main.o  
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat/main.cpp:35: undefined reference to `xmlCreateFileParserCtxt'
/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat/main.cpp:40: undefined reference to `xmlParseDocument'
/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat/main.cpp:46: undefined reference to `xmlFreeParserCtxt'
collect2: ld returned 1 exit status
gmake[2]: *** [dist/Debug/GNU-Linux-x86/xml_decoder_red_hat] Error 1
gmake[2]: Leaving directory `/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat'
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory `/home/saebyuk/.netbeans/remote/redHat/saebyuk-pc-Windows-x86/C/Users/saebyuk/Documents/NetBeansProjects/xml_decoder_Red_hat'
gmake: *** [.build-impl] Error 2

私はこれがここで何千回も尋ねられたことを知っていますが、私は正しい答えを見つけることができませんでした。私はこれに慣れていないので、あなたの誰かが私を導くことができれば感謝します。

4

2 に答える 2

0

libxml2 ライブラリは libxml2/libxml/* の下にありますが、すべてのヘッダー ファイルは libxml/* を使用しています。

ディレクティブをに変更

#include <libxml2/libxml/*>

すべてのディレクティブが同じフォルダーを指しているため、エラーも発生します。私がリモート サーバーで行った回避策は、インクルード フォルダーの下にライブラリへのシンボリック リンクを作成することでした。

ARM ボード上の Debian Lenny...

ln -s /usr/include/libxml2/libxml /usr/include/libxml

Netbeans を再起動すると、すべての赤が消え、ビルドが成功し、正常に実行されました。

于 2014-01-07T00:31:18.207 に答える
0

Netbeans の設定方法がわかりません。ただし、このコマンドを手動で実行すると、コードは問題なくコンパイルされます。

gcc -o xmltest xmltest.c -I /usr/include/libxml2 -lxml2

をまだ持っていない場合はMakefile、これが良いスタートです:

LDFLAGS := -I /usr/include/libxml2 -lxml2

しかし、Netbeans が別のビルド システムの使用を強制する場合は、リンカー オプションを適切に設定する別の方法を考え出す必要があります。

于 2012-04-22T00:44:23.217 に答える