linking c and fortran in the same archive
John (Eljay) Love-Jensen
eljay@adobe.com
Thu Nov 12 15:36:00 GMT 2009
On 11/12/09 9:14 AM, "Jean-François MAUREL" <jfr.maurel@gmail.com> wrote:
> Hi every one,
>
> I am a newcomer to gcc. I searched within documentation and mailing list
> archive but did not find anything useful for the following issue:
> I cannot link c and f object files when I provide a single archive file.
> I can do it only when I provide individual object files
>
> Below are the details:
>
> I can compile link and execute a test program containing a c program
> file and a fortran program file (see below) with following set of commands:
> (Windows Vista MinGW gcc , gfortran 4.4.0 ):
> gcc -c main.c -omain.o -Wall
> gfortran -c sub.f -osub.o -Wall
> gcc *.o -Wall -enable-stdcall-fixup -omain.exe
>
> when I use the following commands I have an undefined reference error :
> gcc -c main.c -omain.o -Wall
> gfortran -c sub.f -osub.o -Wall
> ar -r libtotal.a main.o sub.o
> gcc -ltotal -Wall -enable-stdcall-fixup -omain.exe -L.
> ./libtotal.a(main.o):main.c:(.text+0x6b): undefined reference to `test_@24'
> collect2: ld a retourné 1 code d'état d'exécution
>
> gcc -ltotal -Wall -enable-stdcall-fixup -omain.exe -L.
> Could someone tell what I am missing here?
What happens if you put your library dependencies in order?
gcc -Wall -enable-stdcall-fixup -o main.exe -L. -ltotal
The order is important. The libraries are processed left-to-right. At the
time of the -ltotal in your command-line, there is no outstanding symbols
from the *.o files (since there haven't been any *.o files).
Note: *.o files are taken in their entirety, unlike the archive library.
Your linker may also have a switch to pull in all the parts in the archive
library, such as:
gcc -Wl,--whole-archive -ltotal -Wl,--no-whole-archive -Wall
-enable-stdcall-fixup -o main.exe -L.
HTH,
--Eljay
More information about the Gcc-help
mailing list