I am new to gradle and creating library, i am trying to create a lib and link it later on while creating executable. Specifically looking at gradle to do the build system. 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
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
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
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.
If you want a console application with Mingw, you have to drop the option -mwindows
.
If you want a Windows application, you have to provide an implementation-specific form of main
, WinMain .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.