如何在远程主机上使用 GNU 在 Netbeans7.1.1 中编译 C/C++

How to compile C/C++ in Netbeans7.1.1 with GNU on remote host

本文关键字:GNU Netbeans7 C++ 编译 程主机 主机      更新时间:2023-10-16

我已经安装了连接到远程构建主机(我的虚拟盒子)的 Netbeans 7.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 : %sn", 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 contexten");
    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

我知道这已经在这里被问了数千次,但我找不到正确的答案。如果你们中的任何人可以指导我,我将不胜感激,因为我是这方面的新手。

我不知道如何配置 Netbeans;但是如果您手动执行以下命令,您的代码编译起来不会有问题:

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

如果您还没有Makefile,这是一个好的开始:

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

但是,如果 Netbeans 强制您使用不同的构建系统,则必须找出另一种方法来适当地设置链接器选项。

libxml2 库位于 libxml2/libxml/* 下,但所有头文件都使用 libxml/*。

将指令更改为

#include <libxml2/libxml/*>

也会抱怨,因为所有指令都指向同一个文件夹;我在远程服务器上所做的一个解决方法是创建一个符号链接,指向包含文件夹下的库。

Debian Lenny 在 ARM 板上...

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

重新启动 Netbeans,所有红色都消失了,构建成功并成功运行。