c - Gradle undefined reference `WinMain@16' 错误

标签 c gradle mingw build.gradle

我是 gradle 和创建库的新手,我正在尝试创建一个库并稍后在创建可执行文件时链接它。专门看gradle来做构建系统。 我的项目文件夹结构如下,

NativeGradle(root folder)
    src
    build.gradle

(.h files are at)
NativeGradle\src\include -> includes (call.h and main.h)


source files (c files are at)

NativeGradle\src\atlas\call.c
NativeGradle\src\one\main.c

call.c:

#include "main.h"
#include "call.h"
void createSum()
{

    printf("Sum is %d\n", sumMe(5,4));

}


main.c

#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include "call.h"

int sumMe(int a, int b)
{
    return (a+b);
}

int main()
{

    printf("Hellow world !!\n");
    createSum();
    return 0;
}

call.h

#include <stdio.h> 
#include "main.h"
void createSum(void);

main.h

#include <stdio.h>
int sumMe(int , int);

下面是我正在使用的build.gradle

apply plugin: 'c'


model {  
    components {
     hello(NativeLibrarySpec) {
            sources {
                c {
                    source {
                        srcDirs "src/include"
                        include "call.h"
                        include "main.h"
                        srcDir "src/atlas"
                        include "*/call.c"
                    }

                }
            }
        }
    }

     components {
     out(NativeExecutableSpec) {
            sources {
                c {
                    source {
                        c.lib library: "hello" 
                        srcDirs "src/include"
                        include "call.h"
                        include "main.h"                      
                        srcDir "src/one"
                        include "*/main.c"
                    }

                }
            }
        }
    }


}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

当我给出 gradle build 命令时,出现以下错误

c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

:linkOutExecutable FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':linkOutExecutable'.
> A build operation failed.
      Linker failed while linking out.exe.
  See the complete log at: file:///C:/PROS/Training/NativeGradle/build/tmp/linkOutExecutable/output.txt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

linkOut可执行内容是

See file:///C:/PROS/Training/NativeGradle/build/tmp/linkOutExecutable/output.txt for all output for linkOutExecutable.
linking out.exe failed.
c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

Finished linkOutExecutable, see full log file:///C:/PROS/Training/NativeGradle/build/tmp/linkOutExecutable/output.txt.

请帮我解决一下 谢谢

最佳答案

“WinMain”表示编译器设置为将其链接为 Windows 可执行文件,而不是控制台应用程序。

如果你想要一个带有 Mingw 的控制台应用程序,你必须删除选项 -mwindows

如果你想要一个 Windows 应用程序,你必须提供 main 的特定实现形式,WinMain .

关于c - Gradle undefined reference `WinMain@16' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37990081/

相关文章:

java - Gradle 依赖与传递 false 继续检索依赖

c++ - OpenMP undefined reference `_CRT_fenv' 和 `_setargv'

c++ - 为什么在 C++ 中 pow(10,5) = 9,999

GCC的异常处理模型

c - 两个相似的功能,不同的结果

c++ - c/c++中perl的hash变量替换

android - Gradle 不包括已发布的 pom.xml 中的依赖项

android - 错误: In project 'app' a resolved Google Play services library dependency depends on another

c - 从程序集调用 C 函数 "exit"时是否必须清理堆栈?

c - 为什么下面的代码没有循环遍历 m?