- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Itried to convertour 32bits codesto 64bit.In our projects, there is one C code file withtwo subroutines whichare called by other fortran functions.We write
our own command line makefile, which use Intel VF9.0 to compile Fortran codes and Visual C++ compliler to compiler the C codes. Then the object files are linked to form the executable file. However, I got the link error
A.obj : error LNK2019: unresolved external symbol _myfunc1 referenced in function B
Where A.obj is the fortranobject file andmyfunc1 is the c function which is defined in a file C. The compiler did produced the objectC.obj.
The header ofour c function is like the following:
void myfunc1 (char* , short *, int *, int *)
and the interface defined in Fortran files is like this:
SUBROUTINE myfunc1(name, a1, a2, a3)
!MS$ATTRIBUTES C, ALIAS:'_myfunc1' :: myfunc1
!MS$ATTRIBUTES REFERENCE :: name, a1, a2
!MS$ATTRIBUTES REFERENCE :: a3
character*(*) name
integer*2 a1(4)
integer*4 a2(4)
integer*4 a3
END SUBROUTINE myfunc1
Do you know howcan I fix it?
Thank you!
Link Copied
15 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Take off the alias attribute - you don't need it and it's incorrect on EM64T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. I took off the alias attribute; however, the problem still exits. Now the new link error is
A.obj : error LNK2019: unresolved external symbol myfunc1 referenced in function B
while the older is
A.obj : error LNK2019: unresolved external symbol _myfunc1 referenced in function B
Any idea?
Thanks!
phu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, what is the ACTUAL declaration of myfunc1 in the C source? Is the source file named .c or .cpp? If .cpp, you need to preface the declaration with 'extern "C"'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
The actual declaration of myfunc1 is just
volid myfunc1(char * name, short *a1, int *a2, int *a3)
which is defined in source file C.c.
BTW: (1) It works under the build environment for Fortran IA-32 application
(2) The cl.exe c++ compiler of .net 2003 is used to compiler c code,
doesthis compilersupport 64bits? Or I have to use the c++
compiler from .net 2005 beta? If so, I am afraid that it won't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would need to use the cl that is provided by the Microsoft Platform SDK. VS.NET 2003 does not provide a compiler for EM64T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If ALIAS for leading _ is incorrect on EMT64 I am sure then that this is a common mistake. Therefore I would like to submit the suggestion that a compiler Information message be issued when ALIAS is use to declare an _'d alias.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't think that is appropriate. The assumption is that the user knows what the alias should be. We introduced the DECORATE attribute if all you want to do is change the "spelling" of the name, and I would recommend its use instead of including the decoration in the alias.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
I tried with the Microsoft Platform SDK comipler. It seems that
it has nothing to do with the link error. The error is still there. I do not know how IVF tries to solve the possible name confliction when linking object files coming from different languages under 64bits. That could mostly be the problem.
Thanks!
phu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This isn't an IVF issue. You simply have to make sure you're using the same naming convention as the C compiler you are using.
The best thing to do is start a Fortran "Build Environment" command session, and do a "dumpbin -symbols csubr.obj" (where csubr.obj is the name of the object with your C routine.) If dumpbin is not recognized, use link /dump /symbols instead. Examine the output and see how your routine appears in the symbol table.
The best thing to do is start a Fortran "Build Environment" command session, and do a "dumpbin -symbols csubr.obj" (where csubr.obj is the name of the object with your C routine.) If dumpbin is not recognized, use link /dump /symbols instead. Examine the output and see how your routine appears in the symbol table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
I got something like the following from C.obj (which contains
the c function myfunc1)
---------------------------------------------------
007 00000000 SECT3 notype () External | ?myfunc1@@YAXPEADPEAFPEAH2@Z (void __cdecl myfunc1(char *,short *,int *,int *))
008 00000000 SECT3 notype Label | $LN8
009 00000000 SECT4 notype Static | .pdata
Section length C, #relocs 3, #linenums 0, checksum 9E16D8C3, selection 5 (pick associative Section 0x3)
00B 00000000 SECT4 notype Static | $pdata$? myfunc1@@YAXPEADPEAFPEAH2@Z
00C 00000000 SECT5 notype Static | .xdata
Section length 18, #relocs 0, #linenums 0, checksum E7920FBD, selection 5 (pick associative Section 0x3)
00E 00000000 SECT5 notype Static | $unwind$ myfunc1@@YAXPEADPEAFPEAH2@Z
---------------------------------------------------
While the in the symbol table of the object file call myfunc1,
the symbol table has a line like
-----------------------------------
169 00000000 UNDEF notype () External | myfunc1
--------------------------------------
It seems that the C.obj mismatch with it.
Do you know how to fix it? Thanks!
Phu
I got something like the following from C.obj (which contains
the c function myfunc1)
---------------------------------------------------
007 00000000 SECT3 notype () External | ?myfunc1@@YAXPEADPEAFPEAH2@Z (void __cdecl myfunc1(char *,short *,int *,int *))
008 00000000 SECT3 notype Label | $LN8
009 00000000 SECT4 notype Static | .pdata
Section length C, #relocs 3, #linenums 0, checksum 9E16D8C3, selection 5 (pick associative Section 0x3)
00B 00000000 SECT4 notype Static | $pdata$? myfunc1@@YAXPEADPEAFPEAH2@Z
00C 00000000 SECT5 notype Static | .xdata
Section length 18, #relocs 0, #linenums 0, checksum E7920FBD, selection 5 (pick associative Section 0x3)
00E 00000000 SECT5 notype Static | $unwind$ myfunc1@@YAXPEADPEAFPEAH2@Z
---------------------------------------------------
While the in the symbol table of the object file call myfunc1,
the symbol table has a line like
-----------------------------------
169 00000000 UNDEF notype () External | myfunc1
--------------------------------------
It seems that the C.obj mismatch with it.
Do you know how to fix it? Thanks!
Phu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your C file is a .cpp file and therefore you are getting C++ name mangling. Change the header in the C file to read:
extern "C" void myfunc1 (char* , short *, int *, int *)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, my file is a .c file.
Phu
Phu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How are you compiling it, and with which compiler? Try the 'extern "C"' anyway. It's clear you're getting C++ semantics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
I use the extern and now I got something like the following from C.obj (which contains the c function myfunc1)
--------------------------------------------------------
006 00000000 SECT2 notype () External | myfunc1
007 00000000 UNDEF notype () External | fopen
008 00000000 UNDEF notype () External | fread
009 00000000 UNDEF notype () External | fclose
00A 00000000 SECT3 notype Static | .xdata$x Section length 10, #relocs 0,
#linenums 0, checksum 0, selection 5 (pick associative Section 0x2)
00C 00000000 SECT3 notype Static | $unwind$myfunc1
00D 00000000 SECT4 notype Static | .pdata$x Section length C, #relocs 3,
#linenums 0, checksum 0, selection 5 (pick associative Section 0x2)
00F 00000000 SECT4 notype Static | $pdata$myfunc1
---------------------------------------------------------
While the in the symbol table of the object file call myfunc1, the symbol table has a line like
-----------------------------------
169 00000000 UNDEF notype () External | myfunc1
--------------------------------------
However, it still could not link together!
Phu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(Please ignore my previous post -- I didn't see that you posted both caller and callee symbol dumps and that they appear to agree. Thus, the problem lies somewhere else.)
Jugoslav
Jugoslav
Message Edited by JugoslavDujic on 10-26-2005 09:43 AM
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page