c语言问题,高手请

来源:百度知道 编辑:UC知道 时间:2024/05/02 23:09:46
前提 我保证 程序是 正确的(说明 ::我的main.cpp里用include包含了一个aux.cpp 和aux.h文件):才有以下问题->>
请问高手为什么我写的c程序在 shell 下用 g++ main.cpp 编译是正确的,且生成 a.out是正确的。。

然而有什么 在Netbeans 下 一个工程中 为什么 编译 成功后,点击Run->Run Main Project..确出现以下错误

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/root/NetBeansProjects/expressionCal'
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/expressioncal
make[2]: Entering directory `/root/NetBeansProjects/expressionCal'
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/expressioncal build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/expressioncal] Error 1
make[2]: Leaving directory `/root/NetBeansProjects/expressionCal'
make[1]: *** [.build-co

你怎么问了两个地方啊,可能是重定义问题,不是的话,就把代码贴一下吧:

写头文件时进行宏定义检查及宏定义,防止重复包含同一段代码,那对编译器就是重定义,肯定报错,你都写在main肯定只有包含一次了,因此要这样做:
aux.h:
#ifndef AUX_H
#define AUX_H
// 。。。头文件代码
#endif

包含头文件前进行是否已被包含检查:
#ifndef AUX_H
# include "aux.h"
#endif

.cpp应该是只有实现的,不应该去include cpp。如果有东西在cpp是在外部需要用到的,请在.h添加定义。只需要include .h即可。

linux和windows应该不一样,你的make有没有设环境变量,你的程序有没有连接库文件

#include 可以包含cpp文件么,学习了