This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Issues with LD when using GCC in a C program


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]