udf编译报错
fluent吧
全部回复
仅看楼主
level 10
LOSTSTARS 楼主
大佬求助。fluent编译udf时报错,报错内容如下:
Compiler and linker: Clang (builtin)
Compiler path: "D:\ANSYSI~1\v231\fluent"\ntbin\clang\bin\clang-cl
Linker path: "D:\ANSYSI~1\v231\fluent"\ntbin\clang\bin\lld-link
UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 961: illegal multibyte sequence:
File "E:\wenquan yang\postgraduate\research\micro combustor\micro combustor40%h2\residual flame mechanism\data\test\libudf\win64\3ddp_node\SConstruct", line 180:
generate_udf_source(t, s, env)
File "E:\wenquan yang\postgraduate\research\micro combustor\micro combustor40%h2\residual flame mechanism\data\test\libudf\win64\3ddp_node\SConstruct", line 91:
for line in f:
起初我以为是语法错误,然后我把之前编译成功而且结果验证过的代码拿来编译报了一样的错。Google搜了一下说是编码的问题。但不知道怎么解决,有没有大佬知道的。感激不尽。
2023年10月22日 11点10分 1
level 10
LOSTSTARS 楼主
报错文件如下(至181行):
#
# Copyright 1987-2023 ANSYS, Inc. All Rights Reserved.
#
import os
import re
import SCons
# disable the print of SCons actions (e.g., the Copy action in `Execute(Copy(file1, file2))`)
SCons.Action.print_actions = 0
vars = Variables('user.txt')
vars.Add('VERSION', '', '')
vars.Add('FLUENT_ARCH', '', '')
vars.Add('FLUENT_RELEASE','', '')
vars.Add('HOST_FLAGS', '', '')
vars.Add('CSOURCES', '', '')
vars.Add('HSOURCES', '', '')
# vars.Add('PARALLEL_NODE','','')
env = Environment(variables=vars)
if os.environ.get('FLUENT_INC', '') == '':
print("Fluent Directory not set")
exit()
if env['FLUENT_ARCH'] != 'win64':
print("FLUENT_ARCH variable should be win64")
exit()
if env['VERSION'] not in ['2d_host', '2d_node', '3d_host', '3d_node', '2ddp_host', '2ddp_node', '3ddp_host', '3ddp_node']:
print("Fluent version not supported")
exit()
env['MSVC'] = os.environ['FLUENT_UDF_COMPILER']
env['FLUENT_INC'] = os.environ['FLUENT_INC']
env['CLANGV'] = os.environ['FLUENT_UDF_CLANG']
if env['CLANGV'] == 'clangenv':
env['CC'] = 'clang-cl'
env['CLINK'] = 'lld-link'
env['ENV']['PATH'] = os.environ['PATH']
#env['ENV']['LIB'] = os.environ['LIB']
#env['ENV']['LIBPATH'] = os.environ['LIBPATH']
else:
fluent_inc_s = '"' + str(env['FLUENT_INC']) + '"'
env['CC'] = os.path.join(fluent_inc_s, 'ntbin', 'clang', 'bin', 'clang-cl')
env['CLINK'] = os.path.join(fluent_inc_s, 'ntbin', 'clang', 'bin', 'lld-link')
print("Compiler path:", env['CC'])
print("Linker path:", env['CLINK'])
source_files = []
if env['CSOURCES']:
source_files = env['CSOURCES'].split('$(SRC)')
header_files = []
if env['HSOURCES']:
header_files = env['HSOURCES'].split('$(SRC)')
sfiles = []
for c in source_files:
if c.rstrip().endswith('.c') or c.rstrip().endswith('.cpp'):
sfiles.append(c.rstrip())
hfiles = []
for c in header_files:
if c.rstrip().endswith('.h'):
hfiles.append(c.rstrip())
fluent_path = env['FLUENT_INC']
version = env['VERSION']
fluent_inc = env['FLUENT_INC']
arch = env['FLUENT_ARCH']
release = env['FLUENT_RELEASE']
release_strings = release.split('fluent')
release_year = release_strings[1]
release_ver_strings = release_strings[1].split('.')
fstring = release_ver_strings[0]+release_ver_strings[1]+release_ver_strings[2]
def generate_udf_source(target, source, env):
defines = []
for s in source:
f = open(str(s), 'r')
with f:
multi_lines = []
ncomm = 0
for line in f:
if "/*" in line:
ncomm += 1
if "*/" in line:
ncomm = 0
if line.lstrip().startswith('DEFINE_') and ncomm == 0:
if ")" in line:
csub = str(line).split('{')
multi_lines.append(csub[0].strip())
nlines = ""
for c in multi_lines:
nlines += c
defines.append(nlines)
multi_lines = []
else:
multi_lines.append(line.strip())
elif len(multi_lines) > 0 and ncomm == 0:
if ")" in line:
csub = str(line).split('{')
multi_lines.append(csub[0].strip())
nlines = ""
for c in multi_lines:
nlines += c
defines.append(nlines)
multi_lines = []
else:
multi_lines.append(line.strip())
target = target[0]
f = open(str(target), 'w')
with f:
f.write(('/* This file generated automatically. */\n'
'/* Do not modify. */\n'
'#include "udf.h"\n'
'#include "prop.h"\n'
'#include "dpm.h"\n'))
for d in defines:
f.write('extern {};\n'.format(d))
f.write('__declspec(dllexport) UDF_Data udf_data[] = {\n')
regex = re.compile('DEFINE_([^( ]*) *\( *([^, )]*)')
for d in defines:
define_name, first_arg = regex.match(d).groups()
f.write(
'{{"{0}", (void(*)()){0}, UDF_TYPE_{1}}},\n'.format(first_arg, define_name))
dllexport = '__declspec(dllexport) '
f.write(('}};\n'
'{0}int n_udf_data = sizeof(udf_data)/sizeof(UDF_Data);\n'
'#include "version.h"\n'
'{0}void UDF_Inquire_Release(int *major, int *minor, int *revision)\n'
'{{\n'
' *major = RampantReleaseMajor;\n'
' *minor = RampantReleaseMinor;\n'
' *revision = RampantReleaseRevision;\n'
'}}\n').format(dllexport))
return 0
udf_path = os.path.abspath('../../')
src_path = os.path.join(udf_path, 'src')
c_sources_t = os.listdir(src_path)
dir = os.path.abspath('.')
dfile = os.path.join(dir, 'resolve.exe')
sfile = os.path.join(fluent_inc, 'ntbin', 'win64', 'resolve.exe')
Execute(Copy(dfile, sfile))
c_sources = []
for c in c_sources_t:
if sfiles:
if c in sfiles:
c_sources.append(c)
else:
c_sources.append(c)
for c in c_sources_t:
if hfiles:
if c in hfiles:
c_sources.append(c)
s = []
for c in c_sources:
if c.endswith('.c') or c.endswith('.cpp') or c.endswith('.h'):
sfile = os.path.join(src_path, c)
dfile = os.path.join(dir, c)
Execute(Copy(dfile, sfile))
if c.endswith('.c') or c.endswith('.cpp'):
s.append(dfile)
t = ['udf_names.c']
generate_udf_source(t, s, env)
c_sources.append('udf_names.c')
2023年10月22日 11点10分 2
level 1
兄弟你解决了吗
2023年12月18日 04点12分 4
重装了一遍[乖]好像就没了
2023年12月18日 14点12分
重装fluent吗[啊],但是我跑老师给的代码是可以跑的
2023年12月18日 14点12分
@tearTree 也有可能是代码有问题,你再检查一下
2023年12月19日 00点12分
1