fortran lib 中 C 语言的链接错误

发布于 2024-07-26 00:02:32 字数 2773 浏览 7 评论 0原文

我正在将旧的 Fortran 编译器和旧的 Visual Studio(VC5) 应用程序移植到新的 Fortran 编译器 11 和 Visual Studio 2005。应用程序包含“C”和 Fortran 代码。 我正在编译 Fortran 代码并创建名为 server_lib.lib 的库(正在创建库,但有一些警告)并链接到“C”代码。 链接应用程序时给出一些以下链接错误。

2>Linking...
2>server_lib.lib(Preparx.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Query.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Utm.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Runvhf.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(PFLTPV.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Qdesic.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Headach.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Plotky.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Terrain.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Morpho.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Diflos.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Micro.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(OpenGL_F.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Violet.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Fieldp.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Step.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(White.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>.\Debug/Server.exe : fatal error LNK1169: one or more multiply defined symbols found

上面的“serverstuff”是在 server.for 文件中定义的,并且该 server.for 包含在所有上述文件中。 请从 server.for 文件中找到以下代码块。 但serverstuff变量只在server.for文件中定义一次。

INTEGER iErrPipe !error code for pipe i/o
INTEGER clientIndex !index into client list
CHARACTER*136 Buffer(17) !buffer for pipe i/o
CHARACTER dBuffer(2313) !buffer for pipe i/o
EQUIVALENCE(dBuffer,Buffer)
COMMON/serverstuff/clientIndex,dBuffer

DATA dBuffer(2313)/0/

为什么上面的代码会给出重新声明错误? 它如何与以前的 Fortran 编译器一起工作? 当我评论“COMMON/serverstuff/clientIndex,dBuffer”行时,它链接完美,但应用程序崩溃了。

请给我任何想法,因为我不了解 fortran 语言。

I am porting the application with old fortran compiler and old visual studio(VC5) to new fortran compiler 11 and visual studio 2005. Application contains both 'C' and fortran code. I am compiling the fortran code and creating library called server_lib.lib(library is createing with some warnings) and linking to the 'C' code. while linking application is giving some below linking errors.

2>Linking...
2>server_lib.lib(Preparx.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Query.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Utm.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Runvhf.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(PFLTPV.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Qdesic.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Headach.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Plotky.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Terrain.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Morpho.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Diflos.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Micro.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(OpenGL_F.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Violet.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Fieldp.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(Step.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>server_lib.lib(White.obj) : error LNK2005: _SERVERSTUFF already defined in server_lib.lib(Athena7.obj)
2>.\Debug/Server.exe : fatal error LNK1169: one or more multiply defined symbols found

above "serverstuff" is defined in server.for file and this server.for is included in all above files. Please find the below code block from server.for file. But the serverstuff variable defined only once in server.for file.

INTEGER iErrPipe !error code for pipe i/o
INTEGER clientIndex !index into client list
CHARACTER*136 Buffer(17) !buffer for pipe i/o
CHARACTER dBuffer(2313) !buffer for pipe i/o
EQUIVALENCE(dBuffer,Buffer)
COMMON/serverstuff/clientIndex,dBuffer

DATA dBuffer(2313)/0/

Why the above code is giving redeclaration error? How it worked with previous fortran compiler? When I am commenting the "COMMON/serverstuff/clientIndex,dBuffer" line then it's linking perfectly, but the application is crashed..

Please give me any idea as I don't know about fortran language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

腻橙味 2024-08-02 00:02:32

问题在于,公共块的含义(COMMON 这个词就是这个意思)在不同版本之间发生了某种变化。 以前,编译器发现多个文件中的公共块必须合并到一个变量中,现在它确实在每个 .obj 文件中包含一份变量副本,这会导致稍后出现链接错误。 您必须阅读新版本手册,了解通用块在新版本中如何工作 - 这可能会揭示如何克服问题。

The problem is that the meaning of common blocks (the word COMMON is for that) has somehow changed between the versions. Previously the compiler figured out that the common blocks in several files must be merged into one variable and now it does include a copy of variable into every .obj file and this causes link error later. You have to read the new version manual on how the common blocks work in the new version - that will likely shed light onto how to overcome the problem.

眼藏柔 2024-08-02 00:02:32

我不确定发生了什么,但混合语言程序过去经常出现的一个问题是处理或加载特定于语言的事物。 例如,如果您有一个用 C 编写的 main 函数和一个执行 IO 的 fortran 子例程,那么使用 C 系统进行链接可能不会加载 fortran io 库,因为它不知道有关它们的任何信息。

我想知道您是否有 C 或 C++ 中的 main 函数,链接器不知道公共块是全局变量。
您可以尝试

extern char[2313] _SERVERSTUFF;

在函数 main 之前放置。 您可能需要尝试删除下划线,并且可能需要删除 SERVERSTUFF 的情况

I am not sure what is happening but a problem that used to occur with mixed language programs was processing or loading of language specific things. For example if you have a main function written in C and a fortran subroutine which does IO then linking using the C system may not load the fortran io libraries because it does not know anything about them.

I am wondering if you have a main function in C or C++ the linker does not know that the common block is a global variable.
You could try putting

extern char[2313] _SERVERSTUFF;

before your function main. you may need to play with removing the underscore and possible the case of SERVERSTUFF

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文