Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22006

Gcc Will Not Set Entry Point

$
0
0

I am trying to set my main function to be the first executable code in my program and to bypass the libc startup code. I want a very basic output so I can observe the assembly code generated. I'm running this with MinGW on windows 10. I've tried to compile and link my program via this command:

gcc -m32 -O0 -Wl,-emain "test.cpp" -o "test.exe"

However, I get this warning:

warning: cannot find entry symbol main; defaulting to 00401000

But main is very clearly in my program (a simple hello world type program). This compiled but leads to my program having no output for whatever reason.

I have also tried -nostartfiles which forces me to rename my main function as _start or _main but doesn't even execute it. It literally just executes the first function in the program.

gcc -m32 -O0 -nostartfiles "test.cpp" -o "test.exe"

Here is the simple code I am using

#include <stdio.h>
void f1()
{
printf ("Should not be called but is.\n");
}

int _start(void)    
{
printf("Should be called but isn't.");

return 0;
}

I also tried -nostdlib and linking the msvcrt library manually with -lmsvcrt, but with the same thing happening.

I was very easily able to achieve what I want with msvc using these options:

cl "test.cpp" msvcrt.lib /link /entry:main

Any help is greatly appreciated, thank you!


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>