mingw linker question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

mingw linker question

Brian Henning
Greetings All:

i have the following c program that i am trying to build into an exe.
Let's call it example.c. When i go to build the object file like so.
gcc -c examle.c

I get an object file of couse. I would basically like to learn howto
use the linker to build the exe for this object.

when i run this command I get errors. Could someone tell me what i am
doing wrong.
do i have to tell the linker where the entry point is? where the libc
library is?
ld examle.o

ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
example_main.o(.text+0x2b):example_main.c: undefined reference to `_alloca'
example_main.o(.text+0x30):example_main.c: undefined reference to `__main'
example_main.o(.text+0x48):example_main.c: undefined reference to `_imp___iob'
example_main.o(.text+0x51):example_main.c: undefined reference to `fprintf'
example_main.o(.text+0x5e):example_main.c: undefined reference to `exit'
example_main.o(.text+0x73):example_main.c: undefined reference to `printf'

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[] ) {
   if( argc != 2 ) {
       fprintf(stderr, "Usage: %s <arg1>\n", argv[0]);
       exit(1);
   }
   printf("%s\n", argv[1]);
   return 0;
}


Thanks,

Brian


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: mingw linker question

Brian Dessent
Brian Henning wrote:

> when i run this command I get errors. Could someone tell me what i am
> doing wrong.
> do i have to tell the linker where the entry point is? where the libc
> library is?
> ld examle.o

You shouldn't call the linker directly.  Use "gcc -o example
example.o".  Doing it this way passes all the correct libraries and
flags that are necessary, which are otherwise absent if you try to do it
yourself.  You can pass a command to gcc that will show you the actual
ld parameters used, but unless you're curious that's just trivia.

Brian


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: mingw linker question

Brian Henning
What is the parameter that you can pass to gcc to show the parameters to ld?

On 6/16/05, Brian Dessent <[hidden email]> wrote:

> Brian Henning wrote:
>
> > when i run this command I get errors. Could someone tell me what i am
> > doing wrong.
> > do i have to tell the linker where the entry point is? where the libc
> > library is?
> > ld examle.o
>
> You shouldn't call the linker directly.  Use "gcc -o example
> example.o".  Doing it this way passes all the correct libraries and
> flags that are necessary, which are otherwise absent if you try to do it
> yourself.  You can pass a command to gcc that will show you the actual
> ld parameters used, but unless you're curious that's just trivia.
>
> Brian
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users
>


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: mingw linker question

Brian Dessent
Brian Henning wrote:

> What is the parameter that you can pass to gcc to show the parameters to ld?

-v

(Please read the gcc manual and "gcc --help" output)


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users