【问题标题】:FreeBSD to Windows using Cygwin使用 Cygwin 从 FreeBSD 到 Windows
【发布时间】:2023-03-26 12:45:01
【问题描述】:

我有一个在 FreeBSD 中开发的 C 和 Fortran 代码,我想在我的 Windows 系统上运行它。所以我使用 Cygwin 作为替代方案。 除了代码之外,还有一个 Makefile,我尝试过并在 Makefile 中进行了一些更改。现在 makefile 运行完美,但在 makefile 中的某个时刻,它给了我大量与 Fortran 和 Lapack 库相关的错误。 我检查了我的库,它们都存在于我的系统中。 在参考了论坛的相关问题后,我尝试并使用了许多选项。但这没有用。 我对这个 Makefile 东西很陌生。 请帮我解决这些错误。


下面是 Makefile


#BASE_DIR=..
STD_LIB= -lm -llapack -lblas -lgcc  -lgfortran
#PROF_LIB=-lm_p -llapack_p -lblas_p -lg2c_p -L/usr/local/lib/gcc46 -lgfortran
#PROF=-pg

:if empty(PROF)
LDFLAGS=$(STD_LIB)
:else
LDFLAGS=$(PROF_LIB)
:endif


#LDFLAGS+=-L $(TOOL_DIR)/trapfpe -ltrapfpe

#test::
#   echo LDFLAG=$(LDFLAGS)

CC=/usr/bin/gcc
FC=/usr/bin/gfortran
CFLAGS= -g -ggdb -O3 -ffast-math -I -Wall $(PROF)
#CFLAGS= -g -ffast-math -I -Wall $(PROF)
FFLAGS= -g -I -Wall $(PROF) -fbounds-check
COMMON_OBJS=phase_unwrapping-lib.o matrix.o splotlib.o args_lib.o
UNWRAP_TOOL=rot_comp_unwrap
SUB=res_pos
ALL=$(UNWRAP_TOOL)
WORK=$(ALL)
WORK+=poisson_test boundary_search clustering band_matrix

default:: ctags $(WORK)
all:: $(ALL)

ctags::tags
tags:$(WORK:C/$/.c/) $(SUB:C/$/.c/)
ctags -w $ $^
#   ctags -w $ (.ALLSRC)

GA_OBJS=res_pos.o ga-core.o ga-fit.o data.o
CLUSTERING_OBJS=clustering.o
BOUNDARY_SUB_OBJS=poisson_enclosed_Neumann.o intlin.o solve_flux_eps_least_norm.o        band_matrix.o
BOUNDARY_OBJS=boundary_search.o $(BOUNDARY_SUB_OBJS)

SRCS=rot_comp_unwrap.c clustering.c boundary_search.c poisson_test.c res_pos.c band_matrix.c


rot_comp_unwrap:rot_comp_unwrap.o $(GA_OBJS) $(CLUSTERING_OBJS) $(BOUNDARY_OBJS)   $(COMMON_OBJS)
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $^
#   $(CC) $(CFLAGS) -o $(.TARGET) $(LDFLAGS) $(.ALLSRC)
res_pos:res_pos.c ga-core.o ga-fit.o data.o
$(CC) -o $@ -DMAIN $(CFLAGS) $(LDFLAGS) $^
#   $(CC) -o $(.TARGET) -DMAIN $(CFLAGS) $(LDFLAGS) $(.ALLSRC)

poisson_test:poisson_test.o poisson_enclosed_Neumann.o intlin.o
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $^
#   $(CC) -o $(.TARGET) $(CFLAGS) $(LDFLAGS) $(.ALLSRC)

boundary_search:boundary_search.c $(BOUNDARY_SUB_OBJS) $(COMMON_OBJS)
$(CC) -DMAIN $(CFLAGS) -O3 -o $@ $(LDFLAGS) $^
#   $(CC) -DMAIN $(CFLAGS) -O3 -o $(.TARGET) $(LDFLAGS) $(.ALLSRC)

