weixing1531 发表于 2023-9-22 18:21:22

两个静态库重复定义造成冲突如何解决?

编译器:SimplyFortran 3.31
Dislin库文件dismg_d.a与SimplyFortran自带界面库文件libappgraphics.a中均有line子程序,重复定义造成冲突
报错信息:
d:/program files (x86)/simply fortran 3/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libappgraphics.a(drawing.o):drawing.c:(.text+0x13e0): multiple definition of `line'
c:\dislin\dismg_d.a(line.o):line.c:(.text+0x476e): first defined here
collect2.exe: error: ld returned 1 exit status


li913 发表于 2023-9-23 12:12:23

use module 的时候,只导出需要的函数, use A,only: B. 如果两个line都需要,可以用别名use A, AB=>B

fcode 发表于 2023-9-23 13:12:06

li913 发表于 2023-9-23 12:12
use module 的时候,只导出需要的函数, use A,only: B. 如果两个line都需要,可以用别名use A, AB=>B ...

这俩库如果有源代码还好,可以改一下。
如果没有源代码,还是比较麻烦的。

weixing1531 发表于 2023-9-23 14:00:01

fcode 发表于 2023-9-23 13:12
这俩库如果有源代码还好,可以改一下。
如果没有源代码,还是比较麻烦的。
...

改别名试过了,不行

chiangtp 发表于 2023-9-23 20:17:30

DISLIN: (LINE) -> (STRTPT, STRTPT)
or
SimplyFortran, AppGraphics: (line) -> (moveto, lineto)

======================================================================                                             
DISLIN: (LINE) -> (STRTPT, STRTPT)                                                                                 
======================================================================                                             
                                                                                                                  
L I N E                                                                                                            
                                                                                                                  
LINE joins two points with a line.                                                                                 
Different line styles can be used.                                                                                 
                                                                                                                  
The call is:    CALL LINE (X1, Y1, X2, Y2)      level 1, 2, 3                                                      
                                                                                                                  
X1, Y1are real numbers containing the plot coordinates of the first point.                                       
X2, Y2are real numbers containing the plot coordinates of the second point.                                       
                                                                                                                  
----------------------------------------                                                                           
                                                                                                                  
XMOVE and XDRAW are simple subroutines for plotting lines.                                                         
Different line styles can be used.                                                                                 
                                                                                                                  
The calls are:CALL STRTPT (X, Y)      level 1, 2, 3                                                               
                CALL CONNPT (X, Y)      level 1, 2, 3                                                               
                                                                                                                  
X, Y    are real numbers containing the plot coordinates.                                                         
                                                                                                                  
======================================================================                                             
SimplyFortran, AppGraphics: (line) -> (moveto, lineto)                                                            
======================================================================                                             
                                                                                                                  
line                                                                                                               
                                                                                                                  
Fortran subroutine line (x1, y1, x2, y2)                                                                           
                                                                                                                  
Description                                                                                                         
Draws a line using the current color from point (x1,y1) to point (x2,y2).                                          
                                                                                                                  
Parameters                                                                                                         
Parameter       Fortran Type    Description                                                                        
x1            integer         Horizontal coordinate of the start point of the line                              
y1            integer         Vertical coordinate of the start point of the line                                 
x2            integer         Horizontal coordinate of the end point of the line                                 
y2            integer         Vertical coordinate of the end point of the line                                    
                                                                                                                  
----------------------------------------                                                                           
                                                                                                                  
moveto                                                                                                            
Fortran subroutine moveto (x, y)                                                                                    
                                                                                                                  
Description                                                                                                         
Sets the current position to be used with subsequent relative graphics operations.                                 
                                                                                                                  
Parameters                                                                                                         
Parameter       Fortran Type    Description                                                                        
x               integer         Horizontal coordinate of the current position                                       
y               integer         Vertical coordinate of the current position                                       
                                                                                                                  
--------------------                                                                                                
                                                                                                                  
lineto                                                                                                            
                                                                                                                  
Fortran subroutine lineto (x, y)                                                                                    
                                                                                                                  
Description                                                                                                         
Draws a line from the current position to the point (x, y) using the current color.                                 
The current position is moved to this new offset after the drawing operation.                                       
                                                                                                                  
Parameters                                                                                                         
Parameter       Fortran Type    Description                                                                        
x               integer         Horizontal coordinate of the end point of the line                                 
y               integer         Vertical coordinate of the end point of the line                                    
                                                                                                                  

weixing1531 发表于 2023-9-25 10:03:12

chiangtp 发表于 2023-9-23 20:17
DISLIN: (LINE) -> (STRTPT, STRTPT)
or
SimplyFortran, AppGraphics: (line) -> (moveto, lineto)


用相同功能函数代替还是不行

chiangtp 发表于 2023-9-25 10:13:35

weixing1531 发表于 2023-9-25 10:03
用相同功能函数代替还是不行

請告知 "錯誤訊息"

weixing1531 发表于 2023-9-25 10:44:54

chiangtp 发表于 2023-9-25 10:13
請告知 "錯誤訊息"

还是相同的错误信息,网上说只有对静态库进行重新改名封装了

chiangtp 发表于 2023-9-25 11:01:14

1. "LINE" 在DISLIN中為"EXTERNAL" subroutine,在AppGraphics中應該也是
2. 如果都是"MODULE" subroutines, li913的作法OK
3. 如果 錯誤訊息 仍是 multiple definition of `line', 請確認:你的程式中 所有的 "LINE"calls 均已做替換
    DISLIN: (LINE) -> (STRTPT, CONNPT)      
    AppGraphics: (line) -> (moveto, lineto)

weixing1531 发表于 2023-9-28 09:21:02

这是SF作者的答复:错误是由链接器而非编译器产生的。链接器遇到两个不同的行过程并失败。即使您没有显式地使用line,由于库中的一些较低级别调用,它仍然很有可能需要链接。
页: [1] 2
查看完整版本: 两个静态库重复定义造成冲突如何解决?