【问题标题】:netbeans c program build fail with tdm-gcc msysnetbeans c程序构建失败,tdm-gcc msys
【发布时间】:2017-01-13 13:55:50
【问题描述】:

我最近开始使用 netbeans 在 c 中编程。我通常使用代码块。为此,我已经安装了 tdm-gcc 和 msys。

程序正在成功编译。但在执行时,它显示构建失败(退出值 2)。

    "/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/f/NetBeansProjects/C_Programs'
"/C/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_TDM-Windows/c_programs.exe
make.exe[2]: Entering directory `/f/NetBeansProjects/C_Programs'
mkdir -p build/Debug/MinGW_TDM-Windows
rm -f "build/Debug/MinGW_TDM-Windows/main.o.d"
gcc    -c -g -MMD -MP -MF "build/Debug/MinGW_TDM-Windows/main.o.d" -o build/Debug/MinGW_TDM-Windows/main.o main.c
mkdir -p dist/Debug/MinGW_TDM-Windows
gcc     -o dist/Debug/MinGW_TDM-Windows/c_programs build/Debug/MinGW_TDM-Windows/main.o build/Debug/MinGW_TDM-Windows/structure_union.o 
build/Debug/MinGW_TDM-Windows/structure_union.o: In function `main':
F:\NetBeansProjects\C_Programs/structure_union.c:32: multiple definition of `main'
build/Debug/MinGW_TDM-Windows/main.o:F:\NetBeansProjects\C_Programs/main.c:15: first defined here
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW_TDM-Windows/c_programs.exe] Error 1
make.exe[2]: Leaving directory `/f/NetBeansProjects/C_Programs'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/f/NetBeansProjects/C_Programs'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 657ms)

有人可以帮我解决我做错了什么吗?

【问题讨论】:

    标签: c netbeans msys build-error tdm-gcc


    【解决方案1】:

    您的项目中有多个main() 函数:

    […]/structure_union.c:32: `main'的多重定义

    structure_union 中似乎有一个,main.c 中似乎有另一个(第 15 行)。

    C 只允许main()一个定义;删除其中一个,它应该可以工作。

    【讨论】:

    • 我删除了另一个 main() 函数。现在它显示构建成功。但是运行该项目花费的时间太长。为什么 msys 窗口打不开?
    • 能比较一下NB和终端的时间吗?如果你有一个控制台项目,你不会得到一个窗口,它是在 Netbeans 终端中执行的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 2019-05-30
    • 1970-01-01
    相关资源
    最近更新 更多