[英]Gradle undefined reference to `WinMain@16' error
I am new to gradle and creating library, i am trying to create a lib and link it later on while creating executable. 我是gradle和创建库的新手,我正在尝试创建一个lib并在创建可执行文件时将其链接起来。 Specifically looking at gradle to do the build system.
专门看gradle来做构建系统。 I am having below folder structure for the project,
我在项目的文件夹结构下面,
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);
and below is the build.gradle am using 以下是我使用的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'
}
When i give gradle build
command i get below error 当我给
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.
linkOutExecutable content is linkOutExecutable内容是
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.
Please help me to solve it Thank you 请帮我解决一下谢谢
"WinMain" indicates that the compiler is set to link this as a Windows executable, rather than a console application. “WinMain”表示编译器设置为将其链接为Windows可执行文件,而不是控制台应用程序。
If you want a console application with Mingw, you have to drop the option -mwindows
. 如果你想要一个带有Mingw的控制台应用程序,你必须删除
-mwindows
选项。
If you want a Windows application, you have to provide an implementation-specific form of main
, WinMain . 如果您需要Windows应用程序,则必须提供特定于实现的
main
, WinMain形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.