public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Issues with LD when using GCC in a C program
@ 2009-03-24  4:45 Marcus Clyne
  2009-03-24 14:17 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Marcus Clyne @ 2009-03-24  4:45 UTC (permalink / raw)
  To: gcc-help

Hi,

I'm writing a C program which calls gcc using execl().

I have successfully called gcc to create an object file, but when I try 
to create the shared object file, I get problems with ld.

The error I'm getting is:
------------------
/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function 
`_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
------------------

I have added a PATH and LD_LIBRARY_PATH in the evironment, but this 
doesn't solve the problem.

The relevant code is:
-------------------
setenv ("PATH", 
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games", 
1);
setenv ("LD_LIBRARY_PATH", 
"/usr/local/lib:/usr/lib:/lib:/lib/tls/i686/cmov", 1);


// compile the shared object

execl ("/usr/bin/gcc",
           "-shared",
           "-lmylib",
           "-o",
           so_file,
           object_file,
           NULL);
-------------------

Where so_file and object_file are NULL-terminated char*'s, and the 
object_file has been created.

I can successfully compile the files using gcc from my shell, and ld is 
located at /usr/bin/ld.

I'm guessing that I need to add something to my env, or perhaps to the 
gcc options, but I'm not quite sure what.


Can anyone help?

Thanks,

Marcus Clyne.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-03-30 17:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-24  4:45 Issues with LD when using GCC in a C program Marcus Clyne
2009-03-24 14:17 ` Ian Lance Taylor
2009-03-30  9:27   ` Philip Herron
2009-03-30 17:43     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).