band_matrix:band_matrix.c $(COMMON_OBJS)
$(CC) -DMAIN $(CFLAGS) -ffast-math -o $@ $(LDFLAGS) $^
#   $(CC) -DMAIN $(CFLAGS) -ffast-math -o $(.TARGET) $(LDFLAGS) $(.ALLSRC)
clustering:clustering.c $(COMMON_OBJS)
$(CC) -DMAIN $(CFLAGS) -ffast-math -o $@ $(LDFLAGS) $^
#   $(CC) -DMAIN $(CFLAGS) -ffast-math -o $(.TARGET) $(LDFLAGS) $(.ALLSRC)

clean::
rm *.o

backup::
cp -pf *.c *.F *.h *.o Makefile $(WORK) bak

depend::
mkdep ${CFLAGS} ${SRCS}

以下是我得到的错误


/usr/bin/gcc -g -ggdb -O3 -ffast-math -I -Wall  -o rot_comp_unwrap  rot_comp_unwrap.o res_pos.o ga-core.o ga-fit.o data.o clustering.o boundary_search.o poisson_enclosed_Neumann.o intlin.o solve_flux_eps_least_norm.o band_matrix.o phase_unwrapping-lib.o matrix.o splotlib.o args_lib.o
ga-core.o: In function `cpgene_':

/cygdrive/e/Lc-code1/ga-core.F:93: undefined reference to `_gfortran_runtime_error_at'

/cygdrive/e/Lc-code1/ga-core.F:93:(.text+0x5c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_gfortran_runtime_error_at'

/cygdrive/e/Lc-code1/ga-core.F:113:(.text+0x459): additional relocation overflows omitted from the output

/cygdrive/e/Lc-code1/ga-core.F:116: undefined reference to `_gfortran_transfer_real_write'

/cygdrive/e/Lc-code1/ga-core.F:116: undefined reference to `_gfortran_st_write_done'

ga-core.o: In function `fluct_':

/cygdrive/e/Lc-code1/ga-core.F:274: undefined reference to `_gfortran_rand'

ga-core.o:/cygdrive/e/Lc-code1/ga-core.F:278: more undefined references to `_gfortran_runtime_error_at' follow

ga-fit.o: In function `gapara_':

/cygdrive/e/Lc-code1/ga-fit.F:241: undefined reference to `_gfortran_st_open'

/cygdrive/e/Lc-code1/ga-fit.F:243: undefined reference to `_gfortran_st_read'

/cygdrive/e/Lc-code1/ga-fit.F:243: undefined reference to `_gfortran_transfer_integer'

/cygdrive/e/Lc-code1/ga-fit.F:243: undefined reference to `_gfortran_st_read_done'

/cygdrive/e/Lc-code1/ga-fit.F:244: undefined reference to `_gfortran_st_read'

/cygdrive/e/Lc-code1/solve_flux_eps_least_norm.F:73: undefined reference to `dgesv_'

/cygdrive/e/Lc-code1/solve_flux_eps_least_norm.F:109: undefined reference to `dgbsv_'

collect2: error: ld returned 1 exit status
Makefile:47: recipe for target 'rot_comp_unwrap' failed
make: *** [rot_comp_unwrap] Error 1

【问题讨论】:

    标签: windows makefile cygwin fortran freebsd


    【解决方案1】:

    您从链接器标志中删除了所有外部库。将 STD_LIB 中的库添加到您的命令中

    【讨论】:

    • 您能否详细说明您的答案该怎么做。
    • 取消注释 LDFLAGS=$(STD_LIB) 行
    • 我这样做了,但又出现了同样的错误。.f 和 .F 扩展名 fortran 文件之间有什么区别。因为我所有的 fortran 文件都带有 .F 扩展名。
    • 您可以尝试使用 gfortran 编译和链接 fortran 文件,使用 $(FC) 而不是 CC。
    • 我确实更改了 $(FC) 而不是 $(CC) 所以与 fortran 库相关的错误消失了,只有与 Lapack 相关的错误仍然存​​在。
    猜你喜欢
    • 2017-04-12
    • 2011-09-29
    • 1970-01-01
    • 2010-12-21
    • 2017-11-29
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多