从 MS Visual C++ 编译器更改为英特尔 C++ 19.1 编译器时未解析的外部符号 __imp__fread
Posted
技术标签:
【中文标题】从 MS Visual C++ 编译器更改为英特尔 C++ 19.1 编译器时未解析的外部符号 __imp__fread【英文标题】:unresolved external symbol __imp__fread when changing from MS Visual C++ Compiler to Intel C++ 19.1 Compiler 【发布时间】:2020-10-31 13:28:39 【问题描述】:有一个使用 freetype263.lib 的项目,它可以使用 Visual Studio 2019 中的 Microsoft Visual C++ 编译器正常编译,但是当尝试在 Visual Studio 2019 中使用英特尔 C++ 19.1 编译器编译 C++ 项目时,会出现以下错误:
1>freetype263.lib(ftsystem.obj) : : error LNK2019: unresolved external symbol __imp__fread referenced in function _ft_ansi_stream_io
1>freetype263.lib(ftsystem.obj) : : error LNK2019: unresolved external symbol __imp__fseek referenced in function _ft_ansi_stream_io
1>freetype263.lib(ftsystem.obj) : : error LNK2019: unresolved external symbol __imp__ftell referenced in function _FT_Stream_Open
还有一些警告,虽然我不确定这些是否重要:
1>LINK : : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : : warning LNK4286: symbol '_qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'freetype263_intel.lib(psaux.obj)'
1>LINK : : warning LNK4286: symbol '_qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'freetype263_intel.lib(type1.obj)'
1>LINK : : warning LNK4217: symbol '_qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'freetype263_intel.lib(ftbase.obj)' in function '_FT_Raccess_Get_DataOffsets.'
1>LINK : : warning LNK4286: symbol '_qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'freetype263_intel.lib(bdf.obj)'
1>LINK : : warning LNK4286: symbol '_qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'freetype263_intel.lib(sfnt.obj)'
1>LINK : : warning LNK4286: symbol '_qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'freetype263_intel.lib(psmodule.obj)'
1>LINK : : warning LNK4217: symbol '_strncpy' defined in 'libucrt.lib(strncpy.obj)' is imported by 'freetype263_intel.lib(ftbase.obj)' in function '_raccess_make_file_name'
1>LINK : : warning LNK4217: symbol '_malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'freetype263_intel.lib(ftsystem.obj)' in function '_ft_alloc'
1>LINK : : warning LNK4217: symbol '_realloc' defined in 'libucrt.lib(realloc.obj)' is imported by 'freetype263_intel.lib(ftsystem.obj)' in function '_ft_realloc'
1>LINK : : warning LNK4217: symbol '_free' defined in 'libucrt.lib(free.obj)' is imported by 'freetype263_intel.lib(ftsystem.obj)' in function '_ft_free'
1>LINK : : warning LNK4217: symbol '_fclose' defined in 'libucrt.lib(fclose.obj)' is imported by 'freetype263_intel.lib(ftsystem.obj)' in function '_ft_ansi_stream_close'
1>LINK : : warning LNK4217: symbol '_fopen' defined in 'libucrt.lib(fopen.obj)' is imported by 'freetype263_intel.lib(ftsystem.obj)' in function '_FT_Stream_Open'
1>LINK : : warning LNK4217: symbol '___stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'freetype263_intel.lib(bdf.obj)' in function '__bdf_parse_properties'
1>LINK : : warning LNK4217: symbol '_atol' defined in 'libucrt.lib(atox.obj)' is imported by 'freetype263_intel.lib(type42.obj)' in function '_T42_GlyphSlot_Load'
1>LINK : : warning LNK4286: symbol '_atol' defined in 'libucrt.lib(atox.obj)' is imported by 'freetype263_intel.lib(type1cid.obj)'
我已经使用 Intel 19.1 编译器重新编译了 freetype 项目,该编译器输出一个 .lib 文件,并且成功但仍然没有解决问题。
freetype 项目的代码如下:
摘自包含文件:
#define ft_ptrdiff_t ptrdiff_t
/**********************************************************************/
/* */
/* integer limits */
/* */
/* UINT_MAX and ULONG_MAX are used to automatically compute the size */
/* of `int' and `long' in bytes at compile-time. So far, this works */
/* for all platforms the library has been tested on. */
/* */
/* Note that on the extremely rare platforms that do not provide */
/* integer types that are _exactly_ 16 and 32 bits wide (e.g. some */
/* old Crays where `int' is 36 bits), we do not make any guarantee */
/* about the correct behaviour of FT2 with all fonts. */
/* */
/* In these case, `ftconfig.h' will refuse to compile anyway with a */
/* message like `couldn't find 32-bit type' or something similar. */
/* */
/**********************************************************************/
#include <limits.h>
#define FT_CHAR_BIT CHAR_BIT
#define FT_USHORT_MAX USHRT_MAX
#define FT_INT_MAX INT_MAX
#define FT_INT_MIN INT_MIN
#define FT_UINT_MAX UINT_MAX
#define FT_LONG_MAX LONG_MAX
#define FT_ULONG_MAX ULONG_MAX
/**********************************************************************/
/* */
/* character and string processing */
/* */
/**********************************************************************/
#include <string.h>
#define ft_memchr memchr
#define ft_memcmp memcmp
#define ft_memcpy memcpy
#define ft_memmove memmove
#define ft_memset memset
#define ft_strcat strcat
#define ft_strcmp strcmp
#define ft_strcpy strcpy
#define ft_strlen strlen
#define ft_strncmp strncmp
#define ft_strncpy strncpy
#define ft_strrchr strrchr
#define ft_strstr strstr
/**********************************************************************/
/* */
/* file handling */
/* */
/**********************************************************************/
#include <stdio.h>
#define FT_FILE FILE
#define ft_fclose fclose
#define ft_fopen fopen
#define ft_fread fread
#define ft_fseek fseek
#define ft_ftell ftell
#define ft_sprintf sprintf
/**********************************************************************/
/* */
/* sorting */
/* */
/**********************************************************************/
#include <stdlib.h>
#define ft_qsort qsort
摘自用于生成 lib 的 .c 文件:
/*************************************************************************/
/* */
/* <Function> */
/* ft_ansi_stream_io */
/* */
/* <Description> */
/* The function to open a stream. */
/* */
/* <Input> */
/* stream :: A pointer to the stream object. */
/* */
/* offset :: The position in the data stream to start reading. */
/* */
/* buffer :: The address of buffer to store the read data. */
/* */
/* count :: The number of bytes to read from the stream. */
/* */
/* <Return> */
/* The number of bytes actually read. If `count' is zero (this is, */
/* the function is used for seeking), a non-zero return value */
/* indicates an error. */
/* */
FT_CALLBACK_DEF( unsigned long )
ft_ansi_stream_io( FT_Stream stream,
unsigned long offset,
unsigned char* buffer,
unsigned long count )
FT_FILE* file;
if ( !count && offset > stream->size )
return 1;
file = STREAM_FILE( stream );
if ( stream->pos != offset )
ft_fseek( file, (long)offset, SEEK_SET );
return (unsigned long)ft_fread( buffer, 1, count, file );
【问题讨论】:
我认为您的问题是 警告 LNK4098:defaultlib 'MSVCRT' 与使用其他库发生冲突;使用 /NODEFAULTLIB:library 对我来说,这意味着你有超过 1 个 CRT 你不能混合使用 /MD 编译的代码(就像 freetype 一样,CRT 存在于它自己的 DLL 中)和使用 /MT 编译的代码(程序的其余部分,CRT 被链接在)。 /MT 只适用于没有复杂依赖的小程序。 software.intel.com/content/www/us/en/develop/documentation/… 【参考方案1】:为了解决这个问题,我将项目属性 C/C++ - 代码生成 从 多线程 (/MT) 更改为 多线程 DLL (/MD)
这删除了所有链接器错误,但随后出现错误 setup.sbr 未找到。这已通过配置项目属性 C/C++ - 浏览信息 - 启用浏览信息 到 否
【讨论】:
以上是关于从 MS Visual C++ 编译器更改为英特尔 C++ 19.1 编译器时未解析的外部符号 __imp__fread的主要内容,如果未能解决你的问题,请参考以下文章
是否有免费的开源工具供 MS Visual C++ Express 使用 gcc 构建?
Windows 下 Visual Studio 2012 / Intel 编译器的 C++ 双精度失败
将新的 MS C++ 编译器与旧的 Visual Studio 一起使用
在 MS Visual C++ 中启用 VLA(可变长度数组)?